Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This should be a per process variable.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 31 Oct 2013 22:25:37 +0000 (23:25 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 31 Oct 2013 22:53:27 +0000 (23:53 +0100)
src/smpi/private.h
src/smpi/smpi_bench.c
src/smpi/smpi_global.c
src/smpi/smpi_pmpi.c

index 9ea8fb4..12dbaaf 100644 (file)
@@ -114,6 +114,8 @@ smx_rdv_t smpi_process_remote_mailbox_small(int index);
 xbt_os_timer_t smpi_process_timer(void);
 void smpi_process_simulated_start(void);
 double smpi_process_simulated_elapsed(void);
 xbt_os_timer_t smpi_process_timer(void);
 void smpi_process_simulated_start(void);
 double smpi_process_simulated_elapsed(void);
+void smpi_process_set_sampling(int s);
+int smpi_process_get_sampling(void);
 
 void print_request(const char *message, MPI_Request request);
 
 
 void print_request(const char *message, MPI_Request request);
 
@@ -290,7 +292,6 @@ int smpi_coll_basic_alltoallv(void *sendbuf, int *sendcounts,
 // utilities
 extern double smpi_cpu_threshold;
 extern double smpi_running_power;
 // utilities
 extern double smpi_cpu_threshold;
 extern double smpi_running_power;
-extern int smpi_sample_is_running;
 void smpi_bench_destroy(void);
 void smpi_bench_begin(void);
 void smpi_bench_end(void);
 void smpi_bench_destroy(void);
 void smpi_bench_begin(void);
 void smpi_bench_end(void);
index 8376fa4..3992750 100644 (file)
@@ -243,8 +243,6 @@ typedef struct {
   int benching;     /* 1: we are benchmarking; 0: we have enough data, no bench anymore */
 } local_data_t;
 
   int benching;     /* 1: we are benchmarking; 0: we have enough data, no bench anymore */
 } local_data_t;
 
-int smpi_sample_is_running = 0;
-
 static char *sample_location(int global, const char *file, int line) {
   if (global) {
     return bprintf("%s:%d", file, line);
 static char *sample_location(int global, const char *file, int line) {
   if (global) {
     return bprintf("%s:%d", file, line);
@@ -272,7 +270,7 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr
   local_data_t *data;
 
   smpi_bench_end();     /* Take time from previous, unrelated computation into account */
   local_data_t *data;
 
   smpi_bench_end();     /* Take time from previous, unrelated computation into account */
-  smpi_sample_is_running++;
+  smpi_process_set_sampling(1);
 
   if (!samples)
     samples = xbt_dict_new_homogeneous(free);
 
   if (!samples)
     samples = xbt_dict_new_homogeneous(free);
@@ -309,6 +307,7 @@ int smpi_sample_2(int global, const char *file, int line)
 {
   char *loc = sample_location(global, file, line);
   local_data_t *data;
 {
   char *loc = sample_location(global, file, line);
   local_data_t *data;
+  int res;
 
   xbt_assert(samples, "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   data = xbt_dict_get(samples, loc);
 
   xbt_assert(samples, "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   data = xbt_dict_get(samples, loc);
@@ -319,19 +318,18 @@ int smpi_sample_2(int global, const char *file, int line)
     // we need to run a new bench
     XBT_DEBUG("benchmarking: count:%d iter:%d stderr:%f thres:%f; mean:%f",
         data->count, data->iters, data->relstderr, data->threshold, data->mean);
     // we need to run a new bench
     XBT_DEBUG("benchmarking: count:%d iter:%d stderr:%f thres:%f; mean:%f",
         data->count, data->iters, data->relstderr, data->threshold, data->mean);
-    smpi_bench_begin();
-    return 1;
+    res = 1;
   } else {
     // Enough data, no more bench (either we got enough data from previous visits to this benched nest, or we just ran one bench and need to bail out now that our job is done).
     // Just sleep instead
     XBT_DEBUG("No benchmark (either no need, or just ran one): count >= iter (%d >= %d) or stderr<thres (%f<=%f). apply the %fs delay instead",
         data->count, data->iters, data->relstderr, data->threshold, data->mean);
     smpi_execute(data->mean);
   } else {
     // Enough data, no more bench (either we got enough data from previous visits to this benched nest, or we just ran one bench and need to bail out now that our job is done).
     // Just sleep instead
     XBT_DEBUG("No benchmark (either no need, or just ran one): count >= iter (%d >= %d) or stderr<thres (%f<=%f). apply the %fs delay instead",
         data->count, data->iters, data->relstderr, data->threshold, data->mean);
     smpi_execute(data->mean);
-
-    smpi_sample_is_running--;
-    smpi_bench_begin(); // prepare to capture future, unrelated computations
-    return 0;
+    smpi_process_set_sampling(0);
+    res = 0; // prepare to capture future, unrelated computations
   }
   }
+  smpi_bench_begin();
+  return res;
 }
 
 
 }
 
 
index 842b659..290b7c5 100644 (file)
@@ -30,6 +30,7 @@ typedef struct s_smpi_process_data {
   void *data;                   /* user data */
   int index;
   int initialized;
   void *data;                   /* user data */
   int index;
   int initialized;
+  int sampling;                 /* inside an SMPI_SAMPLE_ block? */
 } s_smpi_process_data_t;
 
 static smpi_process_data_t *process_data = NULL;
 } s_smpi_process_data_t;
 
 static smpi_process_data_t *process_data = NULL;
@@ -253,6 +254,18 @@ MPI_Comm smpi_process_comm_self(void)
   return data->comm_self;
 }
 
   return data->comm_self;
 }
 
+void smpi_process_set_sampling(int s)
+{
+  smpi_process_data_t data = smpi_process_data();
+  data->sampling = s;
+}
+
+int smpi_process_get_sampling(void)
+{
+  smpi_process_data_t data = smpi_process_data();
+  return data->sampling;
+}
+
 void print_request(const char *message, MPI_Request request)
 {
   XBT_DEBUG
 void print_request(const char *message, MPI_Request request)
 {
   XBT_DEBUG
@@ -301,6 +314,7 @@ void smpi_global_init(void)
     group = smpi_group_new(1);
     process_data[i]->comm_self = smpi_comm_new(group);
     process_data[i]->initialized = 0;
     group = smpi_group_new(1);
     process_data[i]->comm_self = smpi_comm_new(group);
     process_data[i]->initialized = 0;
+    process_data[i]->sampling = 0;
 
     smpi_group_set_mapping(group, i, 0);
   }
 
     smpi_group_set_mapping(group, i, 0);
   }
index 349bb58..1339144 100644 (file)
@@ -131,7 +131,7 @@ int PMPI_Abort(MPI_Comm comm, int errorcode)
 double PMPI_Wtime(void)
 {
   double time;
 double PMPI_Wtime(void)
 {
   double time;
-  if (smpi_process_initialized() && !smpi_process_finalized() && !smpi_sample_is_running) {
+  if (smpi_process_initialized() && !smpi_process_finalized() && !smpi_process_get_sampling()) {
     smpi_bench_end();
     time = SIMIX_get_clock();
     smpi_bench_begin();
     smpi_bench_end();
     time = SIMIX_get_clock();
     smpi_bench_begin();