Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change spmirun and smpicc to use bash instead of sh and smpi_mpi to use qsort
[simgrid.git] / src / smpi / smpi_util.c
index b7df6a8..596c294 100644 (file)
@@ -1,10 +1,13 @@
 #include "private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_util, smpi, "Logging specific to SMPI (utilities)");
+
 int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
        double now;
-       int retval = 0;
+       int retval;
        smpi_bench_end();
+       retval = 0;
        if (NULL == tv) {
                retval = -1;
        } else {
@@ -18,27 +21,36 @@ int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
 
 unsigned int smpi_sleep(unsigned int seconds)
 {
+       smx_host_t host;
        smx_mutex_t mutex;
        smx_cond_t cond;
-       smx_host_t host;
-       smx_action_t sleep_action;
+       smx_action_t action;
+       e_surf_action_state_t state;
 
        smpi_bench_end();
-       host         = SIMIX_host_self();
-       sleep_action = SIMIX_action_sleep(host, seconds);
-       mutex        = SIMIX_mutex_init();
-       cond         = SIMIX_cond_init();
+
+       host  = SIMIX_host_self();
+       mutex = smpi_host_mutex();
+       cond  = smpi_host_cond();
 
        SIMIX_mutex_lock(mutex);
-       SIMIX_register_action_to_condition(sleep_action, cond);
-       SIMIX_cond_wait(cond, mutex);
-       SIMIX_unregister_action_to_condition(sleep_action, cond);
-       SIMIX_mutex_unlock(mutex);
 
-       SIMIX_mutex_destroy(mutex);
-       SIMIX_cond_destroy(cond);
+       // FIXME: explicit conversion to double?
+       action = SIMIX_action_sleep(host, seconds);
+
+       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_action_destroy(action);
 
-       // FIXME: check for success/failure?
+       SIMIX_mutex_unlock(mutex);
 
        smpi_bench_begin();
        return 0;
@@ -47,9 +59,7 @@ unsigned int smpi_sleep(unsigned int seconds)
 void smpi_exit(int status)
 {
        smpi_bench_end();
-       SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
-       smpi_global->running_hosts_count--;
-       SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex);
+       smpi_mpi_finalize();
        SIMIX_process_kill(SIMIX_process_self());
        return;
 }