From fddcd9b28e2a55ab6cb04c9167524e65bd7a05a6 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 22 Dec 2021 22:09:25 +0100 Subject: [PATCH] Show how to programatically attach a state profile to an XML host in the relevant example --- .../platform-failures/s4u-platform-failures.cpp | 14 +++++++++++++- examples/platforms/profiles/bourassa_state.profile | 2 -- examples/platforms/small_platform_failures.xml | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) delete mode 100644 examples/platforms/profiles/bourassa_state.profile diff --git a/examples/cpp/platform-failures/s4u-platform-failures.cpp b/examples/cpp/platform-failures/s4u-platform-failures.cpp index 56e6edd9c1..4a5cc0f6e0 100644 --- a/examples/cpp/platform-failures/s4u-platform-failures.cpp +++ b/examples/cpp/platform-failures/s4u-platform-failures.cpp @@ -7,7 +7,8 @@ * specifying when the resource must be turned on or off. * * To set such a profile, the first way is to use a file in the XML, while the second is to use the programmatic - * interface. Once this profile is in place, the resource will automatically be turned on and off. + * interface, as exemplified in the main() below. Once this profile is in place, the resource will automatically + * be turned on and off. * * The actors running on a host that is turned off are forcefully killed * once their on_exit callbacks are executed. They cannot avoid this fate. @@ -17,6 +18,7 @@ * Communications using failed links will .. fail. */ +#include "simgrid/kernel/ProfileBuilder.hpp" #include "simgrid/s4u.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); @@ -96,7 +98,17 @@ static void worker(std::vector args) int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); + + // This is how to attach a profile to an host that is created from the XML file. + // This should be done before calling load_platform(), as the on_creation() event is fired when loading the platform. + // You can never set a new profile to a resource that already have one. + simgrid::s4u::Host::on_creation.connect([](simgrid::s4u::Host& h) { + if (h.get_name() == "Bourrassa") { + h.set_state_profile(simgrid::kernel::profile::ProfileBuilder::from_string("bourassa_profile", "67 0\n70 1\n", 0)); + } + }); e.load_platform(argv[1]); + e.register_function("master", master); e.register_function("worker", worker); e.load_deployment(argv[2]); diff --git a/examples/platforms/profiles/bourassa_state.profile b/examples/platforms/profiles/bourassa_state.profile deleted file mode 100644 index 886ba9c0ed..0000000000 --- a/examples/platforms/profiles/bourassa_state.profile +++ /dev/null @@ -1,2 +0,0 @@ -67 0 -70 1 diff --git a/examples/platforms/small_platform_failures.xml b/examples/platforms/small_platform_failures.xml index ef4527de3a..006f2a8acf 100644 --- a/examples/platforms/small_platform_failures.xml +++ b/examples/platforms/small_platform_failures.xml @@ -6,7 +6,7 @@ - + -- 2.20.1