35 #ifdef NEKTAR_USING_PETSC 44 namespace LibUtilities
55 MPI_Initialized(&init);
56 ASSERTL0(!init,
"MPI has already been initialised.");
58 int retval = MPI_Init(&narg, &arg);
59 if (retval != MPI_SUCCESS)
61 ASSERTL0(
false,
"Failed to initialise MPI");
68 #ifdef NEKTAR_USING_PETSC 69 PetscInitializeNoArguments();
94 if (!flag &&
m_comm != MPI_COMM_WORLD)
113 #ifdef NEKTAR_USING_PETSC 117 MPI_Finalized(&flag);
186 MPI_Ssend(buf, count, dt, dest, 0,
m_comm);
190 MPI_Send(buf, count, dt, dest, 0,
m_comm);
199 MPI_Recv(buf, count, dt, source, 0,
m_comm, MPI_STATUS_IGNORE);
208 int dest,
void *recvbuf,
int recvcount,
212 int retval = MPI_Sendrecv(sendbuf, sendcount, sendtype, dest, 0, recvbuf,
213 recvcount, recvtype, source, 0,
m_comm, &status);
216 "MPI error performing send-receive of data.");
223 int pSendProc,
int pRecvProc)
226 int retval = MPI_Sendrecv_replace(buf, count, dt, pRecvProc, 0, pSendProc,
230 "MPI error performing Send-Receive-Replace of data.");
258 int retval = MPI_Allreduce(MPI_IN_PLACE, buf, count, dt, vOp,
m_comm);
260 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-reduce.");
269 int retval = MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount,
272 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All.");
280 int recvcounts[],
int rdispls[],
283 int retval = MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
284 recvcounts, rdispls, recvtype,
m_comm);
286 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing All-to-All-v.");
295 int retval = MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
298 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgather.");
302 void *recvbuf,
int recvcounts[],
int rdispls[],
305 int retval = MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf,
306 recvcounts, rdispls, recvtype,
m_comm);
308 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgather.");
314 int retval = MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, recvbuf,
315 recvcounts, rdispls, recvtype,
m_comm);
317 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Allgatherv.");
322 int retval = MPI_Bcast(buffer, count, dt, root,
m_comm);
323 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Bcast-v.");
330 int n = pData.num_elements();
331 ASSERTL0(n == ans.num_elements(),
"Array sizes differ in Exscan");
350 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Exscan-v.");
357 int retval = MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
360 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Gather.");
367 int retval = MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
369 ASSERTL0(retval == MPI_SUCCESS,
"MPI error performing Scatter.");
381 "Rows/Columns do not match comm size.");
386 int myCol =
m_rank % pColumns;
387 int myRow = (
m_rank - myCol) / pColumns;
392 MPI_Comm_split(
m_comm, myRow, myCol, &newComm);
398 MPI_Comm_split(
m_comm, myCol, myRow, &newComm);
411 MPI_Comm_split(
m_comm, flag ? 0 : MPI_UNDEFINED, 0, &newComm);
416 return std::shared_ptr<Comm>();
421 return std::shared_ptr<Comm>(
new CommMpi(newComm));
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc)
#define ASSERTL0(condition, msg)
ReduceOperator
Type of operation to perform in AllReduce.
virtual void v_Recv(void *buf, int count, CommDataType dt, int source)
virtual void v_Finalise()
CommSharedPtr m_commColumn
Column communicator.
virtual void v_Send(void *buf, int count, CommDataType dt, int dest)
std::string m_type
Type of communication.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp)
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)
CommFactory & GetCommFactory()
CommSharedPtr m_commRow
Row communicator.
virtual bool v_IsSerial(void)
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
virtual CommSharedPtr v_CommCreateIf(int flag)
virtual void v_SplitComm(int pRows, int pColumns)
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)
virtual bool v_TreatAsRankZero(void)
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)
Base communications class.
static std::string className
Name of class.
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, const enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans)
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root)
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
int GetSize()
Returns number of processes.
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)
int m_size
Number of processes.
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)