Table of Contents

Cache locality (1D FDTD)

Cache locality describes how nearby memory accesses reuse cached data. The magnetic loop traverses contiguous arrays and reads overlapping electric neighborhoods:

for (size_t k = 0; k < width - 1; k++) {
    Hy[k] = Ch1[k] * Hy[k] 
          + Ch2[k] * (Ez[k + 1] - Ez[k]);
}

Iteration k reads Ez[k + 1]; the next iteration reads that element again as its left neighbor. Consecutive accesses can reuse cache lines instead of fetching unrelated locations.

Static scheduling gives threads contiguous iteration blocks. This preserves sequential traversal, although writes near block boundaries may share cache lines. As the working set exceeds cache capacity, more traffic reaches main memory. The benchmark can suggest this transition; cache-miss counters are needed to measure it directly.

Source: fdtd_ez_kernels.c.