Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enable setting a specific data copy callback to any comm
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Fri, 23 Jul 2021 09:25:09 +0000 (11:25 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Fri, 23 Jul 2021 09:41:34 +0000 (11:41 +0200)
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<void**>(data), sizeof(void*))
     ->set_copy_data_callback(SIMIX_comm_copy_pointer_callback)
     ->wait(); // or start/vetoable_start

include/simgrid/s4u/Comm.hpp
src/s4u/s4u_Comm.cpp

index 0ea9de8..1be8e56 100644 (file)
@@ -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
index 00c6bcf..36b5702 100644 (file)
@@ -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 *************************** */