From ef8e45c12eed3865ec33faf5760ed19bb55e183a Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 2 Mar 2022 22:23:54 +0100 Subject: [PATCH] New signal: Engine::on_simulation_start --- ChangeLog | 3 +++ docs/source/app_s4u.rst | 1 + include/simgrid/s4u/Engine.hpp | 6 +++++- src/s4u/s4u_Engine.cpp | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9776b48a65..3453aea52a 100644 --- 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(). diff --git a/docs/source/app_s4u.rst b/docs/source/app_s4u.rst index 666ac3f45b..2ff9d3a139 100644 --- a/docs/source/app_s4u.rst +++ b/docs/source/app_s4u.rst @@ -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 diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 3e620e4541..7716e47f4d 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -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& 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& 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& cb) { on_simulation_end.connect(cb); } @@ -228,9 +230,11 @@ public: #endif private: - static xbt::signal on_simulation_end; + static xbt::signal on_simulation_start; static xbt::signal on_time_advance; static xbt::signal on_deadlock; + static xbt::signal on_simulation_end; + kernel::EngineImpl* const pimpl; static Engine* instance_; void initialize(int* argc, char** argv); diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 8baf07d2d8..845c3f053a 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -26,6 +26,7 @@ namespace simgrid { namespace s4u { xbt::signal Engine::on_platform_creation; xbt::signal Engine::on_platform_created; +xbt::signal Engine::on_simulation_start; xbt::signal Engine::on_simulation_end; xbt::signal Engine::on_time_advance; xbt::signal 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); -- 2.20.1