Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Introduce the sg4 namespace alias in all comm examples
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 11 Feb 2021 19:05:11 +0000 (20:05 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 12 Feb 2021 20:39:54 +0000 (21:39 +0100)
examples/cpp/comm-dependent/s4u-comm-dependent.cpp
examples/cpp/comm-pingpong/s4u-comm-pingpong.cpp
examples/cpp/comm-ready/s4u-comm-ready.cpp
examples/cpp/comm-suspend/s4u-comm-suspend.cpp
examples/cpp/comm-wait/s4u-comm-wait.cpp
examples/cpp/comm-waitall/s4u-comm-waitall.cpp
examples/cpp/comm-waitany/s4u-comm-waitany.cpp
examples/cpp/comm-waituntil/s4u-comm-waituntil.cpp

index bcf7bda..7c88907 100644 (file)
@@ -4,14 +4,15 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <simgrid/s4u.hpp>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_dependent, "Messages specific for this s4u example");
 
-static void sender(simgrid::s4u::Mailbox* mailbox)
+static void sender(sg4::Mailbox* mailbox)
 {
-  auto* computation_amount   = new double(simgrid::s4u::this_actor::get_host()->get_speed());
-  simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * (*computation_amount));
-  simgrid::s4u::CommPtr comm = mailbox->put_init(computation_amount, 7e6);
+  auto* computation_amount = new double(sg4::this_actor::get_host()->get_speed());
+  sg4::ExecPtr exec        = sg4::this_actor::exec_init(2 * (*computation_amount));
+  sg4::CommPtr comm        = mailbox->put_init(computation_amount, 7e6);
 
   exec->set_name("exec on sender")->add_successor(comm)->start();
   comm->set_name("comm to receiver")->vetoable_start();
@@ -19,12 +20,12 @@ static void sender(simgrid::s4u::Mailbox* mailbox)
   comm->wait();
 }
 
-static void receiver(simgrid::s4u::Mailbox* mailbox)
+static void receiver(sg4::Mailbox* mailbox)
 {
   double* received           = nullptr;
-  double computation_amount  = simgrid::s4u::this_actor::get_host()->get_speed();
-  simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
-  simgrid::s4u::CommPtr comm = mailbox->get_init()->set_dst_data((void**)&received, sizeof(double));
+  double computation_amount  = sg4::this_actor::get_host()->get_speed();
+  sg4::ExecPtr exec          = sg4::this_actor::exec_init(2 * computation_amount);
+  sg4::CommPtr comm          = mailbox->get_init()->set_dst_data((void**)&received, sizeof(double));
 
   comm->set_name("comm from sender")->add_successor(exec)->start();
   exec->set_name("exec on receiver")->vetoable_start();
@@ -37,13 +38,13 @@ static void receiver(simgrid::s4u::Mailbox* mailbox)
 
 int main(int argc, char* argv[])
 {
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.load_platform(argv[1]);
 
-  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("Mailbox");
+  sg4::Mailbox* mbox = sg4::Mailbox::by_name("Mailbox");
 
-  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("Tremblay"), sender, mbox);
-  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("Jupiter"), receiver, mbox);
+  sg4::Actor::create("sender", sg4::Host::by_name("Tremblay"), sender, mbox);
+  sg4::Actor::create("receiver", sg4::Host::by_name("Jupiter"), receiver, mbox);
 
   e.run();
 
index 5ae5a3f..65acdbd 100644 (file)
@@ -4,37 +4,38 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <simgrid/s4u.hpp>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_pingpong, "Messages specific for this s4u example");
 
-static void pinger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mailbox_out)
+static void pinger(sg4::Mailbox* mailbox_in, sg4::Mailbox* mailbox_out)
 {
   XBT_INFO("Ping from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
 
   /* - Do the ping with a 1-Byte payload (latency bound) ... */
-  auto* payload = new double(simgrid::s4u::Engine::get_clock());
+  auto* payload = new double(sg4::Engine::get_clock());
 
   mailbox_out->put(payload, 1);
   /* - ... then wait for the (large) pong */
   auto sender_time = mailbox_in->get_unique<double>();
 
-  double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
+  double communication_time = sg4::Engine::get_clock() - *sender_time;
   XBT_INFO("Payload received : large communication (bandwidth bound)");
   XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
 }
 
-static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mailbox_out)
+static void ponger(sg4::Mailbox* mailbox_in, sg4::Mailbox* mailbox_out)
 {
   XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
 
   /* - Receive the (small) ping first ....*/
   auto sender_time          = mailbox_in->get_unique<double>();
-  double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
+  double communication_time = sg4::Engine::get_clock() - *sender_time;
   XBT_INFO("Payload received : small communication (latency bound)");
   XBT_INFO("Ping time (latency bound) %f", communication_time);
 
   /*  - ... Then send a 1GB pong back (bandwidth bound) */
-  auto* payload = new double(simgrid::s4u::Engine::get_clock());
+  auto* payload = new double(sg4::Engine::get_clock());
   XBT_INFO("payload = %.3f", *payload);
 
   mailbox_out->put(payload, 1e9);
@@ -42,14 +43,14 @@ static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mai
 
 int main(int argc, char* argv[])
 {
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.load_platform(argv[1]);
 
-  simgrid::s4u::Mailbox* mb1 = simgrid::s4u::Mailbox::by_name("Mailbox 1");
-  simgrid::s4u::Mailbox* mb2 = simgrid::s4u::Mailbox::by_name("Mailbox 2");
+  sg4::Mailbox* mb1 = sg4::Mailbox::by_name("Mailbox 1");
+  sg4::Mailbox* mb2 = sg4::Mailbox::by_name("Mailbox 2");
 
-  simgrid::s4u::Actor::create("pinger", simgrid::s4u::Host::by_name("Tremblay"), pinger, mb1, mb2);
-  simgrid::s4u::Actor::create("ponger", simgrid::s4u::Host::by_name("Jupiter"), ponger, mb2, mb1);
+  sg4::Actor::create("pinger", sg4::Host::by_name("Tremblay"), pinger, mb1, mb2);
+  sg4::Actor::create("ponger", sg4::Host::by_name("Jupiter"), ponger, mb2, mb1);
 
   e.run();
 
index f3a2585..25dbce2 100644 (file)
@@ -22,6 +22,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_ready, "Messages specific for this s4u example");
 
@@ -35,17 +36,17 @@ static void peer(int argc, char** argv)
 
   /* Set myself as the persistent receiver of my mailbox so that messages start flowing to me as soon as they are put
    * into it */
-  simgrid::s4u::Mailbox* my_mbox = simgrid::s4u::Mailbox::by_name(std::string("peer-") + std::to_string(my_id));
-  my_mbox->set_receiver(simgrid::s4u::Actor::self());
+  sg4::Mailbox* my_mbox = sg4::Mailbox::by_name(std::string("peer-") + std::to_string(my_id));
+  my_mbox->set_receiver(sg4::Actor::self());
 
-  std::vector<simgrid::s4u::CommPtr> pending_comms;
+  std::vector<sg4::CommPtr> pending_comms;
 
   /* Start dispatching all messages to peers others that myself */
   for (int i = 0; i < messages_count; i++) {
     for (int peer_id = 0; peer_id < peers_count; peer_id++) {
       if (peer_id != my_id) {
         std::string mboxName        = std::string("peer-") + std::to_string(peer_id);
-        simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+        sg4::Mailbox* mbox          = sg4::Mailbox::by_name(mboxName);
         std::string msgName =
             std::string("Message ") + std::to_string(i) + std::string(" from peer ") + std::to_string(my_id);
         auto* payload = new std::string(msgName); // copy the data we send:
@@ -61,7 +62,7 @@ static void peer(int argc, char** argv)
   for (int peer_id = 0; peer_id < peers_count; peer_id++) {
     if (peer_id != my_id) {
       std::string mboxName        = std::string("peer-") + std::to_string(peer_id);
-      simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+      sg4::Mailbox* mbox          = sg4::Mailbox::by_name(mboxName);
       auto* payload               = new std::string("finalize"); // Make a copy of the data we will send
       pending_comms.push_back(mbox->put_async(payload, msg_size));
       XBT_INFO("Send 'finalize' to 'peer-%d'", peer_id);
@@ -74,9 +75,9 @@ static void peer(int argc, char** argv)
   long pending_finalize_messages = peers_count - 1;
   while (pending_finalize_messages > 0) {
     if (my_mbox->ready()) {
-      double start        = simgrid::s4u::Engine::get_clock();
+      double start        = sg4::Engine::get_clock();
       auto received       = my_mbox->get_unique<std::string>();
-      double waiting_time = simgrid::s4u::Engine::get_clock() - start;
+      double waiting_time = sg4::Engine::get_clock() - start;
       xbt_assert(
           waiting_time == 0,
           "Expecting the waiting time to be 0 because the communication was supposedly ready, but got %f instead",
@@ -87,12 +88,12 @@ static void peer(int argc, char** argv)
       }
     } else {
       XBT_INFO("Nothing ready to consume yet, I better sleep for a while");
-      simgrid::s4u::this_actor::sleep_for(.01);
+      sg4::this_actor::sleep_for(.01);
     }
   }
 
   XBT_INFO("I'm done, just waiting for my peers to receive the messages before exiting");
-  simgrid::s4u::Comm::wait_all(&pending_comms);
+  sg4::Comm::wait_all(&pending_comms);
 
   XBT_INFO("Goodbye now!");
 }
@@ -101,7 +102,7 @@ int main(int argc, char* argv[])
 {
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.register_function("peer", &peer);
 
   e.load_platform(argv[1]);
index af6db22..7af40f9 100644 (file)
@@ -9,6 +9,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_wait, "Messages specific for this s4u example");
 
@@ -16,20 +17,20 @@ static void sender(int argc, char**)
 {
   xbt_assert(argc == 1, "Expecting no parameter from the XML deployment file but got %d", argc - 1);
 
-  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
+  sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver");
 
   // Copy the data we send: the 'msg_content' variable is not a stable storage location.
   // It will be destroyed when this actor leaves the loop, ie before the receiver gets the data
   auto* payload = new std::string("Sent message");
 
   /* Create a communication representing the ongoing communication and then */
-  simgrid::s4u::CommPtr comm = mbox->put_init(payload, 13194230);
+  sg4::CommPtr comm = mbox->put_init(payload, 13194230);
   XBT_INFO("Suspend the communication before it starts (remaining: %.0f bytes) and wait a second.",
            comm->get_remaining());
-  simgrid::s4u::this_actor::sleep_for(1);
+  sg4::this_actor::sleep_for(1);
   XBT_INFO("Now, start the communication (remaining: %.0f bytes) and wait another second.", comm->get_remaining());
   comm->start();
-  simgrid::s4u::this_actor::sleep_for(1);
+  sg4::this_actor::sleep_for(1);
 
   XBT_INFO("There is still %.0f bytes to transfer in this communication. Suspend it for one second.",
            comm->get_remaining());
@@ -44,7 +45,7 @@ static void sender(int argc, char**)
 
 static void receiver(int, char**)
 {
-  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
+  sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver");
   XBT_INFO("Wait for the message.");
   auto received = mbox->get_unique<std::string>();
 
@@ -55,7 +56,7 @@ int main(int argc, char* argv[])
 {
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.register_function("sender", &sender);
   e.register_function("receiver", &receiver);
 
index d34d916..25cf806 100644 (file)
@@ -15,6 +15,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_wait, "Messages specific for this s4u example");
 
@@ -26,10 +27,10 @@ static void sender(int argc, char** argv)
   double sleep_start_time = 5.0;
   double sleep_test_time  = 0;
 
-  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
+  sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver");
 
   XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
-  simgrid::s4u::this_actor::sleep_for(sleep_start_time);
+  sg4::this_actor::sleep_for(sleep_start_time);
 
   for (int i = 0; i < messages_count; i++) {
     std::string msg_content = std::string("Message ") + std::to_string(i);
@@ -38,12 +39,12 @@ static void sender(int argc, char** argv)
     auto* payload = new std::string(msg_content);
 
     /* Create a communication representing the ongoing communication and then */
-    simgrid::s4u::CommPtr comm = mbox->put_async(payload, msg_size);
+    sg4::CommPtr comm = mbox->put_async(payload, msg_size);
     XBT_INFO("Send '%s' to '%s'", msg_content.c_str(), mbox->get_cname());
 
     if (sleep_test_time > 0) {   /* - "test_time" is set to 0, wait */
       while (not comm->test()) { /* - Call test() every "sleep_test_time" otherwise */
-        simgrid::s4u::this_actor::sleep_for(sleep_test_time);
+        sg4::this_actor::sleep_for(sleep_test_time);
       }
     } else {
       comm->wait();
@@ -61,19 +62,19 @@ static void receiver(int, char**)
   double sleep_start_time = 1.0;
   double sleep_test_time  = 0.1;
 
-  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
+  sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver");
 
   XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, sleep_test_time);
-  simgrid::s4u::this_actor::sleep_for(sleep_start_time);
+  sg4::this_actor::sleep_for(sleep_start_time);
 
   XBT_INFO("Wait for my first message");
   for (bool cont = true; cont;) {
     std::string* received;
-    simgrid::s4u::CommPtr comm = mbox->get_async<std::string>(&received);
+    sg4::CommPtr comm = mbox->get_async<std::string>(&received);
 
     if (sleep_test_time > 0) {   /* - "test_time" is set to 0, wait */
       while (not comm->test()) { /* - Call test() every "sleep_test_time" otherwise */
-        simgrid::s4u::this_actor::sleep_for(sleep_test_time);
+        sg4::this_actor::sleep_for(sleep_test_time);
       }
     } else {
       comm->wait();
@@ -90,7 +91,7 @@ int main(int argc, char* argv[])
 {
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.register_function("sender", &sender);
   e.register_function("receiver", &receiver);
 
index 26ada76..79e78ac 100644 (file)
@@ -16,6 +16,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_waitall, "Messages specific for this s4u example");
 
@@ -36,12 +37,12 @@ public:
   {
     // sphinx-doc: init-begin (this line helps the doc to build; ignore it)
     /* Vector in which we store all ongoing communications */
-    std::vector<simgrid::s4u::CommPtr> pending_comms;
+    std::vector<sg4::CommPtr> pending_comms;
 
     /* Make a vector of the mailboxes to use */
-    std::vector<simgrid::s4u::Mailbox*> mboxes;
+    std::vector<sg4::Mailbox*> mboxes;
     for (int i = 0; i < receivers_count; i++)
-      mboxes.push_back(simgrid::s4u::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
+      mboxes.push_back(sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
     // sphinx-doc: init-end
 
     /* Start dispatching all messages to receivers, in a round robin fashion */
@@ -54,20 +55,20 @@ public:
       XBT_INFO("Send '%s' to '%s'", msg_content.c_str(), mboxes[i % receivers_count]->get_cname());
 
       /* Create a communication representing the ongoing communication, and store it in pending_comms */
-      simgrid::s4u::CommPtr comm = mboxes[i % receivers_count]->put_async(payload, msg_size);
+      sg4::CommPtr comm = mboxes[i % receivers_count]->put_async(payload, msg_size);
       pending_comms.push_back(comm);
     }
 
     /* Start sending messages to let the workers know that they should stop */ // sphinx-doc: put-begin
     for (int i = 0; i < receivers_count; i++) {
       XBT_INFO("Send 'finalize' to 'receiver-%d'", i);
-      simgrid::s4u::CommPtr comm = mboxes[i]->put_async(new std::string("finalize"), 0);
+      sg4::CommPtr comm = mboxes[i]->put_async(new std::string("finalize"), 0);
       pending_comms.push_back(comm);
     }
     XBT_INFO("Done dispatching all messages");
 
     /* Now that all message exchanges were initiated, wait for their completion in one single call */
-    simgrid::s4u::Comm::wait_all(&pending_comms);
+    sg4::Comm::wait_all(&pending_comms);
     // sphinx-doc: put-end
 
     XBT_INFO("Goodbye now!");
@@ -76,14 +77,14 @@ public:
 
 /* Receiver actor expects 1 argument: its ID */
 class Receiver {
-  simgrid::s4u::Mailbox* mbox;
+  sg4::Mailbox* mbox;
 
 public:
   explicit Receiver(std::vector<std::string> args)
   {
     xbt_assert(args.size() == 2, "Expecting one parameter from the XML deployment file but got %zu", args.size());
     std::string mboxName = std::string("receiver-") + args[1];
-    mbox                 = simgrid::s4u::Mailbox::by_name(mboxName);
+    mbox                 = sg4::Mailbox::by_name(mboxName);
   }
   void operator()()
   {
@@ -101,7 +102,7 @@ int main(int argc, char* argv[])
 {
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.register_actor<Sender>("sender");
   e.register_actor<Receiver>("receiver");
 
index 6668c9e..e8f20ae 100644 (file)
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_waitall, "Messages specific for this s4u example");
 
@@ -40,12 +41,12 @@ public:
   void operator()() const
   {
     /* Vector in which we store all ongoing communications */
-    std::vector<simgrid::s4u::CommPtr> pending_comms;
+    std::vector<sg4::CommPtr> pending_comms;
 
     /* Make a vector of the mailboxes to use */
-    std::vector<simgrid::s4u::Mailbox*> mboxes;
+    std::vector<sg4::Mailbox*> mboxes;
     for (int i = 0; i < receivers_count; i++)
-      mboxes.push_back(simgrid::s4u::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
+      mboxes.push_back(sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(i)));
 
     /* Start dispatching all messages to receivers, in a round robin fashion */
     for (int i = 0; i < messages_count; i++) {
@@ -57,14 +58,14 @@ public:
       XBT_INFO("Send '%s' to '%s'", msg_content.c_str(), mboxes[i % receivers_count]->get_cname());
 
       /* Create a communication representing the ongoing communication, and store it in pending_comms */
-      simgrid::s4u::CommPtr comm = mboxes[i % receivers_count]->put_async(payload, msg_size);
+      sg4::CommPtr comm = mboxes[i % receivers_count]->put_async(payload, msg_size);
       pending_comms.push_back(comm);
     }
 
     /* Start sending messages to let the workers know that they should stop */
     for (int i = 0; i < receivers_count; i++) {
       XBT_INFO("Send 'finalize' to 'receiver-%d'", i);
-      simgrid::s4u::CommPtr comm = mboxes[i]->put_async(new std::string("finalize"), 0);
+      sg4::CommPtr comm = mboxes[i]->put_async(new std::string("finalize"), 0);
       pending_comms.push_back(comm);
     }
     XBT_INFO("Done dispatching all messages");
@@ -76,7 +77,7 @@ public:
      * Even in this simple example, the pending comms do not terminate in the exact same order of creation.
      */
     while (not pending_comms.empty()) {
-      int changed_pos = simgrid::s4u::Comm::wait_any(&pending_comms);
+      int changed_pos = sg4::Comm::wait_any(&pending_comms);
       pending_comms.erase(pending_comms.begin() + changed_pos);
       if (changed_pos != 0)
         XBT_INFO("Remove the %dth pending comm: it terminated earlier than another comm that was initiated first.",
@@ -89,14 +90,14 @@ public:
 
 /* Receiver actor expects 1 argument: its ID */
 class Receiver {
-  simgrid::s4u::Mailbox* mbox;
+  sg4::Mailbox* mbox;
 
 public:
   explicit Receiver(std::vector<std::string> args)
   {
     xbt_assert(args.size() == 2, "Expecting one parameter from the XML deployment file but got %zu", args.size());
     std::string mboxName = std::string("receiver-") + args[1];
-    mbox                 = simgrid::s4u::Mailbox::by_name(mboxName);
+    mbox                 = sg4::Mailbox::by_name(mboxName);
   }
   void operator()()
   {
@@ -114,7 +115,7 @@ int main(int argc, char* argv[])
 {
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.register_actor<Sender>("sender");
   e.register_actor<Receiver>("receiver");
 
index b123c9b..5ac7b1b 100644 (file)
@@ -14,6 +14,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_waituntil, "Messages specific for this s4u example");
 
@@ -24,19 +25,19 @@ static void sender(int argc, char** argv)
   long msg_size        = std::stol(argv[2]); /* - message size in bytes */
   long receivers_count = std::stol(argv[3]); /* - number of receivers */
 
-  std::vector<simgrid::s4u::CommPtr> pending_comms;
+  std::vector<sg4::CommPtr> pending_comms;
 
   /* Start dispatching all messages to receivers, in a round robin fashion */
   for (int i = 0; i < messages_count; i++) {
     std::string mboxName        = std::string("receiver-") + std::to_string(i % receivers_count);
-    simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+    sg4::Mailbox* mbox          = sg4::Mailbox::by_name(mboxName);
     std::string msgName         = std::string("Message ") + std::to_string(i);
     auto* payload               = new std::string(msgName); // copy the data we send:
 
     // 'msgName' is not a stable storage location
     XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str());
     /* Create a communication representing the ongoing communication */
-    simgrid::s4u::CommPtr comm = mbox->put_async(payload, msg_size);
+    sg4::CommPtr comm = mbox->put_async(payload, msg_size);
     /* Add this comm to the vector of all known comms */
     pending_comms.push_back(comm);
   }
@@ -44,10 +45,10 @@ static void sender(int argc, char** argv)
   /* Start sending messages to let the workers know that they should stop */
   for (int i = 0; i < receivers_count; i++) {
     std::string mboxName        = std::string("receiver-") + std::to_string(i % receivers_count);
-    simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
+    sg4::Mailbox* mbox          = sg4::Mailbox::by_name(mboxName);
     auto* payload               = new std::string("finalize"); // Make a copy of the data we will send
 
-    simgrid::s4u::CommPtr comm = mbox->put_async(payload, 0);
+    sg4::CommPtr comm = mbox->put_async(payload, 0);
     pending_comms.push_back(comm);
     XBT_INFO("Send 'finalize' to 'receiver-%ld'", i % receivers_count);
   }
@@ -55,7 +56,7 @@ static void sender(int argc, char** argv)
 
   /* Now that all message exchanges were initiated, wait for their completion, in order of creation. */
   while (not pending_comms.empty()) {
-    simgrid::s4u::CommPtr comm = pending_comms.back();
+    sg4::CommPtr comm = pending_comms.back();
     comm->wait_for(1);
     pending_comms.pop_back(); // remove it from the list
   }
@@ -67,7 +68,7 @@ static void sender(int argc, char** argv)
 static void receiver(int argc, char** argv)
 {
   xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc);
-  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(std::string("receiver-") + argv[1]);
+  sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("receiver-") + argv[1]);
 
   XBT_INFO("Wait for my first message");
   for (bool cont = true; cont;) {
@@ -82,7 +83,7 @@ int main(int argc, char* argv[])
 {
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);
 
-  simgrid::s4u::Engine e(&argc, argv);
+  sg4::Engine e(&argc, argv);
   e.register_function("sender", &sender);
   e.register_function("receiver", &receiver);