Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make it possible to detach direct communications
[simgrid.git] / examples / s4u / comm-host2host / s4u-comm-host2host.cpp
index 790b9cb..7c80502 100644 (file)
@@ -30,6 +30,12 @@ static void sender(sg4::Host* h1, sg4::Host* h2, sg4::Host* h3, sg4::Host* h4)
   auto c34 = sg4::Comm::sendto_init(h3, h4); // Creates but do not start another direct communication
   c34->set_remaining(1e7);                   // Specify the amount of bytes to exchange in this comm
 
+  // You can also detach() communications that you never plan to test() or wait().
+  // Here we create a communication that only slows down the other ones
+  auto noise = sg4::Comm::sendto_init(h1, h2);
+  noise->set_remaining(10000);
+  noise->detach();
+
   XBT_INFO("After creation,  c12 is %s (remaining: %.2e bytes); c34 is %s (remaining: %.2e bytes)",
            c12->get_state_str(), c12->get_remaining(), c34->get_state_str(), c34->get_remaining());
   sg4::this_actor::sleep_for(1);
@@ -45,8 +51,8 @@ static void sender(sg4::Host* h1, sg4::Host* h2, sg4::Host* h3, sg4::Host* h4)
   XBT_INFO("After c34->wait, c12 is %s (remaining: %.2e bytes); c34 is %s (remaining: %.2e bytes)",
            c12->get_state_str(), c12->get_remaining(), c34->get_state_str(), c34->get_remaining());
 
-  /* As usual, you don't have to explicitly start communications that were just init()ed. The wait() will start it
-   * automatically. */
+  /* As usual, you don't have to explicitly start communications that were just init()ed.
+     The wait() will start it automatically. */
   auto c14 = sg4::Comm::sendto_init(h1, h4);
   c14->set_remaining(100)->wait(); // Chaining 2 operations on this new communication
 }
@@ -56,7 +62,7 @@ int main(int argc, char* argv[])
   sg4::Engine e(&argc, argv);
   e.load_platform(argv[1]);
 
-  sg4::Actor::create("sender", sg4::Host::by_name("Tremblay"), sender, sg4::Host::by_name("Tremblay"),
+  sg4::Actor::create("sender", sg4::Host::by_name("Boivin"), sender, sg4::Host::by_name("Tremblay"),
                      sg4::Host::by_name("Jupiter"), sg4::Host::by_name("Fafard"), sg4::Host::by_name("Ginette"));
 
   e.run();