Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[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_mutex_t mutex;
26         smx_cond_t cond;
27         smx_action_t action;
28         e_surf_action_state_t state;
29
30         smpi_bench_end();
31
32         host  = SIMIX_host_self();
33         mutex = smpi_host_mutex();
34         cond  = smpi_host_cond();
35
36         SIMIX_mutex_lock(mutex);
37
38         // FIXME: explicit conversion to double?
39         action = SIMIX_action_sleep(host, seconds);
40
41         SIMIX_register_action_to_condition(action, cond);
42         for (
43                 state =  SIMIX_action_get_state(action);
44                 state == SURF_ACTION_READY ||
45                 state == SURF_ACTION_RUNNING;
46                 state =  SIMIX_action_get_state(action)
47         ) {
48                 SIMIX_cond_wait(cond, mutex);
49         }
50         SIMIX_unregister_action_to_condition(action, cond);
51         SIMIX_action_destroy(action);
52
53         SIMIX_mutex_unlock(mutex);
54
55         smpi_bench_begin();
56         return 0;
57 }
58
59 void smpi_exit(int status)
60 {
61         smpi_bench_end();
62         smpi_mpi_finalize();
63         SIMIX_process_kill(SIMIX_process_self());
64         return;
65 }