Logo AND Algorithmique Numérique Distribuée

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