X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1507b62960f85534246bbcc97d4ea26ef5b3c2c3..d6ce3162b34f0a964b8844368b9d86df4f1cf89b:/src/smpi/smpi_util.c diff --git a/src/smpi/smpi_util.c b/src/smpi/smpi_util.c new file mode 100644 index 0000000000..b7df6a8a60 --- /dev/null +++ b/src/smpi/smpi_util.c @@ -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; +}