Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

consider a cashe memory that provides three hundred 16 byte blocks. Now consider

ID: 3650968 • Letter: C

Question

consider a cashe memory that provides three hundred 16 byte blocks. Now consider that you are processing all of the data in a two dimensional array of, say, four hundred rows by 400 hundred columns, using a pair of nested loops. Assume that the program stores the array column by column. You can write the program to nest the loops in either direction, that is, process row by row or column by column. Explain which way to process the data. What is the advantage? What is disadvantage of processing it the other way?

Explanation / Answer

Column by column. The program stores the array column by column, so each column is contiguous (all 400 values are right next to each other in memory), and each row is scattered (the values are located at every 400th position). That means that you can load most (or all) of the column into the cache (note spelling). If you did it row by row, the computer would have to read a new column into the cache every time.