Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use CommImpl* for comm_copy callbacks.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 19 Feb 2019 13:07:49 +0000 (14:07 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 20 Feb 2019 08:33:33 +0000 (09:33 +0100)
It's in fact already used for match_fun.

include/simgrid/s4u/Comm.hpp
include/simgrid/simix.h
src/kernel/activity/CommImpl.cpp
src/kernel/activity/CommImpl.hpp
src/msg/msg_gos.cpp
src/msg/msg_private.hpp
src/simix/libsmx.cpp
src/simix/popping_private.hpp
src/smpi/include/private.hpp
src/smpi/internals/smpi_global.cpp
src/smpi/mpi/smpi_request.cpp

index 2aa2f0a..7a540a9 100644 (file)
@@ -141,7 +141,7 @@ private:
   int detached_ = 0;
   int (*match_fun_)(void*, void*, simgrid::kernel::activity::CommImpl*) = nullptr;
   void (*clean_fun_)(void*)                                             = nullptr;
-  void (*copy_data_function_)(smx_activity_t, void*, size_t)            = nullptr;
+  void (*copy_data_function_)(simgrid::kernel::activity::CommImpl*, void*, size_t) = nullptr;
 
   smx_actor_t sender_   = nullptr;
   smx_actor_t receiver_ = nullptr;
index 1dac63b..61755af 100644 (file)
@@ -153,9 +153,14 @@ XBT_PUBLIC void SIMIX_process_on_exit(smx_actor_t process, std::function<void(in
 #endif
 
 /****************************** Communication *********************************/
-XBT_PUBLIC void SIMIX_comm_set_copy_data_callback(void (*callback)(smx_activity_t, void*, size_t));
-XBT_PUBLIC void SIMIX_comm_copy_pointer_callback(smx_activity_t comm, void* buff, size_t buff_size);
-XBT_PUBLIC void SIMIX_comm_copy_buffer_callback(smx_activity_t comm, void* buff, size_t buff_size);
+#ifdef __cplusplus
+XBT_PUBLIC void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*,
+                                                                   size_t));
+XBT_PUBLIC void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
+                                                 size_t buff_size);
+XBT_PUBLIC void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
+                                                size_t buff_size);
+#endif
 
 XBT_ATTRIB_DEPRECATED_v325("Please use CommImpl::finish") XBT_PUBLIC void SIMIX_comm_finish(smx_activity_t synchro);
 
@@ -195,25 +200,26 @@ SG_END_DECL()
 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*),
-                                  void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data, double timeout);
+                                  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*),
                                              void (*clean_fun)(void*),
-                                             void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data,
-                                             int detached);
+                                             void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
+                                             void* data, int 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*),
-                                  void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data, double timeout,
-                                  double rate);
+                                  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*),
-                                             void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data,
-                                             double rate);
+                                             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*),
index ff80213..3ec13f4 100644 (file)
@@ -21,8 +21,8 @@ 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, void* src_buff, size_t src_buff_size,
                                            int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
-                                           void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data,
-                                           double timeout)
+                                           void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
+                                           void* data, double timeout)
 {
   smx_activity_t comm = simcall_HANDLER_comm_isend(simcall, src, mbox, task_size, rate, src_buff, src_buff_size,
                                                    match_fun, nullptr, copy_data_fun, data, 0);
@@ -34,7 +34,7 @@ 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, void* src_buff,
     size_t src_buff_size, int (*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)(smx_activity_t, void*, size_t), // used to copy data if not default one
+    void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), // used to copy data if not default one
     void* data, int detached)
 {
   XBT_DEBUG("send from mailbox %p", mbox);
@@ -103,8 +103,8 @@ 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,
                                            void* dst_buff, size_t* dst_buff_size,
                                            int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
-                                           void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data,
-                                           double timeout, double rate)
+                                           void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
+                                           void* data, double timeout, double rate)
 {
   smx_activity_t comm = simcall_HANDLER_comm_irecv(simcall, receiver, mbox, dst_buff, dst_buff_size, match_fun,
                                                    copy_data_fun, data, rate);
@@ -112,11 +112,10 @@ XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t re
   simcall_HANDLER_comm_wait(simcall, comm, timeout);
 }
 
-XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, smx_actor_t receiver,
-                                                      smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
-                                                      simix_match_func_t match_fun,
-                                                      void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data,
-                                                      double rate)
+XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(
+    smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_mailbox_t mbox, void* 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)
 {
   simgrid::kernel::activity::CommImplPtr this_synchro = simgrid::kernel::activity::CommImplPtr(
       new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::RECEIVE));
@@ -350,13 +349,11 @@ void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros, d
 /******************************************************************************/
 /*                    SIMIX_comm_copy_data callbacks                       */
 /******************************************************************************/
-static void (*SIMIX_comm_copy_data_callback)(smx_activity_t, void*, size_t) = &SIMIX_comm_copy_pointer_callback;
+static void (*SIMIX_comm_copy_data_callback)(simgrid::kernel::activity::CommImpl*, void*,
+                                             size_t) = &SIMIX_comm_copy_pointer_callback;
 
-void SIMIX_comm_copy_buffer_callback(smx_activity_t synchro, void* buff, size_t buff_size)
+void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
 {
-  simgrid::kernel::activity::CommImplPtr comm =
-      boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro);
-
   XBT_DEBUG("Copy the data over");
   memcpy(comm->dst_buff_, buff, buff_size);
   if (comm->detached) { // if this is a detached send, the source buffer was duplicated by SMPI sender to make the
@@ -366,16 +363,13 @@ void SIMIX_comm_copy_buffer_callback(smx_activity_t synchro, void* buff, size_t
   }
 }
 
-void SIMIX_comm_set_copy_data_callback(void (*callback)(smx_activity_t, void*, size_t))
+void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*, size_t))
 {
   SIMIX_comm_copy_data_callback = callback;
 }
 
-void SIMIX_comm_copy_pointer_callback(smx_activity_t synchro, void* buff, size_t buff_size)
+void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
 {
-  simgrid::kernel::activity::CommImplPtr comm =
-      boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro);
-
   xbt_assert((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
   *(void**)(comm->dst_buff_) = buff;
 }
index f64dc44..9595782 100644 (file)
@@ -47,7 +47,7 @@ public:
       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)(smx_activity_t, void*, size_t) = nullptr;
+  void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t) = nullptr;
 
   /* Surf action data */
   resource::Action* surf_action_ = nullptr; /* The Surf communication action encapsulated */
index 8f3b098..770bf52 100644 (file)
@@ -642,15 +642,12 @@ msg_task_t MSG_comm_get_task(msg_comm_t comm)
 
 /**
  * @brief This function is called by SIMIX in kernel mode to copy the data of a comm.
- * @param synchro the comm
+ * @param comm the comm
  * @param buff the data copied
  * @param buff_size size of the buffer
  */
-void MSG_comm_copy_data_from_SIMIX(smx_activity_t synchro, void* buff, size_t buff_size)
+void MSG_comm_copy_data_from_SIMIX(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
 {
-  simgrid::kernel::activity::CommImplPtr comm =
-      boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro);
-
   SIMIX_comm_copy_pointer_callback(comm, buff, buff_size);
 
   // notify the user callback if any
index 6a4a795..e720eba 100644 (file)
@@ -79,7 +79,7 @@ typedef s_MSG_Global_t* MSG_Global_t;
 XBT_PUBLIC_DATA MSG_Global_t msg_global;
 
 /*************************************************************/
-XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(smx_activity_t comm, void* buff, size_t buff_size);
+XBT_PRIVATE void MSG_comm_copy_data_from_SIMIX(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size);
 
 /********** Tracing **********/
 /* declaration of instrumentation functions from msg_task_instr.c */
index 94d37fc..d9aa949 100644 (file)
@@ -118,7 +118,8 @@ e_smx_state_t simcall_process_sleep(double duration)
  */
 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*),
-                       void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data, double timeout)
+                       void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
+                       double timeout)
 {
   /* checking for infinite values */
   xbt_assert(std::isfinite(task_size), "task_size is not finite!");
@@ -147,7 +148,8 @@ 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*),
-                                  void (*clean_fun)(void*), void (*copy_data_fun)(smx_activity_t, void*, size_t),
+                                  void (*clean_fun)(void*),
+                                  void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
                                   void* data, int detached)
 {
   /* checking for infinite values */
@@ -166,7 +168,8 @@ smx_activity_t simcall_comm_isend(smx_actor_t sender, smx_mailbox_t mbox, double
  */
 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*),
-                       void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data, double timeout, double rate)
+                       void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
+                       double timeout, double rate)
 {
   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
   xbt_assert(mbox, "No rendez-vous point defined for recv");
@@ -189,7 +192,8 @@ void simcall_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff,
  */
 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*),
-                                  void (*copy_data_fun)(smx_activity_t, void*, size_t), void* data, double rate)
+                                  void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
+                                  void* data, double rate)
 {
   xbt_assert(mbox, "No rendez-vous point defined for irecv");
 
index 6342232..c20bd04 100644 (file)
@@ -17,7 +17,7 @@ XBT_PUBLIC_DATA const char* simcall_names[]; /* Name of each simcall */
 #include "popping_enum.h" /* Definition of e_smx_simcall_t, with one value per simcall */
 
 typedef int (*simix_match_func_t)(void*, void*, simgrid::kernel::activity::CommImpl*);
-typedef void (*simix_copy_data_func_t)(smx_activity_t, void*, size_t);
+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 80a047a..1ea8e09 100644 (file)
@@ -68,9 +68,11 @@ XBT_PRIVATE MPI_Comm* smpi_deployment_comm_world(const std::string& instance_id)
 XBT_PRIVATE simgrid::s4u::Barrier* smpi_deployment_finalization_barrier(const std::string& instance_id);
 XBT_PRIVATE void smpi_deployment_cleanup_instances();
 
-XBT_PRIVATE void smpi_comm_copy_buffer_callback(smx_activity_t comm, void* buff, size_t buff_size);
+XBT_PRIVATE void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
+                                                size_t buff_size);
 
-XBT_PRIVATE void smpi_comm_null_copy_buffer_callback(smx_activity_t comm, void* buff, size_t buff_size);
+XBT_PRIVATE void smpi_comm_null_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
+                                                     size_t buff_size);
 
 XBT_PRIVATE int smpi_enabled();
 XBT_PRIVATE void smpi_global_init();
index c8253ee..61f16b1 100644 (file)
@@ -102,7 +102,8 @@ static const std::string smpi_default_instance_name("smpirun");
 static simgrid::config::Flag<double> smpi_init_sleep(
   "smpi/init", "Time to inject inside a call to MPI_Init", 0.0);
 
-void (*smpi_comm_copy_data_callback) (smx_activity_t, void*, size_t) = &smpi_comm_copy_buffer_callback;
+void (*smpi_comm_copy_data_callback)(simgrid::kernel::activity::CommImpl*, void*,
+                                     size_t) = &smpi_comm_copy_buffer_callback;
 
 int smpi_process_count()
 {
@@ -151,7 +152,11 @@ int smpi_global_size()
 
 void smpi_comm_set_copy_data_callback(void (*callback) (smx_activity_t, void*, size_t))
 {
-  smpi_comm_copy_data_callback = callback;
+  static void (*saved_callback)(smx_activity_t, void*, size_t);
+  saved_callback               = callback;
+  smpi_comm_copy_data_callback = [](simgrid::kernel::activity::CommImpl* comm, void* buff, size_t size) {
+    saved_callback(smx_activity_t(comm), buff, size);
+  };
 }
 
 static void memcpy_private(void* dest, const void* src, std::vector<std::pair<size_t, size_t>>& private_blocks)
@@ -165,10 +170,8 @@ static void check_blocks(std::vector<std::pair<size_t, size_t>> &private_blocks,
     xbt_assert(block.first <= block.second && block.second <= buff_size, "Oops, bug in shared malloc.");
 }
 
-void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t buff_size)
+void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
 {
-  simgrid::kernel::activity::CommImplPtr comm =
-      boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro);
   int src_shared                        = 0;
   int dst_shared                        = 0;
   size_t src_offset                     = 0;
@@ -227,7 +230,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b
     xbt_free(tmpbuff);
 }
 
-void smpi_comm_null_copy_buffer_callback(smx_activity_t comm, void *buff, size_t buff_size)
+void smpi_comm_null_copy_buffer_callback(simgrid::kernel::activity::CommImpl*, void*, size_t)
 {
   /* nothing done in this version */
 }
index f0f5184..f93d5f1 100644 (file)
@@ -30,7 +30,7 @@ static simgrid::config::Flag<double> smpi_test_sleep(
 
 std::vector<s_smpi_factor_t> smpi_ois_values;
 
-extern void (*smpi_comm_copy_data_callback) (smx_activity_t, void*, size_t);
+extern void (*smpi_comm_copy_data_callback)(simgrid::kernel::activity::CommImpl*, void*, size_t);
 
 namespace simgrid{
 namespace smpi{