Logo AND Algorithmique Numérique Distribuée

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