Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
enable sendto_init()->set_from(h1)->set_to(h2)
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Wed, 22 Dec 2021 13:43:49 +0000 (14:43 +0100)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Wed, 22 Dec 2021 13:43:49 +0000 (14:43 +0100)
include/simgrid/s4u/Comm.hpp
src/s4u/s4u_Comm.cpp

index 8a5fe9f..36e04e8 100644 (file)
@@ -44,6 +44,8 @@ public:
 
   ~Comm() override;
 
+  /*! Creates a communication that bypasses the mailbox mechanism. */
+  static CommPtr sendto_init();
   /*! Creates a communication beween the two given hosts, bypassing the mailbox mechanism. */
   static CommPtr sendto_init(Host* from, Host* to);
   /** Do an asynchronous communication between two arbitrary hosts.
@@ -104,6 +106,10 @@ public:
     return detach();
   }
 
+  /** Set the source and destination of communications that bypass the mailbox mechanism */
+  CommPtr set_from(Host* from);
+  CommPtr set_to(Host* to);
+
   /** Sets the maximal communication rate (in byte/sec). Must be done before start */
   CommPtr set_rate(double rate);
 
index 2b4bcd6..e2b0348 100644 (file)
@@ -85,6 +85,28 @@ size_t Comm::wait_all_for(const std::vector<CommPtr>& comms, double timeout)
   return comms.size();
 }
 
+CommPtr Comm::set_from(Host* from)
+{
+  xbt_assert(state_ == State::INITED || state_ == State::STARTING,
+             "Cannot change the source of a Comm once it's started (state: %s)", to_c_str(state_));
+  from_ = from;
+  // Setting 'from_' may allow to start the activity, let's try
+  vetoable_start();
+
+  return this;
+}
+
+CommPtr Comm::set_to(Host* to)
+{
+  xbt_assert(state_ == State::INITED || state_ == State::STARTING,
+             "Cannot change the destination of a Comm once it's started (state: %s)", to_c_str(state_));
+  to_ = to;
+  // Setting 'to_' may allow to start the activity, let's try
+  vetoable_start();
+
+  return this;
+}
+
 CommPtr Comm::set_rate(double rate)
 {
   xbt_assert(state_ == State::INITED, "You cannot use %s() once your communication started (not implemented)",
@@ -154,10 +176,16 @@ CommPtr Comm::set_payload_size(uint64_t bytes)
   return this;
 }
 
-CommPtr Comm::sendto_init(Host* from, Host* to)
+CommPtr Comm::sendto_init()
 {
   CommPtr res(new Comm());
   res->sender_ = kernel::actor::ActorImpl::self();
+  return res;
+}
+
+CommPtr Comm::sendto_init(Host* from, Host* to)
+{
+  auto res   = Comm::sendto_init();
   res->from_ = from;
   res->to_   = to;