Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a global variable to cache the rank of currently running process.
[simgrid.git] / src / smpi / smpi_bench.c
index d5eb6b3..6dcff87 100644 (file)
@@ -14,6 +14,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi,
 
 xbt_dict_t allocs = NULL;       /* Allocated on first use */
 xbt_dict_t samples = NULL;      /* Allocated on first use */
+int smpi_current_rank = 0;      /* Updated after each MPI call */
 
 typedef struct {
   int count;
@@ -68,6 +69,7 @@ static void smpi_execute(double duration)
 void smpi_bench_begin(void)
 {
   xbt_os_timer_start(smpi_process_timer());
+  smpi_current_rank = smpi_process_index();
 }
 
 void smpi_bench_end(void)
@@ -104,7 +106,7 @@ static char *sample_location(int global, const char *file, int line)
   }
 }
 
-void smpi_sample_1(int global, const char *file, int line, int iters, double threshold)
+int smpi_sample_1(int global, const char *file, int line, int iters, double threshold)
 {
   char *loc = sample_location(global, file, line);
   local_data_t *data;
@@ -123,8 +125,10 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr
     data->threshold = threshold;
     data->started = 0;
     xbt_dict_set(samples, loc, data, &free);
+    return 0;
   }
   free(loc);
+  return 1;
 }
 
 int smpi_sample_2(int global, const char *file, int line)
@@ -132,10 +136,10 @@ int smpi_sample_2(int global, const char *file, int line)
   char *loc = sample_location(global, file, line);
   local_data_t *data;
 
-  xbt_assert0(samples, "You did something very inconsistent, didn't you?");
+  xbt_assert(samples, "You did something very inconsistent, didn't you?");
   data = xbt_dict_get_or_null(samples, loc);
   if (!data) {
-    xbt_assert0(data, "Please, do thing in order");
+    xbt_assert(data, "Please, do thing in order");
   }
   if (!data->started) {
     if ((data->iters > 0 && data->count >= data->iters)
@@ -161,20 +165,20 @@ void smpi_sample_3(int global, const char *file, int line)
   local_data_t *data;
   double sample, n;
 
-  xbt_assert0(samples, "You did something very inconsistent, didn't you?");
+  xbt_assert(samples, "You did something very inconsistent, didn't you?");
   data = xbt_dict_get_or_null(samples, loc);
-  if (!data || !data->started || data->count >= data->iters) {
-    xbt_assert0(data, "Please, do thing in order");
-  }
   smpi_bench_end();
-  sample = smpi_process_simulated_elapsed();
-  data->sum += sample;
-  data->sum_pow2 += sample * sample;
-  n = (double)data->count;
-  data->mean = data->sum / n;
-  data->relstderr = sqrt((data->sum_pow2 / n - data->mean * data->mean) / n) / data->mean;
-  XBT_DEBUG("Average mean after %d steps is %f, relative standard error is %f (sample was %f)", data->count,
-         data->mean, data->relstderr, sample);
+  if(data && data->started && data->count < data->iters) {
+    sample = smpi_process_simulated_elapsed();
+    data->sum += sample;
+    data->sum_pow2 += sample * sample;
+    n = (double)data->count;
+    data->mean = data->sum / n;
+    data->relstderr = sqrt((data->sum_pow2 / n - data->mean * data->mean) / n) / data->mean;
+    XBT_DEBUG("Average mean after %d steps is %f, relative standard error is %f (sample was %f)", data->count,
+           data->mean, data->relstderr, sample);
+  }
+  free(loc);
 }
 
 void smpi_sample_flops(double flops)