Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Squeeze any block with a given delay (in flops).
authorpini <pini@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 29 Sep 2010 16:14:59 +0000 (16:14 +0000)
committerpini <pini@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 29 Sep 2010 16:14:59 +0000 (16:14 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8300 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/smpi/smpi.h
src/smpi/smpi_bench.c

index c6540cd..9842282 100644 (file)
@@ -245,6 +245,7 @@ XBT_PUBLIC(int) smpi_gettimeofday(struct timeval* tv, struct timezone* tz);
 XBT_PUBLIC(void) smpi_sample_1(int global, const char* file, int line, int max);
 XBT_PUBLIC(int) smpi_sample_2(int global, const char* file, int line);
 XBT_PUBLIC(void) smpi_sample_3(int global, const char* file, int line);
+XBT_PUBLIC(void) smpi_sample_flops(double flops);
 
 #define SMPI_SAMPLE_LOCAL(num) for(smpi_sample_1(0, __FILE__, __LINE__, num); \
                                    smpi_sample_2(0, __FILE__, __LINE__);      \
@@ -254,6 +255,8 @@ XBT_PUBLIC(void) smpi_sample_3(int global, const char* file, int line);
                                     smpi_sample_2(1, __FILE__, __LINE__);      \
                                     smpi_sample_3(1, __FILE__, __LINE__))
 
+#define SMPI_SAMPLE_DELAY(flops) for(smpi_sample_flops(flops); 0; )
+
 XBT_PUBLIC(void*) smpi_shared_malloc(size_t size, const char* file, int line);
 #define SMPI_SHARED_MALLOC(size) smpi_shared_malloc(size, __FILE__, __LINE__)
 
index 2667045..387cac4 100644 (file)
@@ -35,32 +35,36 @@ void smpi_bench_destroy(void) {
    }
 }
 
-static void smpi_execute(double duration) {
+static void smpi_execute_flops(double flops) {
   smx_host_t host;
   smx_action_t action;
   smx_mutex_t mutex;
   smx_cond_t cond;
   e_surf_action_state_t state;
 
+  host = SIMIX_host_self();
+  mutex = SIMIX_mutex_init();
+  cond = SIMIX_cond_init();
+  DEBUG1("Handle real computation time: %f flops", flops);
+  action = SIMIX_action_execute(host, "computation", flops);
+  SIMIX_mutex_lock(mutex);
+  SIMIX_register_action_to_condition(action, cond);
+  for(state = SIMIX_action_get_state(action);
+      state == SURF_ACTION_READY ||
+      state == SURF_ACTION_RUNNING; state = SIMIX_action_get_state(action)) {
+    SIMIX_cond_wait(cond, mutex);
+  }
+  SIMIX_unregister_action_to_condition(action, cond);
+  SIMIX_mutex_unlock(mutex);
+  SIMIX_action_destroy(action);
+  SIMIX_cond_destroy(cond);
+  SIMIX_mutex_destroy(mutex);
+}
+
+static void smpi_execute(double duration) {
   if(duration >= xbt_cfg_get_double(_surf_cfg_set, "smpi/cpu_threshold")) {
-    host = SIMIX_host_self();
-    mutex = SIMIX_mutex_init();
-    cond = SIMIX_cond_init();
     DEBUG1("Sleep for %f to handle real computation time", duration);
-    duration *= xbt_cfg_get_double(_surf_cfg_set, "smpi/running_power");
-    action = SIMIX_action_execute(host, "computation", duration);
-    SIMIX_mutex_lock(mutex);
-    SIMIX_register_action_to_condition(action, cond);
-    for(state = SIMIX_action_get_state(action);
-        state == SURF_ACTION_READY ||
-        state == SURF_ACTION_RUNNING; state = SIMIX_action_get_state(action)) {
-      SIMIX_cond_wait(cond, mutex);
-    }
-    SIMIX_unregister_action_to_condition(action, cond);
-    SIMIX_mutex_unlock(mutex);
-    SIMIX_action_destroy(action);
-    SIMIX_cond_destroy(cond);
-    SIMIX_mutex_destroy(mutex);
+    smpi_execute_flops(duration * xbt_cfg_get_double(_surf_cfg_set, "smpi/running_power"));
   }
 }
 
@@ -164,6 +168,10 @@ void smpi_sample_3(int global, const char* file, int line) {
    DEBUG2("Average mean after %d steps is %f", data->count, data->time / (double)data->count);
 }
 
+void smpi_sample_flops(double flops) {
+   smpi_execute_flops(flops);
+}
+
 void* smpi_shared_malloc(size_t size, const char* file, int line) {
    char* loc = bprintf("%s:%d:%zu", file, line, size);
    shared_data_t* data;