Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
made some changes to allow more than one DO_ONCE block. also fixed bug in
[simgrid.git] / src / smpi / smpi_bench.c
index aec13c0..6bb7a8d 100644 (file)
@@ -1,49 +1,86 @@
 #include "private.h"
+#include <string.h>
 
-// FIXME: could cause trouble with multithreaded procs on same host...
-void smpi_bench_begin()
-{
-       int rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
+void smpi_execute(double duration) {
+        smx_host_t host = SIMIX_host_self();
+        smx_action_t action;
+
+       SIMIX_mutex_lock(smpi_global->execute_mutex);
 
-       SIMIX_mutex_lock(smpi_global->timers_mutexes[rank]);
+       action = SIMIX_action_execute(host, "execute", duration * SMPI_DEFAULT_SPEED);
 
-       xbt_os_timer_start(smpi_global->timers[rank]);
+        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_unlock(smpi_global->execute_mutex);
 
        return;
 }
 
-void smpi_bench_end()
+void smpi_start_timer()
 {
-       int rank = smpi_mpi_comm_rank_self(smpi_mpi_global->mpi_comm_world);
-       double duration;
-       smx_host_t host;
-       char compute[] = "compute";
-       smx_action_t action;
-       smx_mutex_t mutex;
-       smx_cond_t cond;
-
-       xbt_os_timer_stop(smpi_global->timers[rank]);
-
-       duration = xbt_os_timer_elapsed(smpi_global->timers[rank]);
+       SIMIX_mutex_lock(smpi_global->timer_mutex);
+       xbt_os_timer_start(smpi_global->timer);
+}
 
-       SIMIX_mutex_unlock(smpi_global->timers_mutexes[rank]);
+double smpi_stop_timer()
+{
+       double duration;
+       xbt_os_timer_stop(smpi_global->timer);
+       duration = xbt_os_timer_elapsed(smpi_global->timer);
+       SIMIX_mutex_unlock(smpi_global->timer_mutex);
+       return duration;
+}
 
-       host   = smpi_mpi_global->mpi_comm_world->hosts[rank];
-       action = SIMIX_action_execute(host, compute, duration * SMPI_DEFAULT_SPEED);
-       mutex  = SIMIX_mutex_init();
-       cond   = SIMIX_cond_init();
+void smpi_bench_begin()
+{
+       smpi_start_timer();
+}
 
-       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);
+void smpi_bench_end()
+{
+       smpi_execute(smpi_stop_timer());
+}
 
-       SIMIX_mutex_destroy(mutex);
-       SIMIX_cond_destroy(cond);
-       SIMIX_action_destroy(action);
+void smpi_do_once_1(const char *file, int line) {
+       smpi_do_once_duration_node_t curr, prev;
+       smpi_bench_end();
+       SIMIX_mutex_lock(smpi_global->do_once_mutex);
+       prev = NULL;
+       for(curr = smpi_global->do_once_duration_nodes;
+               NULL != curr && (strcmp(curr->file, file) || curr->line != line);
+               curr = curr->next) {
+               prev = curr;
+       }
+       if (NULL == curr) {
+               curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
+               curr->file = xbt_strdup(file);
+               curr->line = line;
+               curr->duration = -1;
+               curr->next = NULL;
+               if (NULL == prev) {
+                       smpi_global->do_once_duration_nodes = curr;
+               } else {
+                       prev->next = curr;
+               }
+       }
+       smpi_global->do_once_duration = &curr->duration;
+}
 
-       // FIXME: check for success/failure?
+int smpi_do_once_2() {
+       double duration = *(smpi_global->do_once_duration);
+       if (0 < duration) {
+               SIMIX_mutex_unlock(smpi_global->do_once_mutex);
+               smpi_execute(duration);
+               smpi_bench_begin();
+               return 0;
+       }
+       smpi_start_timer();
+       return 1;
+}
 
-       return;
+void smpi_do_once_3() {
+       *(smpi_global->do_once_duration) = smpi_stop_timer();
 }