Next: ... Up: Chapter1 Previous: Optimising memory accesses

Blocking

The idea of ``blocking'' (a.k.a. ``tiling'') is to reorder the execution of the loop nest so that data is not evicted from the cache before it is needed again. E.g.

for (kk = 0; kk < 500; kk += BLKSZ)
 for (jj = 0; jj < 500; jj += BLKSZ)
  for (i = 0; i < 500; i++)
   for (k = kk; k < min(kk+BLKSZ,500); k++){
    r = A[i][k];
     for (j = jj; j < min(jj+BLKSZ, 500); j++)
      C[i][j] += r * B[k][j];
    }


Paul H J Kelly Thu Feb 6 22:02:49 GMT 1997