The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+3 votes
275 views
Suppose a 32 K×8 K matrix A with 1-byte elements is stored in row major order in virtual memory. Assume only the program in question occupies space in physical memory.
Program 1
for (i = 0; i < 32768; i++)
   for (j = 0; j < 8192; j++)
       A[i][j] = A[i][j] * A[i][j];

Program 2
for (j = 0; j < 8192; j++)
 for (i = 0; i < 32768; i++)
      A[i][j] = A[i][j] * A[i][j];

If Program 1 yields 8 K page faults and  Program 2 experiences the same number of page faults as Program 1 does. How many page faults would Program 2 experience if the physical memory can store 1 page?

(A) 8M
(B) 16M
(C) 32M
(D) 64M
asked in CO & Architecture by Active (3.2k points) | 275 views
0
someone please explain this question
0
@Bhagyashree

is given ans not correct?
0
Ma'am I don't know whether the ans is correct or not.I am unable to understand the solution
0

@Bhagyashree

Process $1$ has page size $32K$ and it stored in row major

that is why there are page fault $8K$

but Process $2$ has same number of page fault, though it is stored in column major

So, we can say though it is stored in column major, page size hasnot changed.

right?

that means loop $i$ visits $\frac{32K}{8K}=4$ times before going to the second page

Now, process size $32K\times 8K=256M$

What will be page size now?

Will it be $8K$?

I think it shpould be mentioned in question

see herehttps://www.techtud.com/multiple-choice-question/suppose-32-k×8-k-matrix-1-byte-element

 

0
Ma'am I got the point that page size has not changed even though it is in column major .but I am unable to get the part "i loop visits32k/8k =4 times"
0
Sorry it will be $j$ loop

Can u tell me what advantage of row major and column major storing in an array?
0
Ma'am I think it depends upon the requirements of the program.what type of operation we wish to perform.
0

See here row major and column major order.

https://en.wikipedia.org/wiki/Row-_and_column-major_order

Say row=3 and column=4

then for a loop row-major order perform 3 times

but column major executes 4 times

0
Yes ma'am this row nd column majormajor I know.The question says how many page faults if " physical memory can store one page".meaning?
+1
I think it will be like this ,

j is page number for process P1 i.e. row major

and i is page number for P2 i.e. column major

Now, of course we can see P2  require more pages than P1

But, P1 and P2 has same page fault

That means P2 and P1 has same number of pages

So, we can say for loop executing more in P2 to visit 1 page than P1

As size of page in P2= size of page  in P1
0
Finally understud to some extent😋

Thank you ma'am.

1 Answer

0 votes

Given a matrix of size 32K*8K

also given that the page fault of both are equal, which is only possible if the whole matrix can be stored in memory.

Further its mentioned that the number of page fault is 8K which means the page size is 32K

Now we need to find out the number of page fault caused by program2 with page size 32K

Number of page faults in program2 for a single page = 4

for each iteration of for(i = 0; i < 32768; i++) loop there will be 32K/4 page faults = 8K page faults

This is repeated for(j = 0; j < 8192; j++) number of times.

Hence total number of page faults = 8K*8K = 64M

Option D is the correct answer

answered by Active (2.1k points)
0

Number of page faults in program2 for a single page = 4

How?

0

@Arjun

Sorry, I actually ment we can access 4 elements in a page without a page fault.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,412 questions
53,594 answers
185,832 comments
70,878 users