From: Arnaud Giersch Date: Tue, 19 Feb 2019 13:07:49 +0000 (+0100) Subject: Use CommImpl* for comm_copy callbacks. X-Git-Tag: v3_22~299 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a146138b74c78c8e7de7294457eb0440a91a7dd9 Use CommImpl* for comm_copy callbacks. It's in fact already used for match_fun. --- diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 2aa2f0af24..7a540a975a 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -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; diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 1dac63be64..61755af002 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -153,9 +153,14 @@ XBT_PUBLIC void SIMIX_process_on_exit(smx_actor_t process, std::function(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(synchro); - xbt_assert((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)", buff_size); *(void**)(comm->dst_buff_) = buff; } diff --git a/src/kernel/activity/CommImpl.hpp b/src/kernel/activity/CommImpl.hpp index f64dc44f33..9595782c41 100644 --- a/src/kernel/activity/CommImpl.hpp +++ b/src/kernel/activity/CommImpl.hpp @@ -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 */ diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 8f3b0986f5..770bf52a84 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -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(synchro); - SIMIX_comm_copy_pointer_callback(comm, buff, buff_size); // notify the user callback if any diff --git a/src/msg/msg_private.hpp b/src/msg/msg_private.hpp index 6a4a795c74..e720eba25a 100644 --- a/src/msg/msg_private.hpp +++ b/src/msg/msg_private.hpp @@ -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 */ diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 94d37fc962..d9aa9493e7 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -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"); diff --git a/src/simix/popping_private.hpp b/src/simix/popping_private.hpp index 63422324f2..c20bd04b34 100644 --- a/src/simix/popping_private.hpp +++ b/src/simix/popping_private.hpp @@ -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 diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index 80a047a16d..1ea8e097f8 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -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(); diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index c8253eecab..61f16b1ccc 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -102,7 +102,8 @@ static const std::string smpi_default_instance_name("smpirun"); static simgrid::config::Flag 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>& private_blocks) @@ -165,10 +170,8 @@ static void check_blocks(std::vector> &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(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 */ } diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index f0f51844c2..f93d5f1d2c 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -30,7 +30,7 @@ static simgrid::config::Flag smpi_test_sleep( std::vector 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{