Logo AND Algorithmique Numérique Distribuée

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