Two Loads Or Three
Two orderings of the same double-precision matrix multiply. Cache blocks hold four 8-byte doubles, and is large enough that a full row does not stay resident.
/* A */ for (i=0;i<n;i++) for (j=0;j<n;j++) { s=0;
for (k=0;k<n;k++) s += A[i][k]*B[k][j];
C[i][j] += s; }
/* B */ for (k=0;k<n;k++) for (i=0;i<n;i++) { r=A[i][k];
for (j=0;j<n;j++) C[i][j] += r*B[k][j]; }
A's inner loop does 2 loads and 0 stores. B's does 2 loads and 1 store. Which is faster for large ?
Sign in to answer questions and track your progress
Sign In