Question: Exercise 5.2 In this exercise we look at memory locality properties of matrix computation. The following code is written in C, where elements within the

Exercise 5.2 In this exercise we look at memory locality properties of matrix computation. The following code is written in C, where elements within the same row are stored contiguously.

a. for (I=0; I<8000; I++)

for (J=0; J<8; J++)

A[I][J]=B[J][0]+A[J][I];

b. for (J=0; J<8; J++)

for (I=0; I<8000; I++)

A[I][J]=B[J][0]+A[J][I];

5.2.1 [5] <5.1> How many 32-bit integers can be stored in a 16-byte cache line?

5.2.2 [5] <5.1> References to which variables exhibit temporal locality?

5.2.3 [5] <5.1> References to which variables exhibit spatial locality?

Locality is affected by both the reference order and data layout. The same computation can also be written below in Matlab, which differs from C by contiguously storing matrix elements within the same column.

a. for I=1:8000 for J=1:8 A(I,J)=B(J,0)+A(J,I);

end end

b. for J=1:8 for I=1:8000 A(I,J) = B(J,0) + A(J,I);

end end 5.2.4 [10] <5.1> How many 16-byte cache lines are needed to store all 32-bit matrix elements being referenced?
5.2.5 [5] <5.1> References to which variables exhibit temporal locality?
5.2.6 [5] <5.1> References to which variables exhibit spatial locality?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock