35#ifdef NEKTAR_USING_PETSC
53 MPI_Initialized(&init);
57 int thread_support = 0;
58 if (MPI_Init_thread(&narg, &arg, MPI_THREAD_MULTIPLE,
59 &thread_support) != MPI_SUCCESS)
63 "Initializing MPI using MPI_Init, if scotch version > 6 and is "
64 "compiled with multi-threading, it might cause deadlocks.")
65 ASSERTL0(MPI_Init(&narg, &arg) == MPI_SUCCESS,
66 "Failed to initialise MPI");
82#ifdef NEKTAR_USING_PETSC
83 PetscInitializeNoArguments();
107 MPI_Finalized(&flag);
108 if (!flag &&
m_comm != MPI_COMM_WORLD)
127#ifdef NEKTAR_USING_PETSC
131 MPI_Finalized(&flag);
167 int version, subversion;
168 int retval = MPI_Get_version(&version, &subversion);
170 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing GetVersion.");
172 return std::make_tuple(version, subversion, 0);
198 MPI_Ssend(buf, count, dt, dest, 0,
m_comm);
202 MPI_Send(buf, count, dt, dest, 0,
m_comm);
211 MPI_Recv(buf, count, dt, source, 0,
m_comm, MPI_STATUS_IGNORE);
222 int retval = MPI_Sendrecv(sendbuf, sendcount, sendtype, dest, 0, recvbuf,
223 recvcount, recvtype, source, 0,
m_comm, &status);
226 "MPI error performing send-receive of data.");
254 int retval = MPI_Allreduce(MPI_IN_PLACE, buf, count, dt, vOp,
m_comm);
256 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-reduce.");
266 int retval = MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount,
269 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All.");
277 void *recvbuf,
const int *recvcounts,
281 MPI_Alltoallv(sendbuf, sendcounts, senddispls, sendtype, recvbuf,
282 recvcounts, recvdispls, recvtype,
m_comm);
284 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All-v.");
294 int retval = MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
297 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgather.");
305 const int *recvcounts,
const int *recvdispls,
308 int retval = MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf,
309 recvcounts, recvdispls, recvtype,
m_comm);
311 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgatherv.");
320 int retval = MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, recvbuf,
321 recvcounts, recvdispls, recvtype,
m_comm);
323 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgatherv.");
331 int retval = MPI_Bcast(buffer, count, dt, root,
m_comm);
333 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Bcast-v.");
343 int retval = MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
346 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Gather.");
356 int retval = MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
359 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Scatter.");
366 [[maybe_unused]]
int indegree, [[maybe_unused]]
const int *sources,
367 [[maybe_unused]]
const int *sourceweights, [[maybe_unused]]
int reorder)
370 ASSERTL0(
false,
"MPI_Dist_graph_create_adjacent is not supported in your "
371 "installed MPI version.");
373 int retval = MPI_Dist_graph_create_adjacent(
374 m_comm, indegree, sources, sourceweights, indegree, sources,
375 sourceweights, MPI_INFO_NULL, reorder, &
m_comm);
378 "MPI error performing Dist_graph_create_adjacent.")
386 [[maybe_unused]]
const int *sendcounts,
387 [[maybe_unused]]
const int *senddispls,
389 [[maybe_unused]]
void *recvbuf,
390 [[maybe_unused]]
const int *recvcounts,
391 [[maybe_unused]]
const int *recvdispls,
395 ASSERTL0(
false,
"MPI_Neighbor_alltoallv is not supported in your "
396 "installed MPI version.");
398 int retval = MPI_Neighbor_alltoallv(sendbuf, sendcounts, senddispls,
399 sendtype, recvbuf, recvcounts,
400 recvdispls, recvtype,
m_comm);
402 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing NeighborAllToAllV.");
413 std::static_pointer_cast<CommRequestMpi>(request);
414 MPI_Irsend(buf, count, dt, dest, 0,
m_comm, req->GetRequest(loc));
424 std::static_pointer_cast<CommRequestMpi>(request);
425 MPI_Isend(buf, count, dt, dest, 0,
m_comm, req->GetRequest(loc));
435 std::static_pointer_cast<CommRequestMpi>(request);
436 MPI_Send_init(buf, count, dt, dest, 0,
m_comm, req->GetRequest(loc));
446 std::static_pointer_cast<CommRequestMpi>(request);
447 MPI_Irecv(buf, count, dt, source, 0,
m_comm, req->GetRequest(loc));
457 std::static_pointer_cast<CommRequestMpi>(request);
458 MPI_Recv_init(buf, count, dt, source, 0,
m_comm, req->GetRequest(loc));
467 std::static_pointer_cast<CommRequestMpi>(request);
468 if (req->GetNumRequest() != 0)
470 MPI_Startall(req->GetNumRequest(), req->GetRequest(0));
480 std::static_pointer_cast<CommRequestMpi>(request);
481 if (req->GetNumRequest() != 0)
483 MPI_Waitall(req->GetNumRequest(), req->GetRequest(0),
484 MPI_STATUSES_IGNORE);
507 "Rows/Columns do not match comm size.");
512 int myCol =
m_rank % pColumns;
513 int myRow = (
m_rank - myCol) / pColumns;
518 MPI_Comm_split(
m_comm, myRow, myCol, &newComm);
524 MPI_Comm_split(
m_comm, myCol, myRow, &newComm);
530 "Rows/Columns/Time do not match comm size.");
535 int mySpace =
m_rank % (pRows * pColumns);
536 int myTime = (
m_rank - mySpace) / (pRows * pColumns);
537 int myCol = mySpace % pColumns;
538 int myRow = (mySpace - myCol) / pColumns;
543 MPI_Comm_split(
m_comm, mySpace, myTime, &newComm);
549 MPI_Comm_split(
m_comm, myTime, mySpace, &newComm);
555 MPI_Comm_split(
m_comm, myRow + pRows * pColumns * myTime, myCol,
562 MPI_Comm_split(
m_comm, myCol + pRows * pColumns * myTime, myRow,
577 MPI_Comm_split(
m_comm, flag ? flag : MPI_UNDEFINED, 0, &newComm);
582 return std::shared_ptr<Comm>();
587 return std::shared_ptr<Comm>(
new CommMpi(newComm));
596 std::pair<CommSharedPtr, CommSharedPtr> ret;
599 ASSERTL0(
false,
"Not implemented for non-MPI-3 versions.");
603 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED,
m_rank,
604 MPI_INFO_NULL, &nodeComm);
608 ret.first = std::shared_ptr<Comm>(
new CommMpi(nodeComm));
610 if (ret.first->GetRank() == 0)
612 ret.second->SplitComm(1, ret.second->GetSize());
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Base communications class.
CommSharedPtr m_commColumn
Column communicator.
CommSharedPtr m_commRow
Row communicator.
int GetSize() const
Returns number of processes.
int m_size
Number of processes.
std::string m_type
Type of communication.
CommSharedPtr m_commSpace
void v_WaitAll(CommRequestSharedPtr request) final
void v_Gather(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
void v_SendInit(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
CommRequestSharedPtr v_CreateRequest(int num) final
CommMpi(int narg, char *arg[])
void v_AllGather(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
void v_Isend(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
void v_Bcast(void *buffer, int count, CommDataType dt, int root) final
void v_Scatter(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
void v_AllGatherv(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
CommSharedPtr v_CommCreateIf(int flag) final
void v_Send(const void *buf, int count, CommDataType dt, int dest) final
std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode() final
void v_SendRecv(const void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
void v_NeighborAlltoAllv(const void *sendbuf, const int *sendcounts, const int *senddispls, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
void v_AlltoAllv(const void *sendbuf, const int *sendcounts, const int *senddispls, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
void v_Recv(void *buf, int count, CommDataType dt, int source) final
void v_StartAll(CommRequestSharedPtr request) final
void v_Irsend(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
void v_DistGraphCreateAdjacent(int indegree, const int *sources, const int *sourceweights, int reorder) final
void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
void v_Finalise() override
void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
static std::string className
Name of class.
void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
bool v_TreatAsRankZero() final
void v_AlltoAll(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
void v_SplitComm(int pRows, int pColumns, int pTime) override
std::tuple< int, int, int > v_GetVersion() final
Class for communicator request type.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
unsigned int CommDataType
std::shared_ptr< CommRequest > CommRequestSharedPtr
std::shared_ptr< CommRequestMpi > CommRequestMpiSharedPtr
CommFactory & GetCommFactory()
ReduceOperator
Type of operation to perform in AllReduce.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.