Question

In: Computer Science

Consider the following program: 1 #define Size 64 int A[Size; Size], B[Size; Size], C[Size; Size]; int...

Consider the following program: 1

#define Size 64

int A[Size; Size], B[Size; Size], C[Size; Size];

int register i, j;

for (j = 0; j< Size; j ++) {

{ for (i = 0; i< Size; i++) C[i; j] = A[i; j] + B[i; j]; } }

Assume that the program is running on a system using demand paging and the page size is 1 Kilobyte. Each integer is 4 bytes long. It is clear that each array requires a 16-page space. As an example, A[0, 0] - A[0, 63], A[1, 0] - A[1, 63], A[2, 0] - A[2, 63], and A[3,0] - A[3, 63] will be stored in the first data page. A similar storage pattern can be derived for the rest of array A and for arrays B and C. Assume that the system allocates a 4-page working set for this process. One of the pages will be used by the program and three pages can be used for the data. Also, two index registers are assigned for i and j (so, no memory accesses are needed for references to these two variables).

(a) Discuss how frequently a page fault would occur (in terms of the number of times C[i,j] = A[i,j] + B[i,j] are executed).

(b) Can you modify the program to minimize the page fault frequency?

(c) What will be the frequency of page faults after your modification?

Solutions

Expert Solution

SOLUTION -

We know that :-

for (j = 0; j< Size; j ++)

for (i = 0; i< Size; i++)

C[i; j] = A[i; j] + B[i; j];

Access order according to the above loop is

A[0,0] A[1,0]...A[0,63] , A[1,0],A[1,1]..A[1,63] ,  A[2,0],A[1,1]..A[1,63] ,  A[3,0],A[1,1]..A[1,63] ,
A[4,0] .....A[4,63] etc


And for B its similar,
B[0,0] B[1,0]...B[0,63] , B[1,0],B[1,1]..B[1,63] , B[2,0],B[1,1]..B[1,63] , B[3,0],B[1,1]..B[1,63] ,
B[4,0] .....B[4,63] etc

Coming to the Memory part , We have 4 pages where 1 has the program and 3 have the data set
Lets says A, B, C are in three data set and the storage order is given
A[0, 0]-A[0, 63], A[1, 0]-A[1, 63], A[2, 0]-A[2, 63], and A[3, 0]-A[3, 63] , We can see When j = 4 there is Page fault

A[0, 0]-A[0, 63], A[1, 0]-A[1, 63], A[2, 0]-A[2, 63], and A[3, 0]-A[3, 63] --> 256 elements , each is 4 bytes so total 1024 bytes = 1KB

(A)

Discuss how frequently the page fault would occur (in terms of number of times C[i, j] = A[i, j] + B[i, j] are executed).

---> When j = 4 , we have 3 page faults for A, B, C, So there is three page fault for every 4th execution.

(B)

. Can you modify the program to minimize the page fault frequency?
Yes, We can change the order of execution,i.e

for (i = 0; i< Size; i++)

for (j = 0; j< Size; j ++)

C[i; j] = A[i; j] + B[i; j];

In this way wat will happen is , We will be accessing in A[0,0] A[0,63] ....A[1,0]A[1,63] ... A[63,0],A[63,63] etc
So there will be less page faults

(C)

What will be the frequency of page faults after your modification?
Since we accessed 256 elements from A[0, 0]-A[0, 63], A[1, 0]-A[1, 63], A[2, 0]-A[2, 63], and A[3, 0]-A[3, 63] , B and C as well So there we only three page faults for 256 executions

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

Consider the following program written in C syntax: void swap(int a, int b) { int temp;...
Consider the following program written in C syntax: void swap(int a, int b) { int temp; temp = a; a = b; b = temp;} void main() { int value = 2, list[5] = {1, 3, 5, 7, 9}; swap(value, list[0]); swap(list[0], list[1]); swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three calls to swap? Passed by value Passed by reference Passed...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size 3x3 as private member.        There should be two public methods within the class definition namely: void setMatrixValue(int i, int j); that should set m[i][j] with user defined values int getMatrixValue(int i, int j); that should return m[i][j] Make a global function named ‘CrossProduct(Matrix m1, Matrix m2)’ that should compute the marix multiplication
Convert the following C++ statements to an ARM assembly language program: const int size = 10;...
Convert the following C++ statements to an ARM assembly language program: const int size = 10; int x[size] = {8, 2, 9, 6, 7, 0, 1, 3, 5, 4}; int y[size] = {399, -87, 12, 0, 42, -367, 57, 92, -1000, 25}; for i = 0; i < size; i++) if (x([ i ] > y[ i ]) z[ i ] = 0 else z[ i ] = 1;
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
[C++ Language] Look at the following pseudo code: Binary_search(int a[], int size) { ……….// binary search...
[C++ Language] Look at the following pseudo code: Binary_search(int a[], int size) { ……….// binary search and return } Selection_Sort(int a[], int z) { …..// do the selection sort } main() {     Selection_Sort(array, size);     Binary_Search(array, item); }
Translate the following function f to MIPS assembly code. int f(int a, int b, int c,...
Translate the following function f to MIPS assembly code. int f(int a, int b, int c, int d) { return func(func(a,b), func(b+c,d)); } Assume the followings. • The prototype of function func is “int func(int a, int b);”. • You do not need to implement function func. The first instruction in function func is labeled “FUNC”. • In the implementation of function f, if you need to use registers $t0 through $t7, use the lower-numbered registers first. • In the...
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
Consider the following program. There are 11 statements in the program starting with int x; Show...
Consider the following program. There are 11 statements in the program starting with int x; Show the memory allocated for the program in the stack and heap for each statement. Also, show any values assigned to each of these memory locations. In other words, you will show 11 stacks and 11 heaps as the answer to your question. #include <iostream> using namespace std; int main() { int x; // Stmt 1 int * y; // Stmt 2 y = new...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;       char B=10; cout<<”Enter Value of A”; cin<<A; show(A) show(50)          }       cin.get(); } int show(int x); { cout<<”Value is =” <<X cout<<endl; }
Consider the following C code that outlines Fibonacci function int fib (int n) { if (n...
Consider the following C code that outlines Fibonacci function int fib (int n) { if (n == 0) return 0; else if (n==1) return 1; else return fib(n-1) + fib (n-2); } For this programming assignment, write and test an ARMv8 program to find Fibonacci (n). You need to write a main function that calls the recursive fib function and passes an argument n. The function fib calls itself (recursively) twice to compute fib(n-1) and fib (n-2). The input to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT