Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify a bit smpi_sample_* functions.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 6 May 2022 08:17:57 +0000 (10:17 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 6 May 2022 08:17:57 +0000 (10:17 +0200)
* merge smpi_sample_1 and smpi_sample_2 into smpi_sample_cond
* rename smpi_sample_3 to smpi_sample_iter

include/smpi/smpi.h
src/smpi/internals/smpi_bench.cpp

index 1bf6d09..468b31e 100644 (file)
@@ -1155,9 +1155,9 @@ XBT_PUBLIC void smpi_bench_end();
 
 XBT_PUBLIC unsigned long long smpi_rastro_resolution();
 XBT_PUBLIC unsigned long long smpi_rastro_timestamp();
-XBT_PUBLIC void smpi_sample_1(int global, const char* file, const char* tag, int iters, double threshold);
-XBT_PUBLIC int smpi_sample_2(int global, const char* file, const char* tag, int iter_count);
-XBT_PUBLIC void smpi_sample_3(int global, const char* file, const char* tag);
+XBT_PUBLIC int smpi_sample_cond(int global, const char* file, const char* tag, int iters, double threshold,
+                                int iter_count);
+XBT_PUBLIC void smpi_sample_iter(int global, const char* file, const char* tag);
 XBT_PUBLIC int smpi_sample_exit(int global, const char* file, const char* tag, int iter_count);
 /**
  * Need a public setter for SMPI copy_callback function, so users can define
@@ -1182,8 +1182,8 @@ XBT_PUBLIC void smpi_trace_set_call_location__(const char* file, const int* line
 #define SMPI_CTAG_NAME(line) SMPI_CTAG_NAME1(line)
 
 #define SMPI_SAMPLE_LOOP(loop_init, loop_end, loop_iter, global, iters, thres, tag)                                    \
-  char SMPI_CTAG_NAME(__LINE__) [132];                                                                                 \
-  snprintf( SMPI_CTAG_NAME(__LINE__), 132, "%s%d", tag, __LINE__);                                                           \
+  char SMPI_CTAG_NAME(__LINE__)[132];                                                                                  \
+  snprintf(SMPI_CTAG_NAME(__LINE__), 132, "%s%d", tag, __LINE__);                                                      \
   int SMPI_ITER_NAME(__LINE__) = 0;                                                                                    \
   {                                                                                                                    \
     loop_init;                                                                                                         \
@@ -1192,11 +1192,11 @@ XBT_PUBLIC void smpi_trace_set_call_location__(const char* file, const int* line
       (loop_iter);                                                                                                     \
     }                                                                                                                  \
   }                                                                                                                    \
-  for ( loop_init;                                                                                                     \
-         (loop_end) ? (smpi_sample_1((global), __FILE__, SMPI_CTAG_NAME(__LINE__), (iters), (thres))                   \
-                        , (smpi_sample_2((global), __FILE__, SMPI_CTAG_NAME(__LINE__), SMPI_ITER_NAME(__LINE__))))     \
-                    : smpi_sample_exit((global), __FILE__, SMPI_CTAG_NAME(__LINE__), SMPI_ITER_NAME(__LINE__));        \
-         smpi_sample_3((global), __FILE__, SMPI_CTAG_NAME(__LINE__)), (loop_iter) )
+  for (loop_init;                                                                                                      \
+       (loop_end) ? smpi_sample_cond((global), __FILE__, SMPI_CTAG_NAME(__LINE__), (iters), (thres),                   \
+                                     SMPI_ITER_NAME(__LINE__))                                                         \
+                  : smpi_sample_exit((global), __FILE__, SMPI_CTAG_NAME(__LINE__), SMPI_ITER_NAME(__LINE__));          \
+       smpi_sample_iter((global), __FILE__, SMPI_CTAG_NAME(__LINE__)), (loop_iter))
 
 #define SMPI_SAMPLE_LOCAL(loop_init, loop_end, loop_iter, iters, thres)                                                \
   SMPI_SAMPLE_LOOP(loop_init, (loop_end), (loop_iter), 0, (iters), (thres), "")
index ebe1d34..f4687af 100644 (file)
@@ -304,7 +304,7 @@ bool LocalData::need_more_benchs() const
 std::unordered_map<SampleLocation, LocalData, std::hash<std::string>> samples;
 }
 
-void smpi_sample_1(int global, const char *file, const char *tag, int iters, double threshold)
+int smpi_sample_cond(int global, const char* file, const char* tag, int iters, double threshold, int iter_count)
 {
   SampleLocation loc(global, file, tag);
   if (not smpi_process()->sampling()) { /* Only at first call when benchmarking, skip for next ones */
@@ -323,12 +323,13 @@ void smpi_sample_1(int global, const char *file, const char *tag, int iters, dou
                                                     0,         // count
                                                     true       // benching (if we have no data, we need at least one)
                                                 });
+  LocalData& data         = sample->second;
+
   if (inserted) {
     XBT_DEBUG("XXXXX First time ever on benched nest %s.", loc.c_str());
     xbt_assert(threshold > 0 || iters > 0,
         "You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)");
   } else {
-    LocalData& data = sample->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??",
@@ -336,24 +337,14 @@ void smpi_sample_1(int global, const char *file, const char *tag, int iters, dou
       THROW_IMPOSSIBLE;
     }
 
-    // if we already have some data, check whether sample_2 should get one more bench or whether it should emulate
+    // if we already have some data, check whether we should get one more bench or whether we should emulate
     // the computation instead
     data.benching = data.need_more_benchs();
     XBT_DEBUG("XXXX Re-entering the benched nest %s. %s", loc.c_str(),
               (data.benching ? "more benching needed" : "we have enough data, skip computes"));
   }
-}
-
-int smpi_sample_2(int global, const char *file,const char *tag, int iter_count)
-{
-  SampleLocation loc(global, file, tag);
-
-  XBT_DEBUG("sample2 %s %d", loc.c_str(), iter_count);
-  auto sample = samples.find(loc);
-  xbt_assert(sample != samples.end(),
-             "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
-  const LocalData& data = sample->second;
 
+  XBT_DEBUG("sample cond %s %d", loc.c_str(), iter_count);
   if (data.benching) {
     // we need to run a new bench
     XBT_DEBUG("benchmarking: count:%d iter:%d stderr:%f thres:%f; mean:%f; total:%f",
@@ -380,18 +371,16 @@ int smpi_sample_2(int global, const char *file,const char *tag, int iter_count)
   return 1;
 }
 
-void smpi_sample_3(int global, const char *file, const char* tag)
+void smpi_sample_iter(int global, const char* file, const char* tag)
 {
   SampleLocation loc(global, file, tag);
 
-  XBT_DEBUG("sample3 %s", loc.c_str());
+  XBT_DEBUG("sample iter %s", loc.c_str());
   auto sample = samples.find(loc);
   xbt_assert(sample != samples.end(),
              "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   LocalData& data = sample->second;
-
-  if (not data.benching)
-    THROW_IMPOSSIBLE;
+  xbt_assert(data.benching);
 
   // ok, benchmarking this loop is over
   xbt_os_threadtimer_stop(smpi_process()->timer());
@@ -407,9 +396,6 @@ void smpi_sample_3(int global, const char *file, const char* tag)
 
   XBT_DEBUG("Average mean after %d steps is %f, relative standard error is %f (sample was %f)",
             data.count, data.mean, data.relstderr, period);
-
-  // That's enough for now, prevent sample_2 to run the same code over and over
-  data.benching = false;
 }
 
 int smpi_sample_exit(int global, const char *file, const char* tag, int iter_count){