Commit c181be81 authored by Neil Gershenfeld's avatar Neil Gershenfeld

wip

parent 6b7276b1
Pipeline #2886 passed with stage
in 1 second
/*
* pi.c
* Neil Gershenfeld 2/6/11
* calculation of pi by a scalar sum
* pi calculation benchmark
* pi = 3.14159265358979323846
*/
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#define NPTS 1000000000
void main() {
int i;
double a,b,c,pi,mflops;
unsigned long int start_time,end_time;
struct timeval start,end;
double a,b,c,pi,dt,mflops;
struct timespec tstart,tend;
clock_gettime(CLOCK_REALTIME,&tstart);
a = 0.5;
b = 0.75;
c = 0.25;
pi = 0;
pi = 0;
gettimeofday(&start, NULL);
for (i = 1; i <= NPTS; ++i)
pi += a/((i-b)*(i-c));
gettimeofday(&end, NULL);
start_time = start.tv_sec * 1e6 + start.tv_usec;
end_time = end.tv_sec * 1e6 + end.tv_usec;
mflops = NPTS*5.0/(end_time-start_time);
clock_gettime(CLOCK_REALTIME,&tend);
dt = (tend.tv_sec+tend.tv_nsec/1e9)-(tstart.tv_sec+tstart.tv_nsec/1e9);
mflops = NPTS*5.0/(dt*1e6);
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