From 7369715466314d1ab38ee29586b632717c98fcad Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Fri, 23 Jul 2021 11:25:09 +0200 Subject: [PATCH] Enable setting a specific data copy callback to any comm This is becoming mandatory if one has the silly idea to mix SMPI communications and S4U communications within the same simulation launched with smpirun. smpirun sets its own callback for ALL comms in smpi_main and thus consider that averything is a SMPI communication. If you need to trick SMPI to have S4U comms on the side, you thus have to override this callback: Sender side: mbox->put_init(payload, size) ->set_copy_data_callback(SIMIX_comm_copy_pointer_callback) ->detach(); // or start/vetoable_start/wait Receiver side: mbox->get_init() ->set_dst_data(reinterpret_cast(data), sizeof(void*)) ->set_copy_data_callback(SIMIX_comm_copy_pointer_callback) ->wait(); // or start/vetoable_start --- include/simgrid/s4u/Comm.hpp | 2 ++ src/s4u/s4u_Comm.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 0ea9de8741..1be8e564eb 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -168,6 +168,8 @@ public: Actor* get_sender() const; bool is_assigned() const override { return (to_ != nullptr && from_ != nullptr) || (mailbox_ != nullptr); } + + CommPtr set_copy_data_callback(void (*callback)(kernel::activity::CommImpl*, void*, size_t)); }; } // namespace s4u } // namespace simgrid diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index 00c6bcf9c9..36b5702cbf 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -297,6 +297,16 @@ Actor* Comm::get_sender() const return sender ? sender->get_ciface() : nullptr; } +CommPtr Comm::set_copy_data_callback(void (*callback)(kernel::activity::CommImpl*, void*, size_t)) +{ + static void (*saved_callback)(kernel::activity::CommImpl*, void*, size_t); + saved_callback = callback; + copy_data_function_ = [](simgrid::kernel::activity::CommImpl* comm, void* buff, size_t size) { + saved_callback(comm, buff, size); + }; + return this; +} + } // namespace s4u } // namespace simgrid /* **************************** Public C interface *************************** */ -- 2.20.1