Révision 196
Pi/C/Simple/Pi_Simple.c (revision 196) | ||
---|---|---|
7 | 7 |
#include <math.h> |
8 | 8 |
#include <stdio.h> |
9 | 9 |
#include <stdlib.h> |
10 |
#include <omp.h> |
|
11 | 10 |
#include <limits.h> |
11 |
#include <sys/time.h> |
|
12 | 12 |
|
13 | 13 |
// Marsaglia RNG very simple implementation |
14 | 14 |
#define znew ((z=36969*(z&65535)+(z>>16))<<16) |
... | ... | |
18 | 18 |
#define CONG (jcong=69069*jcong+1234567) |
19 | 19 |
#define KISS ((MWC^CONG)+SHR3) |
20 | 20 |
|
21 |
#define MWCfp (float)MWC*2.3283064365386963e-10f
|
|
22 |
#define KISSfp (float)KISS*2.328306435454494e-10f
|
|
23 |
#define SHR3fp (float)SHR3*2.328306435454494e-10f
|
|
24 |
#define CONGfp (float)CONG*2.328306435454494e-10f
|
|
21 |
#define MWCfp MWC*2.328306435454494e-10f
|
|
22 |
#define KISSfp KISS*2.328306435454494e-10f |
|
23 |
#define SHR3fp SHR3*2.328306435454494e-10f |
|
24 |
#define CONGfp CONG*2.328306435454494e-10f |
|
25 | 25 |
|
26 | 26 |
#define ITERATIONS 1000000000 |
27 | 27 |
|
... | ... | |
125 | 125 |
|
126 | 126 |
unsigned int seed_w=110271,seed_z=101008; |
127 | 127 |
LENGTH iterations=ITERATIONS,inside=0; |
128 |
|
|
128 |
struct timeval tv1,tv2; |
|
129 |
struct timezone tz; |
|
130 |
|
|
129 | 131 |
if (argc > 1) { |
130 | 132 |
iterations=(LENGTH)atoll(argv[1]); |
131 | 133 |
} |
... | ... | |
144 | 146 |
printf ("\tMax long = %ld\n", LONG_MAX); |
145 | 147 |
printf ("\tMax long long = %lld\n\n", LLONG_MAX); |
146 | 148 |
|
149 |
// Set start timer |
|
150 |
gettimeofday(&tv1, &tz); |
|
151 |
|
|
147 | 152 |
inside=MainLoopGlobal(iterations,seed_w,seed_z); |
153 |
|
|
154 |
// Set stop timer |
|
155 |
gettimeofday(&tv2, &tz); |
|
148 | 156 |
|
149 |
float pi=4.*(float)inside/(float)iterations; |
|
157 |
double elapsed=(double)((tv2.tv_sec-tv1.tv_sec) * 1000000L + |
|
158 |
(tv2.tv_usec-tv1.tv_usec))/1000000; |
|
159 |
|
|
160 |
double itops=(double)(iterations)/elapsed; |
|
161 |
|
|
162 |
printf("Inside/Total %ld %ld\nElapsed Time %.2f\nItops %.0f\nPi estimation %f\n\n",inside,iterations,elapsed,itops,(4.*(float)inside/(float)(iterations))); |
|
150 | 163 |
|
151 |
printf("\t%lld inside for %lld iterations\n", |
|
152 |
(long long)inside,(long long)iterations); |
|
153 |
printf("\tPi=%f with error %f\n\n", |
|
154 |
pi,fabs(pi-4*atan(1))/pi); |
|
164 |
printf("\n\n"); |
|
165 |
|
|
166 |
return 0; |
|
155 | 167 |
|
156 | 168 |
} |
Formats disponibles : Unified diff