Hard
Striding down a column of a 1024x1024 matrix
matrix is N x N of double (8 bytes), with N = 1024 (a power of two), so each row is exactly 8192 bytes. The L1 data cache is 32 KB, 8-way set-associative with 64-byte lines (so 64 sets), and the whole matrix fits comfortably inside the much larger shared L3. This loop sums column-major, so the inner loop jumps a full row each iteration. What happens, and why?
main.cpp
double sum = 0;
for (int j = 0; j < N; ++j) {
for (int i = 0; i < N; ++i) {
sum += matrix[i][j]; // stride N*sizeof(double) = 8192 bytes between consecutive i
}
}10 of 47 in Computer Architecture