Commit c181be81 authored by Neil Gershenfeld's avatar Neil Gershenfeld

wip

parent 6b7276b1
Pipeline #2886 passed with stage
in 1 second
/* /*
* pi.c * pi.c
* Neil Gershenfeld 2/6/11 * Neil Gershenfeld 2/6/11
* calculation of pi by a scalar sum * pi calculation benchmark
* pi = 3.14159265358979323846 * pi = 3.14159265358979323846
*/ */
#include <stdio.h> #include <stdio.h>
#include <sys/time.h> #include <time.h>
#define NPTS 1000000000 #define NPTS 1000000000
void main() { void main() {
int i; int i;
double a,b,c,pi,mflops; double a,b,c,pi,dt,mflops;
unsigned long int start_time,end_time; struct timespec tstart,tend;
struct timeval start,end; clock_gettime(CLOCK_REALTIME,&tstart);
a = 0.5; a = 0.5;
b = 0.75; b = 0.75;
c = 0.25; c = 0.25;
pi = 0; pi = 0;
pi = 0; pi = 0;
gettimeofday(&start, NULL);
for (i = 1; i <= NPTS; ++i) for (i = 1; i <= NPTS; ++i)
pi += a/((i-b)*(i-c)); pi += a/((i-b)*(i-c));
gettimeofday(&end, NULL); clock_gettime(CLOCK_REALTIME,&tend);
start_time = start.tv_sec * 1e6 + start.tv_usec; dt = (tend.tv_sec+tend.tv_nsec/1e9)-(tstart.tv_sec+tstart.tv_nsec/1e9);
end_time = end.tv_sec * 1e6 + end.tv_usec; mflops = NPTS*5.0/(dt*1e6);
mflops = NPTS*5.0/(end_time-start_time);
printf("NPTS = %d, pi = %f\n",NPTS,pi); printf("NPTS = %d, pi = %f\n",NPTS,pi);
printf("time = %f, estimated MFlops = %f\n",(end_time-start_time)/1.0e6,mflops); printf("time = %f, estimated MFlops = %f\n",dt,mflops);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment