#include #include #define maxloops 1000 #define maxdim 10000 #define TYPE double //TYPE dot(TYPE *a, TYPE *b, int n) static __inline__ TYPE dot(TYPE *a, TYPE *b, int n) { int k = n - 1; TYPE s = 0.0; for(; k >= 0; k--) { s = s + a[k]*b[k]; } return s; } main() { struct sched_param mysched; struct tms timei, timef; int i, flops; TYPE a[maxdim] = {maxdim*3.14}, b[maxdim] = {maxdim*3.14}, s; /* mysched.sched_priority = 99; if( sched_setscheduler( 0, SCHED_FIFO, &mysched ) == -1 ){ puts(" ERRORE SETTAGGIO SCHEDULER "); perror( "errno" ); exit( 0 ); } */ //printf("> GONE <\n"); times(&timei); s = 0.; for(i = 1; i <= maxloops; i++) { s += dot(a, b, maxdim); } times(&timef); i = timef.tms_utime - timei.tms_utime; flops = (float)maxloops*(float)maxdim*100.0/i; //printf("S = %le, flops = %d.\n", s, flops); //printf("S = %le, time = %d.%d (s), flops = %d.\n", s, i/100, i%100, flops); printf("S = %le\n", s); exit(0); }