Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added flag for printing more debug info
[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,
5                                 "Logging specific to SMPI (benchmarking)");
6
7 void smpi_execute(double duration)
8 {
9   smx_host_t host = SIMIX_host_self();
10   smx_mutex_t mutex = smpi_process_mutex();
11   smx_cond_t cond = smpi_process_cond();
12   smx_action_t action;
13   e_surf_action_state_t state;
14
15   if (duration < 0.001)
16     return;
17   DEBUG1("Sleep for %f to handle real computation time",duration);
18   SIMIX_mutex_lock(mutex);
19
20   action =
21     SIMIX_action_execute(host, "execute",
22                          duration * smpi_global->reference_speed);
23
24   SIMIX_register_action_to_condition(action, cond);
25   for (state = SIMIX_action_get_state(action);
26        state == SURF_ACTION_READY ||
27        state == SURF_ACTION_RUNNING; state = SIMIX_action_get_state(action)
28     ) {
29     SIMIX_cond_wait(cond, mutex);
30   }
31   SIMIX_unregister_action_to_condition(action, cond);
32   SIMIX_action_destroy(action);
33
34   SIMIX_mutex_unlock(mutex);
35
36   return;
37 }
38
39 void smpi_start_timer()
40 {
41   xbt_os_timer_start(smpi_global->timer);
42 }
43
44 double smpi_stop_timer()
45 {
46   double duration;
47   xbt_os_timer_stop(smpi_global->timer);
48   duration = xbt_os_timer_elapsed(smpi_global->timer);
49   return duration;
50 }
51
52 void smpi_bench_begin()
53 {
54   smpi_start_timer();
55 }
56
57 void smpi_bench_end()
58 {
59   smpi_execute(smpi_stop_timer());
60 }
61
62 void smpi_do_once_1(const char *file, int line)
63 {
64   smpi_do_once_duration_node_t curr, prev;
65   smpi_bench_end();
66   SIMIX_mutex_lock(smpi_global->do_once_mutex);
67   prev = NULL;
68   for (curr = smpi_global->do_once_duration_nodes;
69        NULL != curr && (strcmp(curr->file, file) || curr->line != line);
70        curr = curr->next) {
71     prev = curr;
72   }
73   if (NULL == curr) {
74     curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
75     curr->file = xbt_strdup(file);
76     curr->line = line;
77     curr->duration = -1;
78     curr->next = NULL;
79     if (NULL == prev) {
80       smpi_global->do_once_duration_nodes = curr;
81     } else {
82       prev->next = curr;
83     }
84   }
85   smpi_global->do_once_duration = &curr->duration;
86 }
87
88 int smpi_do_once_2()
89 {
90   double duration = *(smpi_global->do_once_duration);
91   if (0 > duration) {
92     smpi_start_timer();
93     return 1;
94   }
95   SIMIX_mutex_unlock(smpi_global->do_once_mutex);
96   smpi_execute(duration);
97   smpi_bench_begin();
98   return 0;
99 }
100
101 void smpi_do_once_3()
102 {
103   *(smpi_global->do_once_duration) = smpi_stop_timer();
104 }