Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert 2 examples from Activity::wait_any to ActivitySet
[simgrid.git] / examples / cpp / exec-waitany / s4u-exec-waitany.cpp
index 89fc558..c30dd31 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -9,22 +9,23 @@
 #include <string>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_exec_waitany, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
 
 static void worker(bool with_timeout)
 {
   /* Vector in which we store all pending executions*/
-  std::vector<simgrid::s4u::ExecPtr> pending_executions;
+  std::vector<sg4::ExecPtr> pending_executions;
 
   for (int i = 0; i < 3; i++) {
-    std::string name = std::string("Exec-") + std::to_string(i);
-    double amount    = (6 * (i % 2) + i + 1) * simgrid::s4u::this_actor::get_host()->get_speed();
+    std::string name = "Exec-" + std::to_string(i);
+    double amount    = (6 * (i % 2) + i + 1) * sg4::this_actor::get_host()->get_speed();
 
-    simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(amount)->set_name(name);
+    sg4::ExecPtr exec = sg4::this_actor::exec_init(amount)->set_name(name);
     pending_executions.push_back(exec);
     exec->start();
 
     XBT_INFO("Activity %s has started for %.0f seconds", name.c_str(),
-             amount / simgrid::s4u::this_actor::get_host()->get_speed());
+             amount / sg4::this_actor::get_host()->get_speed());
   }
 
   /* Now that executions were initiated, wait for their completion, in order of termination.
@@ -35,9 +36,9 @@ static void worker(bool with_timeout)
   while (not pending_executions.empty()) {
     ssize_t pos;
     if (with_timeout)
-      pos = simgrid::s4u::Exec::wait_any_for(pending_executions, 4);
+      pos = sg4::Exec::wait_any_for(pending_executions, 4);
     else
-      pos = simgrid::s4u::Exec::wait_any(pending_executions);
+      pos = sg4::Exec::wait_any(pending_executions);
 
     if (pos < 0) {
       XBT_INFO("Do not wait any longer for an activity");
@@ -52,10 +53,10 @@ static void worker(bool with_timeout)
 
 int main(int argc, char* argv[])
 {
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.load_platform(argv[1]);
-  simgrid::s4u::Actor::create("worker", e.host_by_name("Tremblay"), worker, false);
-  simgrid::s4u::Actor::create("worker_timeout", e.host_by_name("Tremblay"), worker, true);
+  sg4::Actor::create("worker", e.host_by_name("Tremblay"), worker, false);
+  sg4::Actor::create("worker_timeout", e.host_by_name("Tremblay"), worker, true);
   e.run();
 
   return 0;