35 #ifdef NEKTAR_USING_PETSC
44 namespace LibUtilities
56 MPI_Initialized(&init);
60 ASSERTL0(MPI_Init(&narg, &arg) == MPI_SUCCESS,
61 "Failed to initialise MPI");
76 #ifdef NEKTAR_USING_PETSC
77 PetscInitializeNoArguments();
101 MPI_Finalized(&flag);
102 if (!flag &&
m_comm != MPI_COMM_WORLD)
121 #ifdef NEKTAR_USING_PETSC
125 MPI_Finalized(&flag);
158 int version, subversion;
159 int retval = MPI_Get_version(&version, &subversion);
161 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing GetVersion.");
163 return std::make_tuple(version, subversion, 0);
189 MPI_Ssend(buf, count, dt, dest, 0,
m_comm);
193 MPI_Send(buf, count, dt, dest, 0,
m_comm);
202 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.");
226 int pSendProc,
int pRecvProc)
229 int retval = MPI_Sendrecv_replace(buf, count, dt, pRecvProc, 0, pSendProc,
233 "MPI error performing Send-Receive-Replace of data.");
261 int retval = MPI_Allreduce(MPI_IN_PLACE, buf, count, dt, vOp,
m_comm);
263 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-reduce.");
272 int retval = MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount,
275 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All.");
283 int recvcounts[],
int rdispls[],
286 int retval = MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
287 recvcounts, rdispls, recvtype,
m_comm);
289 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All-v.");
298 int retval = MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
301 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgather.");
305 void *recvbuf,
int recvcounts[],
int rdispls[],
308 int retval = MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf,
309 recvcounts, rdispls, recvtype,
m_comm);
311 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgather.");
317 int retval = MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, recvbuf,
318 recvcounts, rdispls, recvtype,
m_comm);
320 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgatherv.");
325 int retval = MPI_Bcast(
buffer, count, dt, root,
m_comm);
326 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Bcast-v.");
333 int n = pData.size();
334 ASSERTL0(n == ans.size(),
"Array sizes differ in Exscan");
353 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Exscan-v.");
360 int retval = MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
363 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Gather.");
370 int retval = MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
372 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Scatter.");
376 const int sourceweights[],
int reorder)
379 boost::ignore_unused(indegree, sources, sourceweights, reorder);
380 ASSERTL0(
false,
"MPI_Dist_graph_create_adjacent is not supported in your "
381 "installed MPI version.");
383 int retval = MPI_Dist_graph_create_adjacent(
384 m_comm, indegree, sources, sourceweights, indegree, sources,
385 sourceweights, MPI_INFO_NULL, reorder, &
m_comm);
388 "MPI error performing Dist_graph_create_adjacent.")
394 void *recvbuf,
int recvcounts[],
398 boost::ignore_unused(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
399 recvcounts, rdispls, recvtype);
400 ASSERTL0(
false,
"MPI_Neighbor_alltoallv is not supported in your "
401 "installed MPI version.");
404 MPI_Neighbor_alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
405 recvcounts, rdispls, recvtype,
m_comm);
407 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing NeighborAllToAllV.");
415 std::static_pointer_cast<CommRequestMpi>(request);
416 MPI_Irsend(buf, count, dt, dest, 0,
m_comm, req->GetRequest(
loc));
423 std::static_pointer_cast<CommRequestMpi>(request);
424 MPI_Isend(buf, count, dt, dest, 0,
m_comm, req->GetRequest(
loc));
431 std::static_pointer_cast<CommRequestMpi>(request);
432 MPI_Send_init(buf, count, dt, dest, 0,
m_comm, req->GetRequest(
loc));
439 std::static_pointer_cast<CommRequestMpi>(request);
440 MPI_Irecv(buf, count, dt, source, 0,
m_comm, req->GetRequest(
loc));
447 std::static_pointer_cast<CommRequestMpi>(request);
448 MPI_Recv_init(buf, count, dt, source, 0,
m_comm, req->GetRequest(
loc));
454 std::static_pointer_cast<CommRequestMpi>(request);
455 if (req->GetNumRequest() != 0)
457 MPI_Startall(req->GetNumRequest(), req->GetRequest(0));
464 std::static_pointer_cast<CommRequestMpi>(request);
465 if (req->GetNumRequest() != 0)
467 MPI_Waitall(req->GetNumRequest(), req->GetRequest(0),
468 MPI_STATUSES_IGNORE);
486 "Rows/Columns do not match comm size.");
501 int myCol =
m_rank % pColumns;
502 int myRow = (
m_rank - myCol) / pColumns;
507 MPI_Comm_split(
m_comm, myRow, myCol, &newComm);
513 MPI_Comm_split(
m_comm, myCol, myRow, &newComm);
518 constexpr
int dims = 3;
519 const int sizes[dims] = {pRows, pColumns, pTime};
520 const int periods[dims] = {0, 0, 0};
521 constexpr
int reorder = 1;
523 MPI_Cart_create(
m_comm, dims, sizes, periods, reorder, &gridComm);
525 constexpr
int keepRow[dims] = {0, 1, 0};
526 MPI_Cart_sub(gridComm, keepRow, &newComm);
529 constexpr
int keepCol[dims] = {1, 0, 0};
530 MPI_Cart_sub(gridComm, keepCol, &newComm);
533 constexpr
int keepTime[dims] = {0, 0, 1};
534 MPI_Cart_sub(gridComm, keepTime, &newComm);
537 constexpr
int keepSpace[dims] = {1, 1, 0};
538 MPI_Cart_sub(gridComm, keepSpace, &newComm);
552 MPI_Comm_split(
m_comm, flag ? flag : MPI_UNDEFINED, 0, &newComm);
557 return std::shared_ptr<Comm>();
562 return std::shared_ptr<Comm>(
new CommMpi(newComm));
568 std::pair<CommSharedPtr, CommSharedPtr> ret;
571 ASSERTL0(
false,
"Not implemented for non-MPI-3 versions.");
575 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED,
m_rank,
576 MPI_INFO_NULL, &nodeComm);
580 ret.first = std::shared_ptr<Comm>(
new CommMpi(nodeComm));
582 if (ret.first->GetRank() == 0)
584 ret.second->SplitComm(1, ret.second->GetSize());
#define MPI_UNSIGNED_LONG_LONG
#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_Exscan(Array< OneD, unsigned long long > &pData, enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans) 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_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc) 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.