Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update on smpirun script to accept -trace argument with the name of the tracefile
[simgrid.git] / src / smpi / smpi_bench.c
1 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "private.h"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi,
10                                 "Logging specific to SMPI (benchmarking)");
11
12 static void smpi_execute(double duration) {
13   smx_host_t host;
14   smx_action_t action;
15   smx_mutex_t mutex;
16   smx_cond_t cond;
17   e_surf_action_state_t state;
18
19   if(duration >= xbt_cfg_get_double(_surf_cfg_set, "smpi/cpu_threshold")) {
20     host = SIMIX_host_self();
21     mutex = SIMIX_mutex_init();
22     cond = SIMIX_cond_init();
23     DEBUG1("Sleep for %f to handle real computation time", duration);
24     duration *= xbt_cfg_get_double(_surf_cfg_set, "smpi/running_power");
25     action = SIMIX_action_execute(host, "computation", duration);
26     SIMIX_mutex_lock(mutex);
27     SIMIX_register_action_to_condition(action, cond);
28     for(state = SIMIX_action_get_state(action);
29         state == SURF_ACTION_READY ||
30         state == SURF_ACTION_RUNNING; state = SIMIX_action_get_state(action)) {
31       SIMIX_cond_wait(cond, mutex);
32     }
33     SIMIX_unregister_action_to_condition(action, cond);
34     SIMIX_mutex_unlock(mutex);
35     SIMIX_action_destroy(action);
36     SIMIX_cond_destroy(cond);
37     SIMIX_mutex_destroy(mutex);
38   }
39 }
40
41 void smpi_bench_begin(int rank, const char* mpi_call) {
42   if(mpi_call && rank >= 0 && xbt_cfg_get_int(_surf_cfg_set, "smpi/log_events")) {
43     INFO3("SMPE: ts=%f rank=%d type=end et=%s", SIMIX_get_clock(), rank, mpi_call);
44   }
45   xbt_os_timer_start(smpi_process_timer());
46 }
47
48 void smpi_bench_end(int rank, const char* mpi_call) {
49   xbt_os_timer_t timer = smpi_process_timer();
50
51   xbt_os_timer_stop(timer);
52   smpi_execute(xbt_os_timer_elapsed(timer));
53   if(mpi_call && rank >= 0 && xbt_cfg_get_int(_surf_cfg_set, "smpi/log_events")) {
54     INFO3("SMPE: ts=%f rank=%d type=begin et=%s", SIMIX_get_clock(), rank, mpi_call);
55   }
56 }
57
58 /*
59 TODO
60 void smpi_do_once_1(const char *file, int line)
61 {
62   smpi_do_once_duration_node_t curr, prev;
63
64   smpi_bench_end();
65   SIMIX_mutex_lock(smpi_global->do_once_mutex);
66   prev = NULL;
67   for(curr = smpi_global->do_once_duration_nodes;
68       NULL != curr && (strcmp(curr->file, file) || curr->line != line);
69       curr = curr->next) {
70     prev = curr;
71   }
72   if(NULL == curr) {
73     curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
74     curr->file = xbt_strdup(file);
75     curr->line = line;
76     curr->duration = -1;
77     curr->next = NULL;
78     if(NULL == prev) {
79       smpi_global->do_once_duration_nodes = curr;
80     } else {
81       prev->next = curr;
82     }
83   }
84   smpi_global->do_once_duration = &curr->duration;
85 }
86
87 int smpi_do_once_2()
88 {
89   double duration = *(smpi_global->do_once_duration);
90
91   if(0 > duration) {
92     smpi_start_timer();
93     return 1;
94   }
95   SIMIX_mutex_unlock(smpi_global->do_once_mutex);
96   smpi_execute(duration);
97   smpi_bench_begin();
98   return 0;
99 }
100
101 void smpi_do_once_3()
102 {
103   *(smpi_global->do_once_duration) = smpi_stop_timer();
104 }
105 */