Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleaning up and refactoring some of the code to create execution actions.
[simgrid.git] / src / smpi / smpi_bench.c
index 7f193c0..b64c2f7 100644 (file)
@@ -1,51 +1,72 @@
 #include "private.h"
 
-// FIXME: could cause trouble with multithreaded procs on same host...
-// FIXME: add benchmarking flag?
+void smpi_execute(double duration) {
+        smx_host_t host = SIMIX_host_self();
+        smx_action_t action;
 
-void smpi_bench_begin()
-{
-       int rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
+       SIMIX_mutex_lock(smpi_global->execute_mutex);
+
+       action = SIMIX_action_execute(host, "computation", duration * SMPI_DEFAULT_SPEED);
+
+        SIMIX_register_action_to_condition(action, smpi_global->execute_cond);
+        SIMIX_cond_wait(smpi_global->execute_cond, smpi_global->execute_mutex);
+        SIMIX_unregister_action_to_condition(action, smpi_global->execute_cond);
+        SIMIX_action_destroy(action);
 
-       SIMIX_mutex_lock(smpi_global->timers_mutexes[rank]);
+        SIMIX_mutex_unlock(smpi_global->execute_mutex);
 
-       xbt_os_timer_start(smpi_global->timers[rank]);
+       return;
+}
 
+void smpi_bench_begin()
+{
+       SIMIX_mutex_lock(smpi_global->timer_mutex);
+       xbt_os_timer_start(smpi_global->timer);
        return;
 }
 
-void smpi_bench_end()
+double smpi_bench_end()
 {
-       int rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
        double duration;
-       smx_host_t host;
-       char computation[] = "computation";
-       smx_action_t action;
-       smx_mutex_t mutex;
-       smx_cond_t cond;
 
-       xbt_os_timer_stop(smpi_global->timers[rank]);
+       xbt_os_timer_stop(smpi_global->timer);
 
-       duration = xbt_os_timer_elapsed(smpi_global->timers[rank]);
+       duration = xbt_os_timer_elapsed(smpi_global->timer);
 
-       SIMIX_mutex_unlock(smpi_global->timers_mutexes[rank]);
+       SIMIX_mutex_unlock(smpi_global->timer_mutex);
 
-       host   = smpi_mpi_global->mpi_comm_world->hosts[rank];
-       action = SIMIX_action_execute(host, computation, duration * SMPI_DEFAULT_SPEED);
-       mutex  = SIMIX_mutex_init();
-       cond   = SIMIX_cond_init();
+       smpi_execute(duration);
 
-       SIMIX_mutex_lock(mutex);
-       SIMIX_register_action_to_condition(action, cond);
-       SIMIX_cond_wait(cond, mutex);
-       SIMIX_unregister_action_to_condition(action, cond);
-       SIMIX_mutex_unlock(mutex);
+       return duration;
+}
+
+
+void smpi_bench_skip() {
+       double duration = smpi_global->times[0];
+       smpi_execute(duration);
+       return;
+}
 
-       SIMIX_mutex_destroy(mutex);
-       SIMIX_cond_destroy(cond);
-       //SIMIX_action_destroy(action);
+void smpi_do_once_1() {
+       smpi_bench_end();
+       SIMIX_mutex_lock(smpi_global->times_mutex);
+       if (0 < smpi_global->times[0]) {
+               smpi_bench_skip();
+       }
+       return;
+}
 
-       // FIXME: check for success/failure?
+int smpi_do_once_2() {
+       int retval = 1;
+       if (0 < smpi_global->times[0]) {
+               SIMIX_mutex_unlock(smpi_global->times_mutex);
+               retval = 0;
+       }
+       smpi_bench_begin();
+       return retval;
+}
 
+void smpi_do_once_3() {
+       smpi_global->times[0] = smpi_bench_end();
        return;
 }