for(i=0; i<256; i++) A[i] = A[i] + B[2*i];
How many bytes will be written to memory if the cache has a write-through policy? I calculated it as follows: The cache can store the whole array with 2 elements per block (block size = 8bytes, element size = 4bytes). For every write, the whole block will be copied. For $0^{th}$ element, the block containing $0^{th}$ and $1^{st}$ element would be written. The same would be done for $1^{st}$ element as well. So, for every iteration the 2 elements would be written. This makes the number of bytes as $256*2* (4bytes / element) = 2048bytes$. But in the solution, they have just calculated the number of loop iterations ($256$) multiplied by the element size ($4byte$) which makes the answer $1024bytes$. If this is true, then the cache would update only the updated byte (not the whole block). Which is correct?
Asked By : Shashwat
Answered By : Reza
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/9221