Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New signal: Engine::on_simulation_start
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 2 Mar 2022 21:23:54 +0000 (22:23 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 2 Mar 2022 23:57:21 +0000 (00:57 +0100)
ChangeLog
docs/source/app_s4u.rst
include/simgrid/s4u/Engine.hpp
src/s4u/s4u_Engine.cpp

index 9776b48..3453aea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,9 @@ SMPI:
    not just at the end, reducing memory cost and performance hit.
  - Update OpenMPI collectives selection logic to match current one (4.1.2)
 
+S4U:
+ - New signal: Engine::on_simulation_start_cb()
+
 XBT:
  - Drop xbt_dynar_shrink().
 
index 666ac3f..2ff9d3a 100644 (file)
@@ -957,6 +957,7 @@ Signals
       .. doxygenfunction:: simgrid::s4u::Engine::on_deadlock_cb
       .. doxygenfunction:: simgrid::s4u::Engine::on_platform_created_cb
       .. doxygenfunction:: simgrid::s4u::Engine::on_platform_creation_cb
+      .. doxygenfunction:: simgrid::s4u::Engine::on_simulation_start_cb
       .. doxygenfunction:: simgrid::s4u::Engine::on_simulation_end_cb
       .. doxygenfunction:: simgrid::s4u::Engine::on_time_advance_cb
 
index 3e620e4..7716e47 100644 (file)
@@ -208,6 +208,8 @@ public:
   /** Add a callback fired when the platform is about to be created
    * (ie, after any configuration change and just before the resource creation) */
   static void on_platform_creation_cb(const std::function<void()>& cb) { on_platform_creation.connect(cb); }
+  /** Add a callback fired when the main simulation loop starts, at the beginning of the first call to Engine::run() */
+  static void on_simulation_start_cb(const std::function<void()>& cb) { on_simulation_start.connect(cb); }
   /** Add a callback fired when the main simulation loop ends, just before the end of Engine::run() */
   static void on_simulation_end_cb(const std::function<void()>& cb) { on_simulation_end.connect(cb); }
 
@@ -228,9 +230,11 @@ public:
 #endif
 
 private:
-  static xbt::signal<void()> on_simulation_end;
+  static xbt::signal<void()> on_simulation_start;
   static xbt::signal<void(double)> on_time_advance;
   static xbt::signal<void(void)> on_deadlock;
+  static xbt::signal<void()> on_simulation_end;
+
   kernel::EngineImpl* const pimpl;
   static Engine* instance_;
   void initialize(int* argc, char** argv);
index 8baf07d..845c3f0 100644 (file)
@@ -26,6 +26,7 @@ namespace simgrid {
 namespace s4u {
 xbt::signal<void()> Engine::on_platform_creation;
 xbt::signal<void()> Engine::on_platform_created;
+xbt::signal<void()> Engine::on_simulation_start;
 xbt::signal<void()> Engine::on_simulation_end;
 xbt::signal<void(double)> Engine::on_time_advance;
 xbt::signal<void(void)> Engine::on_deadlock;
@@ -333,6 +334,11 @@ void Engine::run() const
 }
 void Engine::run_until(double max_date) const
 {
+  static bool callback_called = false;
+  if (not callback_called) {
+    on_simulation_start();
+    callback_called = true;
+  }
   /* Clean IO before the run */
   fflush(stdout);
   fflush(stderr);