Logo AND Algorithmique Numérique Distribuée

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