35 #ifdef NEKTAR_USING_PETSC
44 namespace LibUtilities
56 MPI_Initialized(&init);
57 ASSERTL0(!init,
"MPI has already been initialised.");
59 int retval = MPI_Init(&narg, &arg);
60 if (retval != MPI_SUCCESS)
62 ASSERTL0(
false,
"Failed to initialise MPI");
69 #ifdef NEKTAR_USING_PETSC
70 PetscInitializeNoArguments();
95 if (!flag &&
m_comm != MPI_COMM_WORLD)
114 #ifdef NEKTAR_USING_PETSC
118 MPI_Finalized(&flag);
151 int version, subversion;
152 int retval = MPI_Get_version(&version, &subversion);
154 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing GetVersion.");
156 return std::make_tuple(version, subversion, 0);
182 MPI_Ssend(buf, count, dt, dest, 0,
m_comm);
186 MPI_Send(buf, count, dt, dest, 0,
m_comm);
195 MPI_Recv(buf, count, dt, source, 0,
m_comm, MPI_STATUS_IGNORE);
204 int dest,
void *recvbuf,
int recvcount,
208 int retval = MPI_Sendrecv(sendbuf, sendcount, sendtype, dest, 0, recvbuf,
209 recvcount, recvtype, source, 0,
m_comm, &status);
212 "MPI error performing send-receive of data.");
219 int pSendProc,
int pRecvProc)
222 int retval = MPI_Sendrecv_replace(buf, count, dt, pRecvProc, 0, pSendProc,
226 "MPI error performing Send-Receive-Replace 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.");
265 int retval = MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount,
268 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All.");
276 int recvcounts[],
int rdispls[],
279 int retval = MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
280 recvcounts, rdispls, recvtype,
m_comm);
282 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All-v.");
291 int retval = MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
294 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgather.");
298 void *recvbuf,
int recvcounts[],
int rdispls[],
301 int retval = MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf,
302 recvcounts, rdispls, recvtype,
m_comm);
304 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgather.");
310 int retval = MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, recvbuf,
311 recvcounts, rdispls, recvtype,
m_comm);
313 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgatherv.");
318 int retval = MPI_Bcast(
buffer, count, dt, root,
m_comm);
319 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Bcast-v.");
326 int n = pData.size();
327 ASSERTL0(n == ans.size(),
"Array sizes differ in Exscan");
346 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Exscan-v.");
353 int retval = MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
356 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Gather.");
363 int retval = MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
365 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Scatter.");
369 const int sourceweights[],
int reorder)
372 boost::ignore_unused(indegree, sources, sourceweights, reorder);
373 ASSERTL0(
false,
"MPI_Dist_graph_create_adjacent is not supported in your "
374 "installed MPI version.");
376 int retval = MPI_Dist_graph_create_adjacent(
377 m_comm, indegree, sources, sourceweights, indegree, sources,
378 sourceweights, MPI_INFO_NULL, reorder, &
m_comm);
381 "MPI error performing Dist_graph_create_adjacent.")
387 void *recvbuf,
int recvcounts[],
391 boost::ignore_unused(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
392 recvcounts, rdispls, recvtype);
393 ASSERTL0(
false,
"MPI_Neighbor_alltoallv is not supported in your "
394 "installed MPI version.");
397 MPI_Neighbor_alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
398 recvcounts, rdispls, recvtype,
m_comm);
400 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing NeighborAllToAllV.");
408 std::static_pointer_cast<CommRequestMpi>(request);
409 MPI_Irsend(buf, count, dt, dest, 0,
m_comm, req->GetRequest(
loc));
416 std::static_pointer_cast<CommRequestMpi>(request);
417 MPI_Send_init(buf, count, dt, dest, 0,
m_comm, req->GetRequest(
loc));
424 std::static_pointer_cast<CommRequestMpi>(request);
425 MPI_Irecv(buf, count, dt, source, 0,
m_comm, req->GetRequest(
loc));
432 std::static_pointer_cast<CommRequestMpi>(request);
433 MPI_Recv_init(buf, count, dt, source, 0,
m_comm, req->GetRequest(
loc));
439 std::static_pointer_cast<CommRequestMpi>(request);
440 MPI_Startall(req->GetNumRequest(), req->GetRequest(0));
446 std::static_pointer_cast<CommRequestMpi>(request);
447 MPI_Waitall(req->GetNumRequest(), req->GetRequest(0), MPI_STATUSES_IGNORE);
464 "Rows/Columns do not match comm size.");
469 int myCol =
m_rank % pColumns;
470 int myRow = (
m_rank - myCol) / pColumns;
475 MPI_Comm_split(
m_comm, myRow, myCol, &newComm);
481 MPI_Comm_split(
m_comm, myCol, myRow, &newComm);
494 MPI_Comm_split(
m_comm, flag ? 0 : MPI_UNDEFINED, 0, &newComm);
499 return std::shared_ptr<Comm>();
504 return std::shared_ptr<Comm>(
new CommMpi(newComm));
510 std::pair<CommSharedPtr, CommSharedPtr> ret;
513 ASSERTL0(
false,
"Not implemented for non-MPI-3 versions.");
517 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED,
m_rank,
518 MPI_INFO_NULL, &nodeComm);
522 ret.first = std::shared_ptr<Comm>(
new CommMpi(nodeComm));
524 if(ret.first->GetRank() == 0)
526 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.
virtual void v_Block() final
virtual void v_WaitAll(CommRequestSharedPtr request) final
virtual bool v_IsSerial() final
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
virtual CommRequestSharedPtr v_CreateRequest(int num) final
CommMpi(int narg, char *arg[])
virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[], const int sourceweights[], int reorder) final
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root) final
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc) final
virtual CommSharedPtr v_CommCreateIf(int flag) final
virtual std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode() final
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
virtual double v_Wtime() final
virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
virtual void v_Recv(void *buf, int count, CommDataType dt, int source) final
virtual void v_StartAll(CommRequestSharedPtr request) final
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
virtual void v_Finalise() override
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
virtual int v_GetRank() final
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans) final
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
static std::string className
Name of class.
virtual 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.
virtual void v_SplitComm(int pRows, int pColumns) override
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
virtual bool v_TreatAsRankZero() final
virtual void v_Send(void *buf, int count, CommDataType dt, int dest) final
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
virtual ~CommMpi() override
virtual std::tuple< int, int, int > v_GetVersion() final
virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) 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.