matrix multiplication speed depends on silly things
matrix multiplication speed depends on silly things I wrote a program for fast matrix multiplication. To use CPU cache to the maximal extent, it divides matrix to 10*10 cells, and multiplies each cell separately (increasing cell size to 20*20 or 50*50 does not significantly change time). It turns out that the speed significantly depends on whether matrix size and cell size is know in advance or not. The program is: #include <cmath> #include <cstdlib> #include <iostream> using namespace std; #define forall(i,n) for(int i=0; i<(int)(n); i++) inline void Load(int N, int N2, float* x2, float* x, int iStart, int jStart) { int start = iStart * N + jStart; forall (i, N2) forall (j, N2) x2[i * N2 + j] = x[start + i * N + j]; } inline void Add(int N, int N2, float* x, float* x2, int iStart, int jStart) { int start = iStart * N + jStart; forall (i, N2) forall (j, N2) x[start + i * N + j] += x2[i * N2 + j]; } inline voi...