Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b64c2f7a3a13119451a1a52dcb81b328c3c8dabc
[simgrid.git] / src / smpi / smpi_bench.c
1 #include "private.h"
2
3 void smpi_execute(double duration) {
4         smx_host_t host = SIMIX_host_self();
5         smx_action_t action;
6
7         SIMIX_mutex_lock(smpi_global->execute_mutex);
8
9         action = SIMIX_action_execute(host, "computation", duration * SMPI_DEFAULT_SPEED);
10
11         SIMIX_register_action_to_condition(action, smpi_global->execute_cond);
12         SIMIX_cond_wait(smpi_global->execute_cond, smpi_global->execute_mutex);
13         SIMIX_unregister_action_to_condition(action, smpi_global->execute_cond);
14         SIMIX_action_destroy(action);
15
16         SIMIX_mutex_unlock(smpi_global->execute_mutex);
17
18         return;
19 }
20
21 void smpi_bench_begin()
22 {
23         SIMIX_mutex_lock(smpi_global->timer_mutex);
24         xbt_os_timer_start(smpi_global->timer);
25         return;
26 }
27
28 double smpi_bench_end()
29 {
30         double duration;
31
32         xbt_os_timer_stop(smpi_global->timer);
33
34         duration = xbt_os_timer_elapsed(smpi_global->timer);
35
36         SIMIX_mutex_unlock(smpi_global->timer_mutex);
37
38         smpi_execute(duration);
39
40         return duration;
41 }
42
43
44 void smpi_bench_skip() {
45         double duration = smpi_global->times[0];
46         smpi_execute(duration);
47         return;
48 }
49
50 void smpi_do_once_1() {
51         smpi_bench_end();
52         SIMIX_mutex_lock(smpi_global->times_mutex);
53         if (0 < smpi_global->times[0]) {
54                 smpi_bench_skip();
55         }
56         return;
57 }
58
59 int smpi_do_once_2() {
60         int retval = 1;
61         if (0 < smpi_global->times[0]) {
62                 SIMIX_mutex_unlock(smpi_global->times_mutex);
63                 retval = 0;
64         }
65         smpi_bench_begin();
66         return retval;
67 }
68
69 void smpi_do_once_3() {
70         smpi_global->times[0] = smpi_bench_end();
71         return;
72 }