15 #ifndef CORE_MULTI_SIMULATION_MPI_HELPER_H_
16 #define CORE_MULTI_SIMULATION_MPI_HELPER_H_
25 #if (!defined(__CLING__) && !defined(__ROOTCLING__))
27 #endif // __ROOTCLING__
33 namespace experimental {
39 class MPIObject :
public TMessage {
41 MPIObject() =
default;
42 ~MPIObject()
override =
default;
43 MPIObject(
void* buf, Int_t len) : TMessage(buf, len) {}
50 #if (!defined(__CLING__) && !defined(__ROOTCLING__))
53 int MPI_Send_Obj_ROOT(T* obj,
int dest,
int tag,
54 MPI_Status* status = MPI_STATUS_IGNORE) {
56 mpio.WriteObject(obj);
57 int size = mpio.Length();
59 MPI_Send(&size, 1, MPI_INT, dest, tag, MPI_COMM_WORLD);
61 return MPI_Send(mpio.Buffer(), size, MPI_BYTE, dest, tag, MPI_COMM_WORLD);
66 T* MPI_Recv_Obj_ROOT(
int size,
int source,
int tag,
67 MPI_Status* status = MPI_STATUS_IGNORE) {
68 char* buf = (
char*)malloc(size);
70 MPI_Recv(buf, size, MPI_BYTE, source, tag, MPI_COMM_WORLD, status);
71 MPIObject* mpio =
new MPIObject(buf, size);
72 T* obj = (T*)(mpio->ReadObject(mpio->GetClass()));
77 #endif // __ROOTCLING__
84 #endif // CORE_MULTI_SIMULATION_MPI_HELPER_H_