Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add handling of sleep in replay.
authorAugustin Degomme <adegomme@gmail.com>
Thu, 3 Oct 2019 13:36:23 +0000 (15:36 +0200)
committerAugustin Degomme <adegomme@gmail.com>
Thu, 3 Oct 2019 14:27:04 +0000 (16:27 +0200)
We can trace sleep events with --cfg=tracing/smpi/sleeping. Now we can replay them as well.
Even if 1 second is 1 second, let's allow to accelerate/slow these down artificially with smpi/comp-adjustment-file.
This should allow to test the feature.

include/simgrid/smpi/replay.hpp
include/smpi/smpi_helpers.h
src/smpi/internals/smpi_replay.cpp

index c0d6206..c25ab90 100644 (file)
@@ -79,6 +79,13 @@ public:
   void parse(simgrid::xbt::ReplayAction& action, const std::string& name) override;
 };
 
+class SleepParser : public ActionArgParser {
+public:
+  double time;
+
+  void parse(simgrid::xbt::ReplayAction& action, const std::string& name) override;
+};
+
 class LocationParser : public ActionArgParser {
 public:
   std::string filename;
@@ -231,6 +238,12 @@ public:
   void kernel(simgrid::xbt::ReplayAction& action) override;
 };
 
+class SleepAction : public ReplayAction<SleepParser> {
+public:
+  explicit SleepAction() : ReplayAction("sleep") {}
+  void kernel(simgrid::xbt::ReplayAction& action) override;
+};
+
 class LocationAction : public ReplayAction<LocationParser> {
 public:
   explicit LocationAction() : ReplayAction("location") {}
index 6739870..b1a12da 100644 (file)
 #endif
 
 #include <smpi/smpi_helpers_internal.h>
-
+#ifndef TRACE_CALL_LOCATION /* Defined by smpicc on the command line */
 #define sleep(x) smpi_sleep(x)
 #define usleep(x) smpi_usleep(x)
+#else
+#define sleep(x) ({ smpi_trace_set_call_location(__FILE__,__LINE__); smpi_sleep(x); })
+#define usleep(x) ({ smpi_trace_set_call_location(__FILE__,__LINE__); smpi_usleep(x); })
+#endif
+
 #define gettimeofday(x, y) smpi_gettimeofday((x), 0)
 #if _POSIX_TIMERS > 0
+#ifndef TRACE_CALL_LOCATION /* Defined by smpicc on the command line */
 #define nanosleep(x, y) smpi_nanosleep((x), (y))
+#else
+#define nanosleep(x) ({ smpi_trace_set_call_location(__FILE__,__LINE__); smpi_nanosleep(x); })
+#endif
 #define clock_gettime(x, y) smpi_clock_gettime((x), (y))
 #endif
 
index e093433..04997ef 100644 (file)
@@ -165,6 +165,12 @@ void ComputeParser::parse(simgrid::xbt::ReplayAction& action, const std::string&
   flops = parse_double(action[2]);
 }
 
+void SleepParser::parse(simgrid::xbt::ReplayAction& action, const std::string&)
+{
+  CHECK_ACTION_PARAMS(action, 1, 0)
+  time = parse_double(action[2]);
+}
+
 void LocationParser::parse(simgrid::xbt::ReplayAction& action, const std::string&)
 {
   CHECK_ACTION_PARAMS(action, 2, 0)
@@ -485,6 +491,14 @@ void RecvAction::kernel(simgrid::xbt::ReplayAction&)
 void ComputeAction::kernel(simgrid::xbt::ReplayAction&)
 {
   smpi_execute_flops(args.flops/smpi_adjust_comp_speed());
+
+void SleepAction::kernel(simgrid::xbt::ReplayAction&)
+{
+  XBT_DEBUG("Sleep for: %lf secs", args.time);
+  int rank = simgrid::s4u::this_actor::get_pid();
+  TRACE_smpi_sleeping_in(rank, args.time);
+  simgrid::s4u::this_actor::sleep_for(args.time/smpi_adjust_comp_speed());
+  TRACE_smpi_sleeping_out(rank);
 }
 
 void LocationAction::kernel(simgrid::xbt::ReplayAction&)
@@ -758,6 +772,7 @@ void smpi_replay_init(const char* instance_id, int rank, double start_delay_flop
   xbt_replay_action_register("allgatherv", [](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::GatherVAction("allgatherv").execute(action); });
   xbt_replay_action_register("reducescatter", [](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::ReduceScatterAction().execute(action); });
   xbt_replay_action_register("compute", [](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::ComputeAction().execute(action); });
+  xbt_replay_action_register("sleep", [](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::SleepAction().execute(action); });
   xbt_replay_action_register("location", [](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::LocationAction().execute(action); });
 
   //if we have a delayed start, sleep here.