Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
get/set for CommImpl::type
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Sun, 27 Feb 2022 22:15:07 +0000 (23:15 +0100)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Tue, 1 Mar 2022 01:11:38 +0000 (02:11 +0100)
src/kernel/activity/CommImpl.cpp
src/kernel/activity/CommImpl.hpp
src/kernel/activity/MailboxImpl.cpp
src/kernel/activity/MailboxImpl.hpp

index efdec76..bbc8910 100644 (file)
@@ -53,6 +53,12 @@ void CommImpl::set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t)
   copy_data_callback_ = callback;
 }
 
+CommImpl& CommImpl::set_type(CommImplType type)
+{
+  type_ = type;
+  return *this;
+}
+
 CommImpl& CommImpl::set_size(double size)
 {
   size_ = size;
@@ -211,14 +217,15 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer)
   XBT_DEBUG("send from mailbox %p", mbox);
 
   /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
-  CommImplPtr this_comm(new CommImpl(CommImpl::Type::SEND));
+  CommImplPtr this_comm(new CommImpl());
+  this_comm->set_type(CommImplType::SEND);
 
   /* Look for communication synchro matching our needs. We also provide a description of
    * ourself so that the other side also gets a chance of choosing if it wants to match with us.
    *
    * If it is not found then push our communication into the rendez-vous point */
   CommImplPtr other_comm =
-      mbox->find_matching_comm(CommImpl::Type::RECEIVE, observer->get_match_fun(), observer->get_payload(), this_comm,
+      mbox->find_matching_comm(CommImplType::RECEIVE, observer->get_match_fun(), observer->get_payload(), this_comm,
                                /*done*/ false, /*remove_matching*/ true);
 
   if (not other_comm) {
@@ -270,7 +277,9 @@ ActivityImplPtr CommImpl::isend(actor::CommIsendSimcall* observer)
 
 ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
 {
-  CommImplPtr this_synchro(new CommImpl(CommImpl::Type::RECEIVE));
+  CommImplPtr this_synchro(new CommImpl());
+  this_synchro->set_type(CommImplType::RECEIVE);
+
   auto* mbox = observer->get_mailbox();
   XBT_DEBUG("recv from mbox %p. this_synchro=%p", mbox, this_synchro.get());
 
@@ -279,7 +288,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
   if (mbox->is_permanent() && mbox->has_some_done_comm()) {
     XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication");
     // find a match in the list of already received comms
-    other_comm = mbox->find_matching_comm(CommImpl::Type::SEND, observer->get_match_fun(), observer->get_payload(),
+    other_comm = mbox->find_matching_comm(CommImplType::SEND, observer->get_match_fun(), observer->get_payload(),
                                           this_synchro, /*done*/ true, /*remove_matching*/ true);
     // if not found, assume the receiver came first, register it to the mailbox in the classical way
     if (not other_comm) {
@@ -301,7 +310,7 @@ ActivityImplPtr CommImpl::irecv(actor::CommIrecvSimcall* observer)
      * ourself so that the other side also gets a chance of choosing if it wants to match with us.
      *
      * If it is not found then push our communication into the rendez-vous point */
-    other_comm = mbox->find_matching_comm(CommImpl::Type::SEND, observer->get_match_fun(), observer->get_payload(),
+    other_comm = mbox->find_matching_comm(CommImplType::SEND, observer->get_match_fun(), observer->get_payload(),
                                           this_synchro, /*done*/ false, /*remove_matching*/ true);
 
     if (other_comm == nullptr) {
index d14f5dd..2d9a902 100644 (file)
@@ -14,6 +14,8 @@ namespace simgrid {
 namespace kernel {
 namespace activity {
 
+enum class CommImplType { SEND, RECEIVE };
+
 class XBT_PUBLIC CommImpl : public ActivityImpl_T<CommImpl> {
   ~CommImpl() override;
   void cleanup_surf();
@@ -29,15 +31,16 @@ class XBT_PUBLIC CommImpl : public ActivityImpl_T<CommImpl> {
   long mbox_id_      = -1;      /* ID of the rendez-vous where the comm was first queued (for MC) */
   s4u::Host* from_   = nullptr; /* Pre-determined only for direct host-to-host communications */
   s4u::Host* to_     = nullptr; /* Otherwise, computed at start() time from the actors */
+  CommImplType type_ = CommImplType::SEND; /* Type of the communication (SEND or RECEIVE) */
 
 public:
-  enum class Type { SEND, RECEIVE };
-
   static void set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t));
 
-  explicit CommImpl(Type type) : type_(type) {}
+  CommImpl() = default;
   CommImpl(s4u::Host* from, s4u::Host* to, double bytes);
 
+  CommImpl& set_type(CommImplType type);
+  CommImplType get_type() const { return type_; }
   CommImpl& set_size(double size);
   CommImpl& set_src_buff(unsigned char* buff, size_t size);
   CommImpl& set_dst_buff(unsigned char* buff, size_t* size);
@@ -68,7 +71,6 @@ public:
   void set_exception(actor::ActorImpl* issuer) override;
   void finish() override;
 
-  const Type type_ = Type::SEND; /* Type of the communication (SEND or RECEIVE) */
 
 #if SIMGRID_HAVE_MC
   MailboxImpl* mbox_cpy = nullptr; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
index febedbe..a046c69 100644 (file)
@@ -60,23 +60,23 @@ CommImplPtr MailboxImpl::iprobe(int type, bool (*match_fun)(void*, void*, CommIm
 {
   XBT_DEBUG("iprobe from %p %p", this, &comm_queue_);
 
-  CommImplPtr this_comm;
-  CommImpl::Type smx_type;
+  CommImplPtr this_comm(new CommImpl);
+  CommImplType other_type;
   if (type == 1) {
-    this_comm = CommImplPtr(new CommImpl(CommImpl::Type::SEND));
-    smx_type  = CommImpl::Type::RECEIVE;
+    this_comm->set_type(CommImplType::SEND);
+    other_type = CommImplType::RECEIVE;
   } else {
-    this_comm = CommImplPtr(new CommImpl(CommImpl::Type::RECEIVE));
-    smx_type  = CommImpl::Type::SEND;
+    this_comm->set_type(CommImplType::RECEIVE);
+    other_type = CommImplType::SEND;
   }
   CommImplPtr other_comm = nullptr;
   if (permanent_receiver_ != nullptr && not done_comm_queue_.empty()) {
     XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something");
-    other_comm = find_matching_comm(smx_type, match_fun, data, this_comm, /*done*/ true, /*remove_matching*/ false);
+    other_comm = find_matching_comm(other_type, match_fun, data, this_comm, /*done*/ true, /*remove_matching*/ false);
   }
   if (not other_comm) {
     XBT_DEBUG("check if we have more luck in the normal mailbox");
-    other_comm = find_matching_comm(smx_type, match_fun, data, this_comm, /*done*/ false, /*remove_matching*/ false);
+    other_comm = find_matching_comm(other_type, match_fun, data, this_comm, /*done*/ false, /*remove_matching*/ false);
   }
 
   return other_comm;
@@ -91,7 +91,7 @@ CommImplPtr MailboxImpl::iprobe(int type, bool (*match_fun)(void*, void*, CommIm
  *  @param remove_matching whether or not to clean the found object from the queue
  *  @return The communication activity if found, nullptr otherwise
  */
-CommImplPtr MailboxImpl::find_matching_comm(CommImpl::Type type, bool (*match_fun)(void*, void*, CommImpl*),
+CommImplPtr MailboxImpl::find_matching_comm(CommImplType type, bool (*match_fun)(void*, void*, CommImpl*),
                                             void* this_user_data, const CommImplPtr& my_synchro, bool done,
                                             bool remove_matching)
 {
@@ -99,8 +99,8 @@ CommImplPtr MailboxImpl::find_matching_comm(CommImpl::Type type, bool (*match_fu
 
   auto iter = std::find_if(
       comm_queue.begin(), comm_queue.end(), [&type, &match_fun, &this_user_data, &my_synchro](const CommImplPtr& comm) {
-        void* other_user_data = (comm->type_ == CommImpl::Type::SEND ? comm->src_data_ : comm->dst_data_);
-        return (comm->type_ == type && (not match_fun || match_fun(this_user_data, other_user_data, comm.get())) &&
+        void* other_user_data = (comm->get_type() == CommImplType::SEND ? comm->src_data_ : comm->dst_data_);
+        return (comm->get_type() == type && (not match_fun || match_fun(this_user_data, other_user_data, comm.get())) &&
                 (not comm->match_fun || comm->match_fun(other_user_data, this_user_data, my_synchro.get())));
       });
   if (iter == comm_queue.end()) {
index 3247b05..b9c1214 100644 (file)
@@ -53,7 +53,7 @@ public:
   void push_done(CommImplPtr done_comm) { done_comm_queue_.push_back(done_comm); }
   void remove(const CommImplPtr& comm);
   CommImplPtr iprobe(int type, bool (*match_fun)(void*, void*, CommImpl*), void* data);
-  CommImplPtr find_matching_comm(CommImpl::Type type, bool (*match_fun)(void*, void*, CommImpl*), void* this_user_data,
+  CommImplPtr find_matching_comm(CommImplType type, bool (*match_fun)(void*, void*, CommImpl*), void* this_user_data,
                                  const CommImplPtr& my_synchro, bool done, bool remove_matching);
   bool is_permanent() const { return permanent_receiver_ != nullptr; }
   actor::ActorImplPtr get_permanent_receiver() const { return permanent_receiver_; }