Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
71946a832937761c09cd6a945e85dca32731a251
[simgrid.git] / src / smpi / smpi_util.c
1 #include "private.h"
2
3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_util, smpi, "Logging specific to SMPI (utilities)");
4
5 int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
6 {
7         double now;
8         int retval;
9         smpi_bench_end();
10         retval = 0;
11         if (NULL == tv) {
12                 retval = -1;
13         } else {
14                 now = SIMIX_get_clock();
15                 tv->tv_sec  = now;
16                 tv->tv_usec = ((now - (double)tv->tv_sec) * 1000000.0);
17         }
18         smpi_bench_begin();
19         return retval;
20 }
21
22 unsigned int smpi_sleep(unsigned int seconds)
23 {
24         smx_host_t host;
25         smx_action_t action;
26
27         smpi_bench_end();
28
29         host  = SIMIX_host_self();
30
31         SIMIX_mutex_lock(smpi_global->execute_mutex);
32
33         // FIXME: explicit conversion to double?
34         action = SIMIX_action_sleep(host, seconds);
35
36         SIMIX_register_action_to_condition(action, smpi_global->execute_cond);
37         SIMIX_cond_wait(smpi_global->execute_cond, smpi_global->execute_mutex);
38         SIMIX_unregister_action_to_condition(action, smpi_global->execute_cond);
39         SIMIX_action_destroy(action);
40
41         SIMIX_mutex_unlock(smpi_global->execute_mutex);
42
43         smpi_bench_begin();
44         return 0;
45 }
46
47 void smpi_exit(int status)
48 {
49         smpi_bench_end();
50         smpi_mpi_finalize();
51         SIMIX_process_kill(SIMIX_process_self());
52         return;
53 }