Next: Interchange loops
Up: Chapter1
Previous: If you want to play...
for (i = 0; i < 500; i++)
for (j = 0; j < 500; j++){
r = 0.0;
for (k = 0; k < 500; k++){
r += A[i][k] * B[k][j];
}
C[i][j] = r;
}
- Avoid repeated assignments to memory (note write-through primary
cache).
- 94 seconds (2.65 MFLOPS vs 2.1 MFLOPS: 25% faster).
Paul H J Kelly
Thu Feb 6 22:02:49 GMT 1997