Find expert advice and community support for all your questions on IDNLearn.com. Ask anything and get well-informed, reliable answers from our knowledgeable community members.

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. Assume each word is 32‐bit integer. (hint: 2D array in C stores in row first order).
For (I = 0; I < 8; I++)
For (J = 0; J < 8000; J++)
A[I][J] = B[I][0] + A[J][I];
(1) How many 32‐bit integers can be stored in a 16‐byte cache block?
(2) References to which variables exhibit temporal locality?
(3) References to which variables exhibit spatial locality?


Sagot :

Answer:

  1. Four 32-bit integers can be stored in a 16-byte cache block, since 4 x 32 bits = 128 bits = 16 bytes.
  2. References to the elements of the A and B arrays exhibit temporal locality, since they are accessed multiple times within the inner loop of the code.
  3. References to the elements of the A array exhibit spatial locality, since they are accessed sequentially within the inner loop of the code, with each access being in the same row but in a different column.