1,399 views
0 votes
0 votes
Assuming pages of size 128 words each and array is stored in row major, how many page faults will be generated in the following C program?

int A[128][128];

for(int j=0;j<128;j++)

for(int i=0;i<128;i++)

A[i][j]=0;

 

a)128

b)16384

c)0

d)None

1 Answer

Best answer
1 votes
1 votes
The answer seems to be $none\space of\space these$ to me, but trying to reach one of the other options by taking some assumptions.

Given that $128$ x $128$ words are stored in $row\space major$ order, ie; elements are stored row by row. so there are total $128$ pages, each page containing elements $A[i][0]$ to $A[i][127]$. [Word addressible memory is taken because the size of a word and integer are not given in bytes.]

Now in the loop of the program, the words are accessed in $column\space major$ order $\rightarrow A[0][0]$, $A[1][0]$, $A[2][0]$.. (inner loop is $i$).

Therefore a new page has to be accessed each time $A[i][j]$ is accessed.[Another assumption here, number of pages in memory at a time $<= 128$]
 
Hence the total number of page faults $= 128 * 128 = 16384$
So, the answer is $(B)$
selected by

Related questions

1 votes
1 votes
2 answers
1