Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make SMPE's output to look more like clog2_print's one
[simgrid.git] / src / smpi / smpi_bench.c
1 #include "private.h"
2
3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi,
4                                 "Logging specific to SMPI (benchmarking)");
5
6 static void smpi_execute(double duration) {
7   smx_host_t host;
8   smx_action_t action;
9   smx_mutex_t mutex;
10   smx_cond_t cond;
11   e_surf_action_state_t state;
12
13   if(duration > 0.001) {
14     host = SIMIX_host_self();
15     mutex = SIMIX_mutex_init();
16     cond = SIMIX_cond_init();
17     DEBUG1("Sleep for %f to handle real computation time", duration);
18     duration *= xbt_cfg_get_double(_surf_cfg_set, "reference_speed");
19     action = SIMIX_action_execute(host, "computation", duration);
20     SIMIX_mutex_lock(mutex);
21     SIMIX_register_action_to_condition(action, cond);
22     for(state = SIMIX_action_get_state(action);
23         state == SURF_ACTION_READY ||
24         state == SURF_ACTION_RUNNING; state = SIMIX_action_get_state(action)) {
25       SIMIX_cond_wait(cond, mutex);
26     }
27     SIMIX_unregister_action_to_condition(action, cond);
28     SIMIX_mutex_unlock(mutex);
29     SIMIX_action_destroy(action);
30     SIMIX_cond_destroy(cond);
31     SIMIX_mutex_destroy(mutex);
32   }
33 }
34
35 void smpi_bench_begin(MPI_Comm comm, const char* mpi_call) {
36   double now = SIMIX_get_clock();
37   int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
38
39   if(mpi_call && xbt_cfg_get_int(_surf_cfg_set, "SMPE")) {
40     INFO3("SMPE: ts=%f rank=%d type=end et=%s", now, rank, mpi_call);
41   }
42   xbt_os_timer_start(smpi_process_timer());
43 }
44
45 void smpi_bench_end(MPI_Comm comm, const char* mpi_call) {
46   xbt_os_timer_t timer = smpi_process_timer();
47   double now = SIMIX_get_clock();
48   int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
49
50   xbt_os_timer_stop(timer);
51   smpi_execute(xbt_os_timer_elapsed(timer));
52   if(mpi_call && xbt_cfg_get_int(_surf_cfg_set, "SMPE")) {
53     INFO3("SMPE: ts=%f rank=%d type=begin et=%s", now, rank, mpi_call);
54   }
55 }
56
57 /*
58 TODO
59 void smpi_do_once_1(const char *file, int line)
60 {
61   smpi_do_once_duration_node_t curr, prev;
62
63   smpi_bench_end();
64   SIMIX_mutex_lock(smpi_global->do_once_mutex);
65   prev = NULL;
66   for(curr = smpi_global->do_once_duration_nodes;
67       NULL != curr && (strcmp(curr->file, file) || curr->line != line);
68       curr = curr->next) {
69     prev = curr;
70   }
71   if(NULL == curr) {
72     curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
73     curr->file = xbt_strdup(file);
74     curr->line = line;
75     curr->duration = -1;
76     curr->next = NULL;
77     if(NULL == prev) {
78       smpi_global->do_once_duration_nodes = curr;
79     } else {
80       prev->next = curr;
81     }
82   }
83   smpi_global->do_once_duration = &curr->duration;
84 }
85
86 int smpi_do_once_2()
87 {
88   double duration = *(smpi_global->do_once_duration);
89
90   if(0 > duration) {
91     smpi_start_timer();
92     return 1;
93   }
94   SIMIX_mutex_unlock(smpi_global->do_once_mutex);
95   smpi_execute(duration);
96   smpi_bench_begin();
97   return 0;
98 }
99
100 void smpi_do_once_3()
101 {
102   *(smpi_global->do_once_duration) = smpi_stop_timer();
103 }
104 */