Write subroutines, with prototypes identical to mult(), which perform the following operations:
sub(x,1.000001)to perform the computation. This measures the time needed to make the subroutine calls. To prevent the compiler from automatically in-lining the subroutine, you should put sub() in a separate file.
p=dvector(0,1); free_dvector(p,0,1);This gives a feel for the cost of making calls to the operating system.
x+=x*0.000001;Note that each of these counts as two FLOP (one add and one multiply).
for (k=0; k<n; k++)
for (i=0; i<n; i++)
for (j=0; j<n; j++)
M3[i][j]=M1[i][j];
Note that this loop will
run a lot slower than mult(), which does a number of multiplies
equal to the number of copies here. This gives an idea of the
cost of accessing the main memory.
Finally, in main, uncomment the timer() calls to your new routines as well as the section of print statements labeled ``Print out time ratios.'' Running your code for various sizes, you should find that most operations proceed at a constant rate, except for the cmat operations. The speed of these depends on the size of your matrices compared to the size of the cache memory!
Tomas Arias 2007-03-16