Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make mailbox matching functions return a bool.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 12 Dec 2019 20:54:17 +0000 (21:54 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 16 Dec 2019 12:05:20 +0000 (13:05 +0100)
12 files changed:
include/simgrid/s4u/Comm.hpp
include/simgrid/s4u/Mailbox.hpp
include/simgrid/simix.h
src/kernel/activity/CommImpl.cpp
src/kernel/activity/CommImpl.hpp
src/kernel/activity/MailboxImpl.cpp
src/kernel/activity/MailboxImpl.hpp
src/s4u/s4u_Mailbox.cpp
src/simix/libsmx.cpp
src/simix/popping_private.hpp
src/smpi/include/smpi_request.hpp
src/smpi/mpi/smpi_request.cpp

index 153be7e..1b36682 100644 (file)
@@ -30,7 +30,7 @@ class XBT_PUBLIC Comm : public Activity_T<Comm> {
   std::string tracing_category_       = "";
   /* FIXME: expose these elements in the API */
   bool detached_                                                          = false;
-  int (*match_fun_)(void*, void*, kernel::activity::CommImpl*)            = nullptr;
+  bool (*match_fun_)(void*, void*, kernel::activity::CommImpl*)           = nullptr;
   void (*clean_fun_)(void*)                                               = nullptr;
   void (*copy_data_function_)(kernel::activity::CommImpl*, void*, size_t) = nullptr;
 
index 989ae54..94a58bc 100644 (file)
@@ -80,7 +80,7 @@ public:
   /** Creates and start a data transmission to that mailbox */
   CommPtr put_async(void* data, uint64_t simulated_size_in_bytes);
 
-  smx_activity_t iprobe(int type, int (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data);
+  smx_activity_t iprobe(int type, bool (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data);
   /** Blocking data transmission */
   void put(void* payload, uint64_t simulated_size_in_bytes);
   /** Blocking data transmission with timeout */
index 4adb5c0..382682f 100644 (file)
@@ -138,30 +138,30 @@ SG_END_DECL
 #ifdef __cplusplus
 XBT_PUBLIC void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
                                   size_t src_buff_size,
-                                  int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                  bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                   void* data, double timeout);
 
 XBT_PUBLIC smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate,
                                              void* src_buff, size_t src_buff_size,
-                                             int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                             bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                              void (*clean_fun)(void*),
                                              void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                              void* data, bool detached);
 
 XBT_PUBLIC void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
-                                  int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                  bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                   void* data, double timeout, double rate);
 
 XBT_PUBLIC smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff,
                                              size_t* dst_buff_size,
-                                             int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                             bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                              void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                              void* data, double rate);
 
 XBT_PUBLIC smx_activity_t simcall_comm_iprobe(smx_mailbox_t mbox, int type,
-                                              int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                              bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                               void* data);
 
 /* FIXME: waitany is going to be a vararg function, and should take a timeout */
index e6cc960..63aeb02 100644 (file)
@@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related syn
 
 XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t src, smx_mailbox_t mbox, double task_size,
                                            double rate, unsigned char* src_buff, size_t src_buff_size,
-                                           int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                           bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                            void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                            void* data, double timeout)
 {
@@ -32,7 +32,8 @@ XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t sr
 
 XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend(
     smx_simcall_t /*simcall*/, smx_actor_t src_proc, smx_mailbox_t mbox, double task_size, double rate,
-    unsigned char* src_buff, size_t src_buff_size, int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+    unsigned char* src_buff, size_t src_buff_size,
+    bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
     void (*clean_fun)(void*), // used to free the synchro in case of problem after a detached send
     void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), // used to copy data if not default one
     void* data, bool detached)
@@ -98,7 +99,7 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend(
 
 XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox,
                                            unsigned char* dst_buff, size_t* dst_buff_size,
-                                           int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                           bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                            void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                            void* data, double timeout, double rate)
 {
@@ -110,8 +111,8 @@ XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t re
 
 XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(
     smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size,
-    simix_match_func_t match_fun, void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
-    void* data, double rate)
+    bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+    void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double rate)
 {
   simgrid::kernel::activity::CommImplPtr this_synchro =
       simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl());
index 7c0691a..82368ff 100644 (file)
@@ -58,7 +58,7 @@ public:
 #endif
 
   void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
-  int (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
+  bool (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
 looking if a given communication matches my needs. For that, myself must match the
 expectations of the other side, too. See  */
   void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr;
index 3137c62..8915ec7 100644 (file)
@@ -85,7 +85,7 @@ void MailboxImpl::remove(const CommImplPtr& comm)
   xbt_die("Comm %p not found in mailbox %s", comm.get(), this->get_cname());
 }
 
-CommImplPtr MailboxImpl::iprobe(int type, int (*match_fun)(void*, void*, CommImpl*), void* data)
+CommImplPtr MailboxImpl::iprobe(int type, bool (*match_fun)(void*, void*, CommImpl*), void* data)
 {
   XBT_DEBUG("iprobe from %p %p", this, &comm_queue_);
 
@@ -122,7 +122,7 @@ CommImplPtr MailboxImpl::iprobe(int type, int (*match_fun)(void*, void*, CommImp
  *  @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, int (*match_fun)(void*, void*, CommImpl*),
+CommImplPtr MailboxImpl::find_matching_comm(CommImpl::Type type, bool (*match_fun)(void*, void*, CommImpl*),
                                             void* this_user_data, const CommImplPtr& my_synchro, bool done,
                                             bool remove_matching)
 {
index ac05e66..5cb5a9f 100644 (file)
@@ -42,8 +42,8 @@ public:
   void set_receiver(s4u::ActorPtr actor);
   void push(CommImplPtr comm);
   void remove(const CommImplPtr& comm);
-  CommImplPtr iprobe(int type, int (*match_fun)(void*, void*, CommImpl*), void* data);
-  CommImplPtr find_matching_comm(CommImpl::Type type, int (*match_fun)(void*, void*, CommImpl*), void* this_user_data,
+  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,
                                  const CommImplPtr& my_synchro, bool done, bool remove_matching);
 
   actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
index 95c0ab0..0ab6de7 100644 (file)
@@ -150,7 +150,7 @@ void* Mailbox::get(double timeout)
   return res;
 }
 
-smx_activity_t Mailbox::iprobe(int type, int (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data)
+smx_activity_t Mailbox::iprobe(int type, bool (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data)
 {
   return kernel::actor::simcall([this, type, match_fun, data] { return pimpl_->iprobe(type, match_fun, data); });
 }
index 42988e9..9410c2f 100644 (file)
@@ -65,7 +65,7 @@ e_smx_state_t simcall_process_sleep(double duration) // XBT_DEPRECATED_v329
  * @ingroup simix_comm_management
  */
 void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
-                       size_t src_buff_size, int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                       size_t src_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                        void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
                        double timeout)
 {
@@ -95,7 +95,7 @@ void simcall_comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_size,
  */
 smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff,
                                   size_t src_buff_size,
-                                  int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                  bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                   void (*clean_fun)(void*),
                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                   void* data, bool detached)
@@ -114,7 +114,7 @@ smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double
  * @ingroup simix_comm_management
  */
 void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
-                       int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                       bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                        void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
                        double timeout, double rate)
 {
@@ -138,7 +138,7 @@ void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff,
  * @ingroup simix_comm_management
  */
 smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
-                                  int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
+                                  bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
                                   void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                   void* data, double rate)
 {
@@ -152,7 +152,7 @@ smx_activity_t simcall_comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, void
  * @ingroup simix_comm_management
  */
 smx_activity_t simcall_comm_iprobe(smx_mailbox_t mbox, int type,
-                                   int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void* data)
+                                   bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), void* data)
 {
   xbt_assert(mbox, "No rendez-vous point defined for iprobe");
 
index 26a3cbc..1a7ce1c 100644 (file)
@@ -16,7 +16,7 @@
 
 XBT_PUBLIC_DATA const char* simcall_names[]; /* Name of each simcall */
 
-typedef int (*simix_match_func_t)(void*, void*, simgrid::kernel::activity::CommImpl*);
+typedef bool (*simix_match_func_t)(void*, void*, simgrid::kernel::activity::CommImpl*);
 typedef void (*simix_copy_data_func_t)(simgrid::kernel::activity::CommImpl*, void*, size_t);
 typedef void (*simix_clean_func_t)(void*);
 typedef void (*FPtr)(void); // Hide the ugliness
index cc64583..62d1ae2 100644 (file)
@@ -111,8 +111,8 @@ public:
   static int waitall(int count, MPI_Request requests[], MPI_Status status[]);
   static int waitsome(int incount, MPI_Request requests[], int* indices, MPI_Status status[]);
 
-  static int match_send(void* a, void* b, kernel::activity::CommImpl* ignored);
-  static int match_recv(void* a, void* b, kernel::activity::CommImpl* ignored);
+  static bool match_send(void* a, void* b, kernel::activity::CommImpl* ignored);
+  static bool match_recv(void* a, void* b, kernel::activity::CommImpl* ignored);
 
   static int grequest_start( MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn, MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request);
   static int grequest_complete( MPI_Request request);
index c907155..6011cd7 100644 (file)
@@ -108,7 +108,7 @@ void Request::unref(MPI_Request* request)
   }
 }
 
-int Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*)
+bool Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*)
 {
   MPI_Request ref = static_cast<MPI_Request>(a);
   MPI_Request req = static_cast<MPI_Request>(b);
@@ -131,11 +131,12 @@ int Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*)
     if(req->cancelled_==0)
       req->cancelled_ = -1; // mark as uncancelable
     XBT_DEBUG("match succeeded");
-    return 1;
-  }else return 0;
+    return true;
+  }
+  return false;
 }
 
-int Request::match_send(void* a, void* b, simgrid::kernel::activity::CommImpl*)
+bool Request::match_send(void* a, void* b, simgrid::kernel::activity::CommImpl*)
 {
   MPI_Request ref = static_cast<MPI_Request>(a);
   MPI_Request req = static_cast<MPI_Request>(b);
@@ -157,9 +158,9 @@ int Request::match_send(void* a, void* b, simgrid::kernel::activity::CommImpl*)
     if(req->cancelled_==0)
       req->cancelled_ = -1; // mark as uncancelable
     XBT_DEBUG("match succeeded");
-    return 1;
-  } else
-    return 0;
+    return true;
+  }
+  return false;
 }
 
 void Request::print_request(const char *message)