+#include "xbt/dict.h"
+#include "xbt/sysdep.h"
+#include "surf/surf.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 {
+ int count;
+ double sum;
+ double sum_pow2;
+ double mean;
+ double relstderr;
+ int iters;
+ double threshold;
+ 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_action_t action;
+ smx_host_t host;
+ host = SIMIX_host_self();
+
+ DEBUG1("Handle real computation time: %f flops", flops);
+ action = SIMIX_req_host_execute("computation", host, flops, 1);
+#ifdef HAVE_TRACING
+ SIMIX_req_set_category (action, TRACE_internal_smpi_get_category());
+#endif
+ SIMIX_req_host_execution_wait(action);
+}
+
+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(void)
+{
+ xbt_os_timer_start(smpi_process_timer());
+}