35#ifdef NEKTAR_USING_PETSC
55 MPI_Initialized(&init);
59 ASSERTL0(MPI_Init(&narg, &arg) == MPI_SUCCESS,
60 "Failed to initialise MPI");
75#ifdef NEKTAR_USING_PETSC
76 PetscInitializeNoArguments();
100 MPI_Finalized(&flag);
101 if (!flag &&
m_comm != MPI_COMM_WORLD)
120#ifdef NEKTAR_USING_PETSC
124 MPI_Finalized(&flag);
160 int version, subversion;
161 int retval = MPI_Get_version(&version, &subversion);
163 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing GetVersion.");
165 return std::make_tuple(version, subversion, 0);
191 MPI_Ssend(buf, count, dt, dest, 0,
m_comm);
195 MPI_Send(buf, count, dt, dest, 0,
m_comm);
204 MPI_Recv(buf, count, dt, source, 0,
m_comm, MPI_STATUS_IGNORE);
211 int dest,
void *recvbuf,
int recvcount,
215 int retval = MPI_Sendrecv(sendbuf, sendcount, sendtype, dest, 0, recvbuf,
216 recvcount, recvtype, source, 0,
m_comm, &status);
219 "MPI error performing send-receive of data.");
247 int retval = MPI_Allreduce(MPI_IN_PLACE, buf, count, dt, vOp,
m_comm);
249 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-reduce.");
258 int retval = MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount,
261 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All.");
269 int recvcounts[],
int rdispls[],
272 int retval = MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
273 recvcounts, rdispls, recvtype,
m_comm);
275 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All-v.");
284 int retval = MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
287 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgather.");
294 void *recvbuf,
int recvcounts[],
int rdispls[],
297 int retval = MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf,
298 recvcounts, rdispls, recvtype,
m_comm);
300 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgatherv.");
309 int retval = MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, recvbuf,
310 recvcounts, rdispls, recvtype,
m_comm);
312 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgatherv.");
320 int retval = MPI_Bcast(
buffer, count, dt, root,
m_comm);
322 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Bcast-v.");
332 int retval = MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
335 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Gather.");
345 int retval = MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
348 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Scatter.");
355 const int sourceweights[],
int reorder)
358 boost::ignore_unused(indegree, sources, sourceweights, reorder);
360 ASSERTL0(
false,
"MPI_Dist_graph_create_adjacent is not supported in your "
361 "installed MPI version.");
363 int retval = MPI_Dist_graph_create_adjacent(
364 m_comm, indegree, sources, sourceweights, indegree, sources,
365 sourceweights, MPI_INFO_NULL, reorder, &
m_comm);
368 "MPI error performing Dist_graph_create_adjacent.")
377 void *recvbuf,
int recvcounts[],
381 boost::ignore_unused(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
382 recvcounts, rdispls, recvtype);
383 ASSERTL0(
false,
"MPI_Neighbor_alltoallv is not supported in your "
384 "installed MPI version.");
387 MPI_Neighbor_alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
388 recvcounts, rdispls, recvtype,
m_comm);
390 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing NeighborAllToAllV.");
401 std::static_pointer_cast<CommRequestMpi>(request);
402 MPI_Irsend(buf, count, dt, dest, 0,
m_comm, req->GetRequest(
loc));
412 std::static_pointer_cast<CommRequestMpi>(request);
413 MPI_Isend(buf, count, dt, dest, 0,
m_comm, req->GetRequest(
loc));
423 std::static_pointer_cast<CommRequestMpi>(request);
424 MPI_Send_init(buf, count, dt, dest, 0,
m_comm, req->GetRequest(
loc));
434 std::static_pointer_cast<CommRequestMpi>(request);
435 MPI_Irecv(buf, count, dt, source, 0,
m_comm, req->GetRequest(
loc));
445 std::static_pointer_cast<CommRequestMpi>(request);
446 MPI_Recv_init(buf, count, dt, source, 0,
m_comm, req->GetRequest(
loc));
455 std::static_pointer_cast<CommRequestMpi>(request);
456 if (req->GetNumRequest() != 0)
458 MPI_Startall(req->GetNumRequest(), req->GetRequest(0));
468 std::static_pointer_cast<CommRequestMpi>(request);
469 if (req->GetNumRequest() != 0)
471 MPI_Waitall(req->GetNumRequest(), req->GetRequest(0),
472 MPI_STATUSES_IGNORE);
493 "Rows/Columns/Time do not match comm size.");
508 int myCol =
m_rank % pColumns;
509 int myRow = (
m_rank - myCol) / pColumns;
514 MPI_Comm_split(
m_comm, myRow, myCol, &newComm);
520 MPI_Comm_split(
m_comm, myCol, myRow, &newComm);
525 constexpr int dims = 3;
526 const int sizes[dims] = {pRows, pColumns, pTime};
527 const int periods[dims] = {0, 0, 0};
528 constexpr int reorder = 1;
530 MPI_Cart_create(
m_comm, dims, sizes, periods, reorder, &gridComm);
532 constexpr int keepRow[dims] = {0, 1, 0};
533 MPI_Cart_sub(gridComm, keepRow, &newComm);
536 constexpr int keepCol[dims] = {1, 0, 0};
537 MPI_Cart_sub(gridComm, keepCol, &newComm);
540 constexpr int keepTime[dims] = {0, 0, 1};
541 MPI_Cart_sub(gridComm, keepTime, &newComm);
544 constexpr int keepSpace[dims] = {1, 1, 0};
545 MPI_Cart_sub(gridComm, keepSpace, &newComm);
559 MPI_Comm_split(
m_comm, flag ? flag : MPI_UNDEFINED, 0, &newComm);
564 return std::shared_ptr<Comm>();
569 return std::shared_ptr<Comm>(
new CommMpi(newComm));
578 std::pair<CommSharedPtr, CommSharedPtr> ret;
581 ASSERTL0(
false,
"Not implemented for non-MPI-3 versions.");
585 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED,
m_rank,
586 MPI_INFO_NULL, &nodeComm);
590 ret.first = std::shared_ptr<Comm>(
new CommMpi(nodeComm));
592 if (ret.first->GetRank() == 0)
594 ret.second->SplitComm(1, ret.second->GetSize());
#define ASSERTL0(condition, msg)
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
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) override final
virtual void v_WaitAll(CommRequestSharedPtr request) override final
CommMpi(int narg, char *arg[])
virtual std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode() override final
virtual void v_Isend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) override final
virtual std::tuple< int, int, int > v_GetVersion() override final
virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[], const int sourceweights[], int reorder) override final
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) override final
virtual CommSharedPtr v_CommCreateIf(int flag) override final
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) override final
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) override final
virtual bool v_TreatAsRankZero() override final
virtual void v_Send(void *buf, int count, CommDataType dt, int dest) override final
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) override final
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) override final
virtual void v_Finalise() override
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) override final
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) override final
virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) override final
virtual CommRequestSharedPtr v_CreateRequest(int num) override final
virtual int v_GetRank() override final
static std::string className
Name of class.
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
virtual double v_Wtime() override final
virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) override final
virtual void v_Block() override final
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root) override final
virtual void v_StartAll(CommRequestSharedPtr request) override final
virtual void v_SplitComm(int pRows, int pColumns, int pTime) override
virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) override final
virtual ~CommMpi() override
virtual void v_Recv(void *buf, int count, CommDataType dt, int source) override final
virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) override final
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) override final
virtual bool v_IsSerial() override 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.
The above copyright notice and this permission notice shall be included.