19
//---NOTE : all the timers function have been modified to
20
// avoid global timers (privatize these).
21
// ----------------------- timers ---------------------
22
void timer_clear(double *onetimer) {
27
void timer_start(double *onetimer) {
28
*onetimer = MPI_Wtime();
31
void timer_stop(int n,double *elapsed,double *start) {
39
double timer_read(int n, double *elapsed) { /* ok, useless, but jsut to keep function call */
42
/********************************************************************
43
***************** V R A N L C ******************
44
***************** *****************/
45
double vranlc(int n, double x, double a, double *y)
48
long i246m1=0x00003FFFFFFFFFFF;
52
// This doesn't work, because the compiler does the calculation in 32
53
// bits and overflows. No standard way (without f90 stuff) to specify
54
// that the rhs should be done in 64 bit arithmetic.
55
// parameter(i246m1=2**46-1)
59
// c Note that the v6 compiler on an R8000 does something stupid with
60
// c the above. Using the following instead (or various other things)
61
// c makes the calculation run almost 10 times as fast.
64
// c data d2m46/0.0d0/
65
// c if (d2m46 .eq. 0.0d0) then
66
// c d2m46 = 0.5d0**46
71
//fprintf(stdout,("================== Vranlc ================");
72
//fprintf(stdout,("Before Loop: Lx = " + Lx + ", La = " + La);
74
for (i=0; i< n; i++) {
77
y[i] = d2m46 * (double)LLx;
80
fprintf(stdout,("After loop 0:");
81
fprintf(stdout,("Lx = " + Lx + ", La = " + La);
82
fprintf(stdout,("d2m46 = " + d2m46);
83
fprintf(stdout,("LLX(Lx) = " + LLX.doubleValue());
84
fprintf(stdout,("Y[0]" + y[0]);
91
fprintf(stdout,("Change: Lx = " + Lx);
92
fprintf(stdout,("=============End Vranlc ================");
99
//-------------- the core (unique function) -----------
100
void doTest(int argc, char **argv) {
101
double dum[3] = {1.,1.,1.};
102
double x1, x2, sx, sy, tm, an, tt, gc;
104
double epsilon=1.0E-8, a = 1220703125., s=271828183.;
105
double t1, t2, t3, t4;
106
double sx_verify_value, sy_verify_value, sx_err, sy_err;
108
#include "npbparams.h"
110
// --> set by make : in npbparams.h
111
//m=28, // for CLASS=A
112
//m=30, // for CLASS=B
115
nn = (int)(pow(2,mm)),
116
nk = (int)(pow(2,mk)),
125
k, nit, no_large_nodes,
127
int me, nprocs, root=0, dp_type;
130
char size[500]; // mind the size of the string to represent a big number
134
double R23, R46, T23, T46;
136
double *qq = (double *) malloc (10000*sizeof(double));
137
double *start = (double *) malloc (64*sizeof(double));
138
double *elapsed = (double *) malloc (64*sizeof(double));
140
double *x = (double *) malloc (2*nk*sizeof(double));
141
double *q = (double *) malloc (nq*sizeof(double));
143
MPI_Init( &argc, &argv );
144
MPI_Comm_size( MPI_COMM_WORLD, &no_nodes);
145
MPI_Comm_rank( MPI_COMM_WORLD, &node);
153
/* Because the size of the problem is too large to store in a 32-bit
154
* integer for some classes, we put it into a string (for printing).
155
* Have to strip off the decimal point put in there by the floating
156
* point print statement (internal file)
158
fprintf(stdout," NAS Parallel Benchmarks 3.2 -- EP Benchmark");
159
sprintf(size,"%d",pow(2,m+1));
160
//size = size.replace('.', ' ');
161
fprintf(stdout," Number of random numbers generated: %s\n",size);
162
fprintf(stdout," Number of active processes: %d\n",no_nodes);
167
/* c Compute the number of "batches" of random number pairs generated
168
c per processor. Adjust if the number of processors does not evenly
169
c divide the total number
173
no_large_nodes = nn % no_nodes;
174
if (node < no_large_nodes) np_add = 1;
179
fprintf(stdout,"Too many nodes: %d %d",no_nodes,nn);
180
MPI_Abort(MPI_COMM_WORLD,1);
184
/* c Call the random number generator functions and initialize
185
c the x-array to reduce the effects of paging on the timings.
186
c Also, call all mathematical functions that are used. Make
187
c sure these initializations cannot be eliminated as dead code.
190
//call vranlc(0, dum[1], dum[2], dum[3]);
191
// Array indexes start at 1 in Fortran, 0 in Java
192
vranlc(0, dum[0], dum[1], &(dum[2]));
194
dum[0] = randlc(&(dum[1]),&(dum[2]));
195
/////////////////////////////////
196
for (i=0;i<2*nk;i++) {
199
Mops = log(sqrt(abs(1)));
202
c---------------------------------------------------------------------
203
c Synchronize before placing time stamp
204
c---------------------------------------------------------------------
206
MPI_Barrier( MPI_COMM_WORLD );
208
timer_clear(&(elapsed[1]));
209
timer_clear(&(elapsed[2]));
210
timer_clear(&(elapsed[3]));
211
timer_start(&(start[1]));
214
//fprintf(stdout,("(ep.f:160) t1 = " + t1);
215
t1 = vranlc(0, t1, a, x);
216
//fprintf(stdout,("(ep.f:161) t1 = " + t1);
219
/* c Compute AN = A ^ (2 * NK) (mod 2^46). */
222
//fprintf(stdout,("(ep.f:165) t1 = " + t1);
223
for (i=1; i <= mk+1; i++) {
224
t2 = randlc(&t1, &t1);
225
//fprintf(stdout,("(ep.f:168)[loop i=" + i +"] t1 = " + t1);
228
//fprintf(stdout,("(ep.f:172) s = " + s);
233
for (i=0; i < nq ; i++) {
238
Each instance of this loop may be performed independently. We compute
239
the k offsets separately to take into account the fact that some nodes
240
have more numbers to generate than others
244
k_offset = node * np -1;
246
k_offset = no_large_nodes*(np+1) + (node-no_large_nodes)*np -1;
249
for(k = 1; k <= np; k++) SMPI_SAMPLE_LOCAL(0.25 * np, 0.03) {
253
//fprintf(stdout,("(ep.f:193) t1 = " + t1);
256
// Find starting seed t1 for this kk.
258
for (i=1;i<=100 && !stop;i++) {
260
//fprintf(stdout,("(ep.f:199) ik = " +ik+", kk = " + kk);
262
t3 = randlc(&t1, &t2);
263
//fprintf(stdout,("(ep.f:200) t1= " +t1 );
268
t3 = randlc(&t2, &t2);
272
// Compute uniform pseudorandom numbers.
274
//if (timers_enabled) timer_start(3);
275
timer_start(&(start[3]));
276
//call vranlc(2 * nk, t1, a, x) --> t1 and y are modified
278
//fprintf(stdout,">>>>>>>>>>>Before vranlc(l.210)<<<<<<<<<<<<<");
279
//fprintf(stdout,"2*nk = " + (2*nk));
280
//fprintf(stdout,"t1 = " + t1);
281
//fprintf(stdout,"a = " + a);
282
//fprintf(stdout,"x[0] = " + x[0]);
283
//fprintf(stdout,">>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<");
285
t1 = vranlc(2 * nk, t1, a, x);
287
//fprintf(stdout,(">>>>>>>>>>>After Enter vranlc (l.210)<<<<<<");
288
//fprintf(stdout,("2*nk = " + (2*nk));
289
//fprintf(stdout,("t1 = " + t1);
290
//fprintf(stdout,("a = " + a);
291
//fprintf(stdout,("x[0] = " + x[0]);
292
//fprintf(stdout,(">>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<");
294
//if (timers_enabled) timer_stop(3);
295
timer_stop(3,elapsed,start);
297
/* Compute Gaussian deviates by acceptance-rejection method and
298
* tally counts in concentric square annuli. This loop is not
301
//if (timers_enabled) timer_start(2);
302
timer_start(&(start[2]));
303
for(i=1; i<=nk;i++) {
304
x1 = 2. * x[2*i-2] -1.0;
305
x2 = 2. * x[2*i-1] - 1.0;
308
t2 = sqrt(-2. * log(t1) / t1);
311
l = (int)(abs(t3) > abs(t4) ? abs(t3) : abs(t4));
318
fprintf(stdout,"x1 = " + x1);
319
fprintf(stdout,"x2 = " + x2);
320
fprintf(stdout,"t1 = " + t1);
321
fprintf(stdout,"t2 = " + t2);
322
fprintf(stdout,"t3 = " + t3);
323
fprintf(stdout,"t4 = " + t4);
324
fprintf(stdout,"l = " + l);
325
fprintf(stdout,"q[l] = " + q[l]);
326
fprintf(stdout,"sx = " + sx);
327
fprintf(stdout,"sy = " + sy);
331
//if (timers_enabled) timer_stop(2);
332
timer_stop(2,elapsed,start);
335
//int MPI_Allreduce(void *sbuf, void *rbuf, int count, MPI_Datatype dtype, MPI_Op op, MPI_Comm comm)
336
MPI_Allreduce(&sx, x, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
337
sx = x[0]; //FIXME : x[0] or x[1] => x[0] because fortran starts with 1
338
MPI_Allreduce(&sy, x, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
340
MPI_Allreduce(q, x, nq, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
342
for(i = 0; i < nq; i++) {
345
for(i = 0; i < nq; i++) {
349
timer_stop(1,elapsed,start);
350
tm = timer_read(1,elapsed);
351
MPI_Allreduce(&tm, x, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
359
sx_verify_value = -3.247834652034740E3;
360
sy_verify_value = -6.958407078382297E3;
362
sx_verify_value = -2.863319731645753E3;
363
sy_verify_value = -6.320053679109499E3;
365
sx_verify_value = -4.295875165629892E3;
366
sy_verify_value = -1.580732573678431E4;
368
sx_verify_value = 4.033815542441498E4;
369
sy_verify_value = -2.660669192809235E4;
371
sx_verify_value = 4.764367927995374E4;
372
sy_verify_value = -8.084072988043731E4;
374
sx_verify_value = 1.982481200946593E5;
375
sy_verify_value = -1.020596636361769E5;
381
fprintf(stdout,("sx = " + sx);
382
fprintf(stdout,("sx_verify = " + sx_verify_value);
383
fprintf(stdout,("sy = " + sy);
384
fprintf(stdout,("sy_verify = " + sy_verify_value);
387
sx_err = abs((sx - sx_verify_value)/sx_verify_value);
388
sy_err = abs((sy - sy_verify_value)/sy_verify_value);
390
fprintf(stdout,("sx_err = " + sx_err);
391
fprintf(stdout,("sy_err = " + sx_err);
392
fprintf(stdout,("epsilon= " + epsilon);
394
verified = ((sx_err < epsilon) && (sy_err < epsilon));
397
Mops = (pow(2.0, m+1))/tm/1000;
399
fprintf(stdout,"EP Benchmark Results:\n");
400
fprintf(stdout,"CPU Time=%d\n",tm);
401
fprintf(stdout,"N = 2^%d\n",m);
402
fprintf(stdout,"No. Gaussain Pairs =%d\n",gc);
403
fprintf(stdout,"Sum = %lf %ld\n",sx,sy);
404
fprintf(stdout,"Count:");
405
for(i = 0; i < nq; i++) {
406
fprintf(stdout,"%d\t %ld\n",i,q[i]);
410
print_results("EP", _class, m+1, 0, 0, nit, npm, no_nodes, tm, Mops,
411
"Random numbers generated", verified, npbversion,
412
compiletime, cs1, cs2, cs3, cs4, cs5, cs6, cs7) */
413
fprintf(stdout,"\nEP Benchmark Completed\n");
414
fprintf(stdout,"Class = %s\n", _class);
415
fprintf(stdout,"Size = %s\n", size);
416
fprintf(stdout,"Iteration = %d\n", nit);
417
fprintf(stdout,"Time in seconds = %lf\n",(tm/1000));
418
fprintf(stdout,"Total processes = %d\n",no_nodes);
419
fprintf(stdout,"Mops/s total = %lf\n",Mops);
420
fprintf(stdout,"Mops/s/process = %lf\n", Mops/no_nodes);
421
fprintf(stdout,"Operation type = Random number generated\n");
423
fprintf(stdout,"Verification = SUCCESSFUL\n");
425
fprintf(stdout,"Verification = UNSUCCESSFUL\n");
427
fprintf(stdout,"Total time: %lf\n",(timer_read(1,elapsed)/1000));
428
fprintf(stdout,"Gaussian pairs: %lf\n",(timer_read(2,elapsed)/1000));
429
fprintf(stdout,"Random numbers: %lf\n",(timer_read(3,elapsed)/1000));
432
MPE_Finish_log(argv[0]);
438
int main(int argc, char **argv) {