1 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi,
10 "Logging specific to SMPI (benchmarking)");
12 static void smpi_execute(double duration) {
17 e_surf_action_state_t state;
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);
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);
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);
45 xbt_os_timer_start(smpi_process_timer());
48 void smpi_bench_end(int rank, const char* mpi_call) {
49 xbt_os_timer_t timer = smpi_process_timer();
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);
60 void smpi_do_once_1(const char *file, int line)
62 smpi_do_once_duration_node_t curr, prev;
65 SIMIX_mutex_lock(smpi_global->do_once_mutex);
67 for(curr = smpi_global->do_once_duration_nodes;
68 NULL != curr && (strcmp(curr->file, file) || curr->line != line);
73 curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
74 curr->file = xbt_strdup(file);
79 smpi_global->do_once_duration_nodes = curr;
84 smpi_global->do_once_duration = &curr->duration;
89 double duration = *(smpi_global->do_once_duration);
95 SIMIX_mutex_unlock(smpi_global->do_once_mutex);
96 smpi_execute(duration);
101 void smpi_do_once_3()
103 *(smpi_global->do_once_duration) = smpi_stop_timer();