Created
September 25, 2014 22:34
-
-
Save spikebike/1f5d06b42a96258430b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/time.h> | |
/* crude wall clock time keeping, returns a double of seconds */ | |
double | |
seconds() | |
{ | |
struct timeval tp; | |
struct timezone tzp; | |
gettimeofday (&tp, &tzp); | |
return ((double) tp.tv_sec + (double) tp.tv_usec * 1.e-6); | |
} | |
/* allocate 3 512MB arrays, 64M each */ | |
#define SIZE 67108864 | |
main() | |
{ | |
double *a,*b,*c; | |
double start,stop,diff; | |
int i,mem; | |
a=(double *) malloc(SIZE*sizeof(double)); | |
b=(double *) malloc(SIZE*sizeof(double)); | |
c=(double *) malloc(SIZE*sizeof(double)); | |
for (i=0;i<SIZE;i++) | |
{ | |
b[i]=i*1.25; | |
c[i]=i*1.9; | |
} | |
start=seconds(); | |
for (i=0;i<SIZE;i++) | |
{ | |
a[i]=b[i]*c[i]; | |
} | |
stop=seconds(); | |
diff=stop-start; | |
mem=(SIZE*sizeof(double)*3); | |
printf ("%d double flops took %f seconds\n",SIZE,diff); | |
printf ("%f Mflops/sec\n",SIZE/(diff*1000000)); | |
printf ("total size of 3 arrays = %d MB\n",mem/(1024*1024)); | |
printf ("memory bandwidth = %5.2f GB/sec\n",(mem/(1048*1024*1024))/diff); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ./a.out
67108864 double flops took 0.123589 seconds
543.000129 Mflops/sec
total size of 3 arrays = 1536 MB
memory bandwidth = 8.09 GB/sec