Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reindent and only one timer type
[simgrid.git] / examples / smpi / NAS / ep.c
index c56cf20..33aa77e 100644 (file)
@@ -19,26 +19,16 @@ int main(int argc, char **argv) {
   double epsilon=1.0E-8, a = 1220703125., s=271828183.;
   double t1, t2, t3, t4;
   double sx_verify_value, sy_verify_value, sx_err, sy_err;
+  int timers_enabled = true;
 
   int    m, mk=16,
          mm, nn,
          nk = (int)(pow(2,mk)), 
          nq=10, 
-         np, 
-         node, 
-         no_nodes, 
-         i, 
-         ik, 
-         kk, 
-         l, 
-         k, nit, no_large_nodes,
-         np_add, k_offset;
+         np, node, no_nodes, i, ik, kk, l, k, nit, no_large_nodes, np_add, k_offset;
   int    root=0;
-  int verified;
-  char  size[500]; // mind the size of the string to represent a big number
-
-  double *start = (double *) malloc (64*sizeof(double));
-  double *elapsed = (double *) malloc (64*sizeof(double));
+  int    verified;
+  char   size[500]; // mind the size of the string to represent a big number
 
   double *x = (double *) malloc (2*nk*sizeof(double));
   double *q = (double *) malloc (nq*sizeof(double));
@@ -70,8 +60,7 @@ int main(int argc, char **argv) {
   if (node == root ) {
     /* Because the size of the problem is too large to store in a 32-bit integer for some classes, we put it into a
      * string (for printing). Have to strip off the decimal point put in there by the floating point print statement
-     * (internal file)
-     */
+     * (internal file) */
     fprintf(stdout," NAS Parallel Benchmarks 3.2 -- EP Benchmark");
     sprintf(size,"%zu",(unsigned long)pow(2,m+1));
     //size = size.replace('.', ' ');
@@ -81,9 +70,7 @@ int main(int argc, char **argv) {
   verified = false;
 
   /* Compute the number of "batches" of random number pairs generated per processor. Adjust if the number of processors
-   * does not evenly divide the total number
-   */
-
+   * does not evenly divide the total number  */
   np = nn / no_nodes;
   no_large_nodes = nn % no_nodes;
   if (node < no_large_nodes) np_add = 1;
@@ -109,15 +96,15 @@ int main(int argc, char **argv) {
   }
   Mops = log(sqrt(abs(1)));
 
-   /* Synchronize before placing time stamp */
+  /* Synchronize before placing time stamp */
   MPI_Barrier( MPI_COMM_WORLD );
 
   TRACE_smpi_set_category ("ep");
 
-  time_clear(&(elapsed[1]));
-  time_clear(&(elapsed[2]));
-  time_clear(&(elapsed[3]));
-  time_start(&(start[1]));
+  timer_clear(1);
+  timer_clear(2);
+  timer_clear(3);
+  timer_start(1);
 
   t1 = a;
   //fprintf(stdout,("(ep.f:160) t1 = " + t1);
@@ -143,7 +130,6 @@ int main(int argc, char **argv) {
 
 /* Each instance of this loop may be performed independently. We compute the k offsets separately to take into account
  * the fact that some nodes have more numbers to generate than others */
-
   if (np_add == 1)
     k_offset = node * np -1;
   else
@@ -175,7 +161,7 @@ int main(int argc, char **argv) {
     //       Compute uniform pseudorandom numbers.
 
     //if (timers_enabled)  timer_start(3);
-    time_start(&(start[3]));
+    timer_start(3);
     //call vranlc(2 * nk, t1, a, x)  --> t1 and y are modified
 
     //fprintf(stdout,">>>>>>>>>>>Before vranlc(l.210)<<<<<<<<<<<<<");
@@ -194,12 +180,11 @@ int main(int argc, char **argv) {
     //fprintf(stdout,(">>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<");
 
     //if (timers_enabled)  timer_stop(3);
-    time_stop(3,elapsed,start);
+    timer_stop(3);
 
     /* Compute Gaussian deviates by acceptance-rejection method and tally counts in concentric square annuli.
      * This loop is not vectorizable. */
-    //if (timers_enabled) timer_start(2);
-    time_start(&(start[2]));
+    if (timers_enabled) timer_start(2);
     for(i=1; i<=nk;i++) {
       x1 = 2. * x[2*i-2] -1.0;
       x2 = 2. * x[2*i-1] - 1.0;
@@ -228,8 +213,7 @@ int main(int argc, char **argv) {
        }
        */
     }
-    //if (timers_enabled)  timer_stop(2);
-    time_stop(2,elapsed,start);
+    if (timers_enabled)  timer_stop(2);
   }
 
   TRACE_smpi_set_category ("finalize");
@@ -247,8 +231,8 @@ int main(int argc, char **argv) {
     gc += q[i];
   }
 
-  time_stop(1,elapsed,start);
-  tm = time_read(1,elapsed);
+  timer_stop(1);
+  tm = timer_read(1);
   MPI_Allreduce(&tm, x, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
   tm = x[0];
 
@@ -308,9 +292,9 @@ int main(int argc, char **argv) {
     }
     c_print_results("EP", class, m+1, 0, 0, nit, nprocs, no_nodes, tm, Mops, "Random number generated",verified);
 
-    fprintf(stdout,"Total time:     %f\n",(time_read(1,elapsed)/1000));
-    fprintf(stdout,"Gaussian pairs: %f\n",(time_read(2,elapsed)/1000));
-    fprintf(stdout,"Random numbers: %f\n",(time_read(3,elapsed)/1000));
+    fprintf(stdout,"Total time:     %f\n",(timer_read(1)/1000));
+    fprintf(stdout,"Gaussian pairs: %f\n",(timer_read(2)/1000));
+    fprintf(stdout,"Random numbers: %f\n",(timer_read(3)/1000));
   }
 
   MPI_Finalize();