Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion src/mpi/orbit_mpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,31 @@ static std::size_t ORBIT_MPI_Type_size(MPI_Datatype data) {
}
#endif

#if USE_MPI > 0
// MPI_Finalize hook for Py_AtExit to propagate error codes.
static void ORBIT_MPI_Finalize_AtExit() {
int initialized = 0;
if (MPI_Initialized(&initialized) != MPI_SUCCESS || !initialized) {
return;
}

int finalized = 0;
if (MPI_Finalized(&finalized) != MPI_SUCCESS || finalized) {
return;
}

MPI_Finalize();
}
#endif

/** A C wrapper around MPI_Init. */
int ORBIT_MPI_Init(){
#if USE_MPI > 0
// Ignoring result; if it fails, the proc is doomed anyway.
MPI_Init(NULL, NULL);

// Registering MPI finalize method at cleanup stage
Py_AtExit(ORBIT_MPI_Finalize);
Py_AtExit(ORBIT_MPI_Finalize_AtExit);
#endif
return MPI_SUCCESS;
}
Expand Down Expand Up @@ -561,6 +578,39 @@ int ORBIT_MPI_Allreduce(void* ar1, void* ar2, int n, MPI_Datatype data, MPI_Op o
#endif
}

int ORBIT_MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
#if USE_MPI > 0
return MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
#else
if (sendbuf == ORBIT_MPI_IN_PLACE || sendbuf == recvbuf) {
return MPI_SUCCESS;
}

if (sendcount > 0) {
std::memcpy(recvbuf, sendbuf, static_cast<std::size_t>(sendcount) * ORBIT_MPI_Type_size(sendtype));
}

return MPI_SUCCESS;
#endif
}

int ORBIT_MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) {
#if USE_MPI > 0
return MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
#else
if (sendbuf == ORBIT_MPI_IN_PLACE || sendbuf == recvbuf) {
return MPI_SUCCESS;
}

if (sendcount > 0) {
std::memcpy(recvbuf, sendbuf, static_cast<std::size_t>(sendcount) * ORBIT_MPI_Type_size(sendtype));
}
return MPI_SUCCESS;
#endif
}

/** A C wrapper around MPI_Bcast. */
int ORBIT_MPI_Bcast(void* ar, int n1, MPI_Datatype data, int n2, MPI_Comm comm ){
int res = 0;
Expand Down
8 changes: 6 additions & 2 deletions src/mpi/orbit_mpi.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Python.h"
#include <Python.h>

#ifndef ORBIT_MPI_INCLUDE
#define ORBIT_MPI_INCLUDE
Expand All @@ -8,7 +8,7 @@
#endif

#if USE_MPI > 0
#include "mpi.h"
#include <mpi.h>
#define ORBIT_MPI_IN_PLACE MPI_IN_PLACE
#else
//---------------------------------------------------------------
Expand Down Expand Up @@ -210,6 +210,10 @@ int ORBIT_MPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int *ne
int ORBIT_MPI_Barrier(MPI_Comm comm);
int ORBIT_MPI_Wait(MPI_Request *request, MPI_Status *status);
int ORBIT_MPI_Allreduce(void* buf_in, void* buf_out, int count, MPI_Datatype, MPI_Op, MPI_Comm);
int ORBIT_MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm);
int ORBIT_MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm);
int ORBIT_MPI_Bcast(void* buf, int count, MPI_Datatype, int rank, MPI_Comm);
int ORBIT_MPI_Send(void* buf, int count, MPI_Datatype, int dest, int tag, MPI_Comm);
int ORBIT_MPI_Recv(void* buf, int count, MPI_Datatype, int source, int tag, MPI_Comm, MPI_Status *);
Expand Down
Loading