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
How many 16 byte cache lines are needed to store all 32-bit matrix
elements being referenced?
解答: a 3186 = 8 * (800/4) * 2 – 8 * (8/4) + 8/4
b 3596 = 8 * (800/4) * 2 – 8 * (8/4) + 8000/4
想請教板上的各位這是怎麼解出來的?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.31.133.241
※ 編輯: aerystyle 來自: 61.31.133.241 (06/05 14:17)