+#include "xbt/dict.h"
+#include "xbt/sysdep.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi,
+ "Logging specific to SMPI (benchmarking)");
+
+xbt_dict_t allocs = NULL; /* Allocated on first use */
+xbt_dict_t samples = NULL; /* Allocated on first use */
+
+typedef struct {
+ int count;
+ char data[];
+} shared_data_t;
+
+typedef struct {
+ double time;
+ int count;
+ int max;
+ int started;
+} local_data_t;
+
+void smpi_bench_destroy(void)
+{
+ if (allocs) {
+ xbt_dict_free(&allocs);
+ }
+ if (samples) {
+ xbt_dict_free(&samples);
+ }
+}
+
+static void smpi_execute_flops(double flops)
+{
+ smx_host_t host;
+ smx_action_t action;
+ smx_mutex_t mutex;
+ smx_cond_t cond;
+ e_surf_action_state_t state;
+
+ host = SIMIX_host_self();
+ mutex = SIMIX_mutex_init();
+ cond = SIMIX_cond_init();
+ DEBUG1("Handle real computation time: %f flops", flops);
+ action = SIMIX_action_execute(host, "computation", flops);
+ SIMIX_mutex_lock(mutex);
+ SIMIX_register_action_to_condition(action, cond);
+ for (state = SIMIX_action_get_state(action);
+ state == SURF_ACTION_READY ||
+ state == SURF_ACTION_RUNNING;
+ state = SIMIX_action_get_state(action)) {
+ SIMIX_cond_wait(cond, mutex);
+ }
+ SIMIX_unregister_action_to_condition(action, cond);
+ SIMIX_mutex_unlock(mutex);
+ SIMIX_action_destroy(action);
+ SIMIX_cond_destroy(cond);
+ SIMIX_mutex_destroy(mutex);
+}
+
+static void smpi_execute(double duration)
+{
+ if (duration >= xbt_cfg_get_double(_surf_cfg_set, "smpi/cpu_threshold")) {
+ DEBUG1("Sleep for %f to handle real computation time", duration);
+ smpi_execute_flops(duration *
+ xbt_cfg_get_double(_surf_cfg_set,
+ "smpi/running_power"));
+ }
+}
+
+void smpi_bench_begin(int rank, const char *mpi_call)
+{
+ if (mpi_call && rank >= 0
+ && xbt_cfg_get_int(_surf_cfg_set, "smpi/log_events")) {
+ INFO3("SMPE: ts=%f rank=%d type=end et=%s", SIMIX_get_clock(), rank,
+ mpi_call);
+ }
+ xbt_os_timer_start(smpi_process_timer());
+}