Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make it possible to detach direct communications
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 20 Jan 2021 17:12:04 +0000 (18:12 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 20 Jan 2021 17:12:04 +0000 (18:12 +0100)
examples/s4u/comm-host2host/s4u-comm-host2host.cpp
examples/s4u/comm-host2host/s4u-comm-host2host.tesh
src/s4u/s4u_Comm.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();
index 5f3fc03..9dcda41 100644 (file)
@@ -1,12 +1,10 @@
 #!/usr/bin/env tesh
 
 $ ${bindir:=.}/s4u-comm-host2host ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2
-> [  0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1
-> [  0.019014] (2:ponger@Jupiter) Payload received : small communication (latency bound)
-> [  0.019014] (2:ponger@Jupiter) Ping time (latency bound) 0.019014
-> [  0.019014] (2:ponger@Jupiter) payload = 0.019
-> [150.178356] (1:pinger@Tremblay) Payload received : large communication (bandwidth bound)
-> [150.178356] (1:pinger@Tremblay) Pong time (bandwidth bound): 150.159
-> [150.178356] (0:maestro@) Total simulation time: 150.178
-
+> [  0.000000] (1:sender@Boivin) Send c12 with sendto_async(Tremblay -> Jupiter), and c34 with sendto_init(Fafard -> Ginette)
+> [  0.000000] (1:sender@Boivin) After creation,  c12 is STARTED (remaining: 1.50e+07 bytes); c34 is INITED (remaining: 1.00e+07 bytes)
+> [  1.000000] (1:sender@Boivin) One sec later,   c12 is STARTED (remaining: 8.48e+06 bytes); c34 is INITED (remaining: 1.00e+07 bytes)
+> [  1.000000] (1:sender@Boivin) After c34->start,c12 is STARTED (remaining: 8.48e+06 bytes); c34 is STARTED (remaining: 1.00e+07 bytes)
+> [  2.272621] (1:sender@Boivin) After c12->wait, c12 is FINISHED (remaining: 0.00e+00 bytes); c34 is STARTED (remaining: 5.33e+05 bytes)
+> [  2.343278] (1:sender@Boivin) After c34->wait, c12 is FINISHED (remaining: 0.00e+00 bytes); c34 is FINISHED (remaining: 0.00e+00 bytes)
+> [  2.359841] (0:maestro@) Total simulation time: 2.360
index f9c3c37..8548847 100644 (file)
@@ -230,9 +230,9 @@ int Comm::test_any(const std::vector<CommPtr>* comms)
 
 Comm* Comm::detach()
 {
-  xbt_assert(state_ == State::INITED, "You cannot use %s() once your communication started (not implemented)",
-             __FUNCTION__);
-  xbt_assert(src_buff_ != nullptr && src_buff_size_ != 0, "You can only detach sends, not recvs");
+  xbt_assert(state_ == State::INITED, "You cannot use %s() once your communication is %s (not implemented)",
+             __FUNCTION__, get_state_str());
+  xbt_assert(dst_buff_ == nullptr && dst_buff_size_ == 0, "You can only detach sends, not recvs");
   detached_ = true;
   vetoable_start();
   return this;