Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Verif lua with Darwin.
[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 static void smpi_execute(double duration) {
8   smx_host_t host;
9   smx_action_t action;
10   smx_mutex_t mutex;
11   smx_cond_t cond;
12   e_surf_action_state_t state;
13
14   if(duration > 0.001) {
15     host = SIMIX_host_self();
16     mutex = SIMIX_mutex_init();
17     cond = SIMIX_cond_init();
18     DEBUG1("Sleep for %f to handle real computation time", duration);
19     duration *= xbt_cfg_get_double(_surf_cfg_set, "reference_speed");
20     action = SIMIX_action_execute(host, "computation", duration);
21     SIMIX_mutex_lock(mutex);
22     SIMIX_register_action_to_condition(action, cond);
23     for(state = SIMIX_action_get_state(action);
24         state == SURF_ACTION_READY ||
25         state == SURF_ACTION_RUNNING; state = SIMIX_action_get_state(action)) {
26       SIMIX_cond_wait(cond, mutex);
27     }
28     SIMIX_unregister_action_to_condition(action, cond);
29     SIMIX_mutex_unlock(mutex);
30     SIMIX_action_destroy(action);
31     SIMIX_cond_destroy(cond);
32     SIMIX_mutex_destroy(mutex);
33   }
34 }
35
36 void smpi_bench_begin(const char* mpi_call) {
37   double simulated = smpi_process_simulated_elapsed();
38
39   if(mpi_call && xbt_cfg_get_int(_surf_cfg_set, "SMPE")) {
40     INFO2("SMPE: %s in %fs", mpi_call, simulated);
41   }
42   xbt_os_timer_start(smpi_process_timer());
43 }
44
45 void smpi_bench_end() {
46   xbt_os_timer_t timer = smpi_process_timer();
47
48   xbt_os_timer_stop(timer);
49   smpi_execute(xbt_os_timer_elapsed(timer));
50   smpi_process_simulated_reset();
51 }
52
53 /*
54 TODO
55 void smpi_do_once_1(const char *file, int line)
56 {
57   smpi_do_once_duration_node_t curr, prev;
58
59   smpi_bench_end();
60   SIMIX_mutex_lock(smpi_global->do_once_mutex);
61   prev = NULL;
62   for(curr = smpi_global->do_once_duration_nodes;
63       NULL != curr && (strcmp(curr->file, file) || curr->line != line);
64       curr = curr->next) {
65     prev = curr;
66   }
67   if(NULL == curr) {
68     curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
69     curr->file = xbt_strdup(file);
70     curr->line = line;
71     curr->duration = -1;
72     curr->next = NULL;
73     if(NULL == prev) {
74       smpi_global->do_once_duration_nodes = curr;
75     } else {
76       prev->next = curr;
77     }
78   }
79   smpi_global->do_once_duration = &curr->duration;
80 }
81
82 int smpi_do_once_2()
83 {
84   double duration = *(smpi_global->do_once_duration);
85
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 {
98   *(smpi_global->do_once_duration) = smpi_stop_timer();
99 }
100 */