Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
refactored smpi into multiple source files.
[simgrid.git] / src / smpi / smpi_util.c
diff --git a/src/smpi/smpi_util.c b/src/smpi/smpi_util.c
new file mode 100644 (file)
index 0000000..b7df6a8
--- /dev/null
@@ -0,0 +1,55 @@
+#include "private.h"
+
+int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+       double now;
+       int retval = 0;
+       smpi_bench_end();
+       if (NULL == tv) {
+               retval = -1;
+       } else {
+               now = SIMIX_get_clock();
+               tv->tv_sec  = now;
+               tv->tv_usec = ((now - (double)tv->tv_sec) * 1000000.0);
+       }
+       smpi_bench_begin();
+       return retval;
+}
+
+unsigned int smpi_sleep(unsigned int seconds)
+{
+       smx_mutex_t mutex;
+       smx_cond_t cond;
+       smx_host_t host;
+       smx_action_t sleep_action;
+
+       smpi_bench_end();
+       host         = SIMIX_host_self();
+       sleep_action = SIMIX_action_sleep(host, seconds);
+       mutex        = SIMIX_mutex_init();
+       cond         = SIMIX_cond_init();
+
+       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: check for success/failure?
+
+       smpi_bench_begin();
+       return 0;
+}
+
+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);
+       SIMIX_process_kill(SIMIX_process_self());
+       return;
+}