Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change host data into process data; count processes instead of hosts; communicator...
[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   SIMIX_mutex_lock(mutex);
16
17   action =
18     SIMIX_action_execute(host, "execute", duration * SMPI_DEFAULT_SPEED);
19
20   SIMIX_register_action_to_condition(action, cond);
21   for (state = SIMIX_action_get_state(action);
22        state == SURF_ACTION_READY ||
23        state == SURF_ACTION_RUNNING; state = SIMIX_action_get_state(action)
24     ) {
25     SIMIX_cond_wait(cond, mutex);
26   }
27   SIMIX_unregister_action_to_condition(action, cond);
28   SIMIX_action_destroy(action);
29
30   SIMIX_mutex_unlock(mutex);
31
32   return;
33 }
34
35 void smpi_start_timer()
36 {
37   SIMIX_mutex_lock(smpi_global->timer_mutex);
38   xbt_os_timer_start(smpi_global->timer);
39 }
40
41 double smpi_stop_timer()
42 {
43   double duration;
44   xbt_os_timer_stop(smpi_global->timer);
45   duration = xbt_os_timer_elapsed(smpi_global->timer);
46   SIMIX_mutex_unlock(smpi_global->timer_mutex);
47   return duration;
48 }
49
50 void smpi_bench_begin()
51 {
52   smpi_start_timer();
53 }
54
55 void smpi_bench_end()
56 {
57   smpi_execute(smpi_stop_timer());
58 }
59
60 void smpi_do_once_1(const char *file, int line)
61 {
62   smpi_do_once_duration_node_t curr, prev;
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   if (0 > duration) {
90     smpi_start_timer();
91     return 1;
92   }
93   SIMIX_mutex_unlock(smpi_global->do_once_mutex);
94   smpi_execute(duration);
95   smpi_bench_begin();
96   return 0;
97 }
98
99 void smpi_do_once_3()
100 {
101   *(smpi_global->do_once_duration) = smpi_stop_timer();
102 }