Logo AND Algorithmique Numérique Distribuée

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