Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Show how to programatically attach a state profile to an XML host in the relevant...
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 22 Dec 2021 21:09:25 +0000 (22:09 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 22 Dec 2021 22:19:04 +0000 (23:19 +0100)
examples/cpp/platform-failures/s4u-platform-failures.cpp
examples/platforms/profiles/bourassa_state.profile [deleted file]
examples/platforms/small_platform_failures.xml

index 56e6edd..4a5cc0f 100644 (file)
@@ -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<std::string> 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 (file)
index 886ba9c..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-67 0
-70 1
index ef4527d..006f2a8 100644 (file)
@@ -6,7 +6,7 @@
     <host id="Jupiter"  speed="25Mf" state_file="profiles/jupiter_state.profile"/>
     <host id="Fafard"   speed="25Mf" state_file="profiles/fafard_state.profile" />
     <host id="Ginette"  speed="25Mf" state_file="profiles/ginette_state.profile"/>
-    <host id="Bourassa" speed="25Mf" state_file="profiles/bourassa_state.profile"/>
+    <host id="Bourassa" speed="25Mf"/>
 
     <link id="1" bandwidth="1MBps" latency="0"/>
     <link id="2" bandwidth="1MBps" latency="0"/>