Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6bb7a8df9a1116188700a88622e27fca0be57e7f
[simgrid.git] / src / smpi / smpi_bench.c
1 #include "private.h"
2 #include <string.h>
3
4 void smpi_execute(double duration) {
5         smx_host_t host = SIMIX_host_self();
6         smx_action_t action;
7
8         SIMIX_mutex_lock(smpi_global->execute_mutex);
9
10         action = SIMIX_action_execute(host, "execute", duration * SMPI_DEFAULT_SPEED);
11
12         SIMIX_register_action_to_condition(action, smpi_global->execute_cond);
13         SIMIX_cond_wait(smpi_global->execute_cond, smpi_global->execute_mutex);
14         SIMIX_unregister_action_to_condition(action, smpi_global->execute_cond);
15         SIMIX_action_destroy(action);
16
17         SIMIX_mutex_unlock(smpi_global->execute_mutex);
18
19         return;
20 }
21
22 void smpi_start_timer()
23 {
24         SIMIX_mutex_lock(smpi_global->timer_mutex);
25         xbt_os_timer_start(smpi_global->timer);
26 }
27
28 double smpi_stop_timer()
29 {
30         double duration;
31         xbt_os_timer_stop(smpi_global->timer);
32         duration = xbt_os_timer_elapsed(smpi_global->timer);
33         SIMIX_mutex_unlock(smpi_global->timer_mutex);
34         return duration;
35 }
36
37 void smpi_bench_begin()
38 {
39         smpi_start_timer();
40 }
41
42 void smpi_bench_end()
43 {
44         smpi_execute(smpi_stop_timer());
45 }
46
47 void smpi_do_once_1(const char *file, int line) {
48         smpi_do_once_duration_node_t curr, prev;
49         smpi_bench_end();
50         SIMIX_mutex_lock(smpi_global->do_once_mutex);
51         prev = NULL;
52         for(curr = smpi_global->do_once_duration_nodes;
53                 NULL != curr && (strcmp(curr->file, file) || curr->line != line);
54                 curr = curr->next) {
55                 prev = curr;
56         }
57         if (NULL == curr) {
58                 curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
59                 curr->file = xbt_strdup(file);
60                 curr->line = line;
61                 curr->duration = -1;
62                 curr->next = NULL;
63                 if (NULL == prev) {
64                         smpi_global->do_once_duration_nodes = curr;
65                 } else {
66                         prev->next = curr;
67                 }
68         }
69         smpi_global->do_once_duration = &curr->duration;
70 }
71
72 int smpi_do_once_2() {
73         double duration = *(smpi_global->do_once_duration);
74         if (0 < duration) {
75                 SIMIX_mutex_unlock(smpi_global->do_once_mutex);
76                 smpi_execute(duration);
77                 smpi_bench_begin();
78                 return 0;
79         }
80         smpi_start_timer();
81         return 1;
82 }
83
84 void smpi_do_once_3() {
85         *(smpi_global->do_once_duration) = smpi_stop_timer();
86 }