News for hackers. Stuff that matters.
Re:The software development final exam: Computer Architectur... by andyjohnson0 on Tuesday October 09, 2012 @07:34AM (#4630954)
In zeroarray1 the address to be zeroed goes linearly from 0 to (1024^2)-1. This generates less cache misses because the address is much more likely to already be in the cache, which is in turn because the address only differes by one from the previous value of the address.

zeroarray2 jumps around (0, 1024, 2048, 4096, ..., 1, 1025, 2049, 4097, ...) in a way that intentionally makes life difficult for the cpu's cache manager, and generating lots of cache misses.

Re:The software development final exam: Computer Architectur... by dagw on Tuesday October 09, 2012 @09:21AM (#4631322)
Also worth noting that this is language dependent. What you say is true in C (which is admittedly what the question was about), but not true in for example Fortran.

edit: Ignore. I'm wrong, see below

Re:The software development final exam: Computer Architectur... by andyjohnson0 on Tuesday October 09, 2012 @09:32AM (#4631380)
I'm not doubting what you say, but could you elaborate on why Fortran is different?

I could understand a difference for two-dimensional (or more) arrays, where different languages lay-out the array contents in memory differently. Does Fortran lay-out the contents of one dimensional arrays in an unusual way?

Re:The software development final exam: Computer Architectur... by dagw on Tuesday October 09, 2012 @10:07AM (#4631534)
Sorry, I screwed up. I skimmed the question and mis-remebered it when making my post. I thought the question looked like:

  for(i=0...
    for(j=0...
      A[i][j]=0;
vs

  for(i=0...
    for(j=0...
      A[j][i]=0;
In which case C vs Fortran makes a difference to the way multidimensional arrays are stored in memory.