Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Give a way to add binaries to the list that shouldn't be messed with by sthread
[simgrid.git] / examples / cpp / exec-async / s4u-exec-async.cpp
index bb94c7dd2d7f81588c409ed008e6056fcf4d44cd..d84cc93646d798ca7a4e87fabaf083c05bbdb07a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-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. */
@@ -6,14 +6,15 @@
 #include "simgrid/s4u.hpp"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+namespace sg4 = simgrid::s4u;
 
 /* This actor simply waits for its activity completion after starting it.
  * That's exactly equivalent to synchronous execution. */
 static void waiter()
 {
-  double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+  double computation_amount = sg4::this_actor::get_host()->get_speed();
   XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
-  simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_init(computation_amount);
+  sg4::ExecPtr activity = sg4::this_actor::exec_init(computation_amount);
   activity->start();
   activity->wait();
 
@@ -23,15 +24,15 @@ static void waiter()
 /* This actor tests the ongoing execution until its completion, and don't wait before it's terminated. */
 static void monitor()
 {
-  double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+  double computation_amount = sg4::this_actor::get_host()->get_speed();
   XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
-  simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_init(computation_amount);
+  sg4::ExecPtr activity = sg4::this_actor::exec_init(computation_amount);
   activity->start();
 
   while (not activity->test()) {
     XBT_INFO("Remaining amount of flops: %g (%.0f%%)", activity->get_remaining(),
              100 * activity->get_remaining_ratio());
-    simgrid::s4u::this_actor::sleep_for(0.3);
+    sg4::this_actor::sleep_for(0.3);
   }
 
   XBT_INFO("Goodbye now!");
@@ -40,11 +41,11 @@ static void monitor()
 /* This actor cancels the ongoing execution after a while. */
 static void canceller()
 {
-  double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+  double computation_amount = sg4::this_actor::get_host()->get_speed();
 
   XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
-  simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_async(computation_amount);
-  simgrid::s4u::this_actor::sleep_for(0.5);
+  sg4::ExecPtr activity = sg4::this_actor::exec_async(computation_amount);
+  sg4::this_actor::sleep_for(0.5);
   XBT_INFO("I changed my mind, cancel!");
   activity->cancel();
 
@@ -53,20 +54,20 @@ static void canceller()
 
 int main(int argc, char* argv[])
 {
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.load_platform(argv[1]);
 
-  simgrid::s4u::Host* fafard  = simgrid::s4u::Host::by_name("Fafard");
-  simgrid::s4u::Host* ginette = simgrid::s4u::Host::by_name("Ginette");
-  simgrid::s4u::Host* boivin  = simgrid::s4u::Host::by_name("Boivin");
+  sg4::Host* fafard  = e.host_by_name("Fafard");
+  sg4::Host* ginette = e.host_by_name("Ginette");
+  sg4::Host* boivin  = e.host_by_name("Boivin");
 
-  simgrid::s4u::Actor::create("wait", fafard, waiter);
-  simgrid::s4u::Actor::create("monitor", ginette, monitor);
-  simgrid::s4u::Actor::create("cancel", boivin, canceller);
+  sg4::Actor::create("wait", fafard, waiter);
+  sg4::Actor::create("monitor", ginette, monitor);
+  sg4::Actor::create("cancel", boivin, canceller);
 
   e.run();
 
-  XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
+  XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
 
   return 0;
 }