/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include "src/internal_config.h"
#include "private.h"
#include "private.hpp"
#include "simgrid/modelchecker.h"
-#include "src/mc/mc_replay.h"
-#include "smpi_process.hpp"
#include "smpi_comm.hpp"
+#include "smpi_process.hpp"
+#include "src/internal_config.h"
+#include "src/mc/mc_replay.h"
+#include <unordered_map>
#ifndef WIN32
#include <sys/mman.h>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_bench, smpi, "Logging specific to SMPI (benchmarking)");
-
-xbt_dict_t samples = nullptr; /* Allocated on first use */
-
double smpi_cpu_threshold = -1;
double smpi_host_speed;
double smpi_total_benched_time = 0;
smpi_privatization_region_t smpi_privatization_regions;
-void smpi_bench_destroy()
-{
- xbt_dict_free(&samples);
-}
-
extern "C" XBT_PUBLIC(void) smpi_execute_flops_(double *flops);
void smpi_execute_flops_(double *flops)
{
int benching; /* 1: we are benchmarking; 0: we have enough data, no bench anymore */
} local_data_t;
+std::unordered_map<std::string, local_data_t*> samples; /* Allocated on first use */
+
static char *sample_location(int global, const char *file, int line) {
if (global) {
return bprintf("%s:%d", file, line);
smpi_bench_end(); /* Take time from previous, unrelated computation into account */
smpi_process()->set_sampling(1);
- if (samples==nullptr)
- samples = xbt_dict_new_homogeneous(free);
-
- local_data_t *data = static_cast<local_data_t *>(xbt_dict_get_or_null(samples, loc));
- if (data==nullptr) {
+ auto ld = samples.find(loc);
+ local_data_t* data;
+ if (ld == samples.end()) {
xbt_assert(threshold>0 || iters>0,
"You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)");
- data = static_cast<local_data_t *>( xbt_new(local_data_t, 1));
+ data = static_cast<local_data_t*>(xbt_new(local_data_t, 1));
data->count = 0;
data->sum = 0.0;
data->sum_pow2 = 0.0;
data->threshold = threshold;
data->benching = 1; // If we have no data, we need at least one
data->mean = 0;
- xbt_dict_set(samples, loc, data, nullptr);
+ samples[loc] = data;
XBT_DEBUG("XXXXX First time ever on benched nest %s.",loc);
} else {
+ data = ld->second;
if (data->iters != iters || data->threshold != threshold) {
XBT_ERROR("Asked to bench block %s with different settings %d, %f is not %d, %f. "
"How did you manage to give two numbers at the same line??",
char *loc = sample_location(global, file, line);
int res;
- xbt_assert(samples, "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
- local_data_t *data = static_cast<local_data_t *>(xbt_dict_get(samples, loc));
+ xbt_assert(not samples.empty(),
+ "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
+ local_data_t* data = samples.at(loc);
XBT_DEBUG("sample2 %s",loc);
xbt_free(loc);
{
char *loc = sample_location(global, file, line);
- xbt_assert(samples, "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
- local_data_t *data = static_cast<local_data_t *>(xbt_dict_get(samples, loc));
+ xbt_assert(not samples.empty(),
+ "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
+ local_data_t* data = samples.at(loc);
XBT_DEBUG("sample3 %s",loc);
xbt_free(loc);
smpi_trace_set_call_location(file, *line);
}
}
+
+void smpi_bench_destroy()
+{
+ for (auto elm : samples)
+ xbt_free(elm.second);
+}