Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
PJ_container_remove_from_parent () becomes Container::removeFromParent
[simgrid.git] / src / smpi / internals / smpi_bench.cpp
index 58c3c70..4e1243a 100644 (file)
@@ -3,7 +3,6 @@
 /* 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 "private.h"
 #include "private.hpp"
 #include "simgrid/modelchecker.h"
 #include "smpi_comm.hpp"
@@ -128,8 +127,6 @@ void smpi_bench_end()
     } else {
       for (unsigned int i = 0; i < counter_data.size(); i++) {
         counter_data[i].second += event_values[i];
-        // XBT_DEBUG("[%i] PAPI: Counter %s: Value is now %lli (got increment by %lli\n", smpi_process()->index(),
-        // counter_data[i].first.c_str(), counter_data[i].second, event_values[i]);
       }
     }
   }
@@ -206,13 +203,13 @@ int smpi_usleep(useconds_t usecs)
 }
 
 #if _POSIX_TIMERS > 0
-int smpi_nanosleep(const struct timespec *tp, struct timespec * t)
+int smpi_nanosleep(const struct timespec* tp, struct timespec* /*t*/)
 {
   return static_cast<int>(private_sleep(static_cast<double>(tp->tv_sec + tp->tv_nsec / 1000000000.0)));
 }
 #endif
 
-int smpi_gettimeofday(struct timeval *tv, void* tz)
+int smpi_gettimeofday(struct timeval* tv, void* /*tz*/)
 {
   smpi_bench_end();
   double now = SIMIX_get_clock();
@@ -229,7 +226,7 @@ int smpi_gettimeofday(struct timeval *tv, void* tz)
 }
 
 #if _POSIX_TIMERS > 0
-int smpi_clock_gettime(clockid_t clk_id, struct timespec *tp)
+int smpi_clock_gettime(clockid_t /*clk_id*/, struct timespec* tp)
 {
   //there is only one time in SMPI, so clk_id is ignored.
   smpi_bench_end();
@@ -265,7 +262,17 @@ unsigned long long smpi_rastro_timestamp ()
 
 /* ****************************** Functions related to the SMPI_SAMPLE_ macros ************************************/
 namespace {
-struct LocalData {
+class SampleLocation : public std::string {
+public:
+  SampleLocation(bool global, const char* file, int line) : std::string(std::string(file) + ":" + std::to_string(line))
+  {
+    if (not global)
+      this->append(":" + std::to_string(smpi_process()->index()));
+  }
+};
+
+class LocalData {
+public:
   double threshold; /* maximal stderr requested (if positive) */
   double relstderr; /* observed stderr so far */
   double mean;      /* mean of benched times, to be used if the block is disabled */
@@ -279,16 +286,7 @@ struct LocalData {
 };
 }
 
-std::unordered_map<std::string, LocalData> samples;
-
-static std::string sample_location(int global, const char* file, int line)
-{
-  if (global) {
-    return std::string(file) + ":" + std::to_string(line);
-  } else {
-    return std::string(file) + ":" + std::to_string(line) + ":" + std::to_string(smpi_process()->index());
-  }
-}
+std::unordered_map<SampleLocation, LocalData, std::hash<std::string>> samples;
 
 bool LocalData::need_more_benchs() const
 {
@@ -302,7 +300,7 @@ bool LocalData::need_more_benchs() const
 
 void smpi_sample_1(int global, const char *file, int line, int iters, double threshold)
 {
-  std::string loc = sample_location(global, file, line);
+  SampleLocation loc(global, file, line);
 
   smpi_bench_end();     /* Take time from previous, unrelated computation into account */
   smpi_process()->set_sampling(1);
@@ -340,7 +338,7 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr
 
 int smpi_sample_2(int global, const char *file, int line)
 {
-  std::string loc = sample_location(global, file, line);
+  SampleLocation loc(global, file, line);
   int res;
 
   XBT_DEBUG("sample2 %s", loc.c_str());
@@ -370,7 +368,7 @@ int smpi_sample_2(int global, const char *file, int line)
 
 void smpi_sample_3(int global, const char *file, int line)
 {
-  std::string loc = sample_location(global, file, line);
+  SampleLocation loc(global, file, line);
 
   XBT_DEBUG("sample3 %s", loc.c_str());
   auto sample = samples.find(loc);