Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / cpp / comm-suspend / s4u-comm-suspend.cpp
index af6db222c2b99998d064eac76977c79f45b55fc5..c3a7be7cfb2f8a3085ed9c4ef3608e9242303783 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2022. 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,27 +9,26 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+namespace sg4 = simgrid::s4u;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_wait, "Messages specific for this s4u example");
 
-static void sender(int argc, char**)
+static void sender()
 {
-  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());
@@ -42,9 +41,9 @@ static void sender(int argc, char**)
   comm->suspend();
 }
 
-static void receiver(int, char**)
+static void receiver()
 {
-  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>();
 
@@ -53,14 +52,13 @@ static void receiver(int, char**)
 
 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);
-  e.register_function("sender", &sender);
-  e.register_function("receiver", &receiver);
+  sg4::Engine e(&argc, argv);
 
   e.load_platform(argv[1]);
-  e.load_deployment(argv[2]);
+
+  sg4::Actor::create("sender", e.host_by_name("Tremblay"), sender);
+  sg4::Actor::create("receiver", e.host_by_name("Jupiter"), receiver);
+
   e.run();
 
   return 0;