Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SMPI over SIMIX_network in a two days rush.
[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;
10   smx_action_t action;
11   smx_mutex_t mutex;
12   smx_cond_t cond;
13   e_surf_action_state_t state;
14
15
16   if(duration > 0.001) {
17     host = SIMIX_host_self();
18     mutex = SIMIX_mutex_init();
19     cond = SIMIX_cond_init();
20     DEBUG1("Sleep for %f to handle real computation time", duration);
21     duration *= xbt_cfg_get_double(_surf_cfg_set, "reference_speed");
22     action = SIMIX_action_sleep(host, duration);
23     SIMIX_mutex_lock(mutex);
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       SIMIX_cond_wait(cond, mutex);
29     }
30     SIMIX_unregister_action_to_condition(action, cond);
31     SIMIX_mutex_unlock(mutex);
32     SIMIX_action_destroy(action);
33     SIMIX_cond_destroy(cond);
34     SIMIX_mutex_destroy(mutex);
35   }
36 }
37
38 void smpi_bench_begin()
39 {
40   xbt_os_timer_start(smpi_process_timer());
41 }
42
43 void smpi_bench_end()
44 {
45   xbt_os_timer_t timer = smpi_process_timer();
46
47   xbt_os_timer_stop(timer);
48   smpi_execute(xbt_os_timer_elapsed(timer));
49 }
50
51 /*
52 TODO
53 void smpi_do_once_1(const char *file, int line)
54 {
55   smpi_do_once_duration_node_t curr, prev;
56
57   smpi_bench_end();
58   SIMIX_mutex_lock(smpi_global->do_once_mutex);
59   prev = NULL;
60   for(curr = smpi_global->do_once_duration_nodes;
61       NULL != curr && (strcmp(curr->file, file) || curr->line != line);
62       curr = curr->next) {
63     prev = curr;
64   }
65   if(NULL == curr) {
66     curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
67     curr->file = xbt_strdup(file);
68     curr->line = line;
69     curr->duration = -1;
70     curr->next = NULL;
71     if(NULL == prev) {
72       smpi_global->do_once_duration_nodes = curr;
73     } else {
74       prev->next = curr;
75     }
76   }
77   smpi_global->do_once_duration = &curr->duration;
78 }
79
80 int smpi_do_once_2()
81 {
82   double duration = *(smpi_global->do_once_duration);
83
84   if(0 > duration) {
85     smpi_start_timer();
86     return 1;
87   }
88   SIMIX_mutex_unlock(smpi_global->do_once_mutex);
89   smpi_execute(duration);
90   smpi_bench_begin();
91   return 0;
92 }
93
94 void smpi_do_once_3()
95 {
96   *(smpi_global->do_once_duration) = smpi_stop_timer();
97 }
98 */