6 #include "nas_common.h"
7 #include "simgrid/instr.h" //TRACE_
15 int main(int argc, char **argv) {
16 double dum[3] = {1.,1.,1.};
17 double x1, x2, sx, sy, tm, an, gc;
19 double epsilon=1.0E-8, a = 1220703125., s=271828183.;
20 double t1, t2, t3, t4;
21 double sx_verify_value, sy_verify_value, sx_err, sy_err;
25 int nk = (int)(pow(2,mk)),
27 np, node, no_nodes, i, ik, kk, l, k, nit, no_large_nodes, np_add, k_offset;
29 char size[500]; // mind the size of the string to represent a big number
31 double *x = (double *) SMPI_SHARED_MALLOC (2*nk*sizeof(double));
32 double *q = (double *) SMPI_SHARED_MALLOC (nq*sizeof(double));
34 MPI_Init( &argc, &argv );
35 MPI_Comm_size( MPI_COMM_WORLD, &no_nodes);
36 MPI_Comm_rank( MPI_COMM_WORLD, &node);
38 TRACE_smpi_set_category ("start");
40 get_info(argc, argv, &nprocs, &class);
41 check_info(EP, nprocs, class);
45 else if (class == 'W')
47 else if (class == 'A')
49 else if (class == 'B')
51 else if (class == 'C')
53 else if (class == 'D')
55 else if (class == 'E')
58 printf("EP: Internal error: invalid class type %c\n", class);
63 int nn = (int)(pow(2,mm));
67 /* Because the size of the problem is too large to store in a 32-bit integer for some classes, we put it into a
68 * string (for printing). Have to strip off the decimal point put in there by the floating point print statement
70 fprintf(stdout," NAS Parallel Benchmarks 3.2 -- EP Benchmark");
71 snprintf(size,500,"%lu",(unsigned long)pow(2,m+1));
72 fprintf(stdout," Number of random numbers generated: %s\n",size);
73 fprintf(stdout," Number of active processes: %d\n",no_nodes);
76 /* Compute the number of "batches" of random number pairs generated per processor. Adjust if the number of processors
77 * does not evenly divide the total number */
79 no_large_nodes = nn % no_nodes;
80 if (node < no_large_nodes)
87 fprintf(stdout,"Too many nodes: %d %d",no_nodes,nn);
88 MPI_Abort(MPI_COMM_WORLD,1);
92 /* Call the random number generator functions and initialize the x-array to reduce the effects of paging the timings.
93 Also, call all mathematical functions that are used. Make sure initializations cannot be eliminated as dead code. */
94 vranlc(0, dum[0], dum[1], &(dum[2]));
96 dum[0] = randlc(&(dum[1]),&(dum[2]));
97 for (i=0;i<2*nk;i++) {
101 /* Synchronize before placing time stamp */
102 MPI_Barrier( MPI_COMM_WORLD );
104 TRACE_smpi_set_category ("ep");
112 t1 = vranlc(0, t1, a, x);
114 /* Compute AN = A ^ (2 * NK) (mod 2^46). */
116 for (i=1; i <= mk+1; i++) {
117 t2 = randlc(&t1, &t1);
123 for (i=0; i < nq ; i++) {
127 /* Each instance of this loop may be performed independently. We compute the k offsets separately to take into account
128 * the fact that some nodes have more numbers to generate than others */
130 k_offset = node * np -1;
132 k_offset = no_large_nodes*(np+1) + (node-no_large_nodes)*np -1;
135 SMPI_SAMPLE_GLOBAL(k = 1, k <= np, k++, 0.25 * np, 0.03){
141 // Find starting seed t1 for this kk.
142 for (i=1;i<=100 && !stop;i++) {
154 // Compute uniform pseudorandom numbers.
158 t1 = vranlc(2 * nk, t1, a, x);
162 /* Compute Gaussian deviates by acceptance-rejection method and tally counts in concentric square annuli.
163 * This loop is not vectorizable. */
166 for(i=1; i<=nk;i++) {
167 x1 = 2. * x[2*i-2] -1.0;
168 x2 = 2. * x[2*i-1] - 1.0;
171 t2 = sqrt(-2. * log(t1) / t1);
174 l = (int)(fabs(t3) > fabs(t4) ? fabs(t3) : fabs(t4));
183 TRACE_smpi_set_category ("finalize");
185 MPI_Allreduce(&sx, x, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
187 MPI_Allreduce(&sy, x, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
189 MPI_Allreduce(q, x, nq, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
191 for(i = 0; i < nq; i++) {
194 for(i = 0; i < nq; i++) {
200 MPI_Allreduce(&tm, x, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
210 sx_verify_value = -3.247834652034740E3;
211 sy_verify_value = -6.958407078382297E3;
213 sx_verify_value = -2.863319731645753E3;
214 sy_verify_value = -6.320053679109499E3;
216 sx_verify_value = -4.295875165629892E3;
217 sy_verify_value = -1.580732573678431E4;
219 sx_verify_value = 4.033815542441498E4;
220 sy_verify_value = -2.660669192809235E4;
222 sx_verify_value = 4.764367927995374E4;
223 sy_verify_value = -8.084072988043731E4;
225 sx_verify_value = 1.982481200946593E5;
226 sy_verify_value = -1.020596636361769E5;
232 sx_err = fabs((sx - sx_verify_value)/sx_verify_value);
233 sy_err = fabs((sy - sy_verify_value)/sy_verify_value);
234 verified = ((sx_err < epsilon) && (sy_err < epsilon));
237 Mops = (pow(2.0, m+1))/tm/1000;
239 fprintf(stdout,"EP Benchmark Results:\n");
240 fprintf(stdout,"CPU Time=%d\n",(int) tm);
241 fprintf(stdout,"N = 2^%d\n",m);
242 fprintf(stdout,"No. Gaussain Pairs =%d\n",(int) gc);
243 fprintf(stdout,"Sum = %f %ld\n",sx,(long) sy);
244 fprintf(stdout,"Count:");
245 for(i = 0; i < nq; i++) {
246 fprintf(stdout,"%d\t %ld\n",i,(long) q[i]);
248 c_print_results("EP", class, m+1, 0, 0, nit, nprocs, no_nodes, tm, Mops, "Random number generated",verified);
250 fprintf(stdout,"Total time: %f\n",(timer_read(1)/1000));
251 fprintf(stdout,"Gaussian pairs: %f\n",(timer_read(2)/1000));
252 fprintf(stdout,"Random numbers: %f\n",(timer_read(3)/1000));