34 #ifndef NEKTAR_LIB_UTILITIES_COMM_H
35 #define NEKTAR_LIB_UTILITIES_COMM_H
39 #include <type_traits>
50 namespace LibUtilities
81 class Comm :
public std::enable_shared_from_this<Comm>
100 template <
class T>
void Send(
int pProc, T &pData);
101 template <
class T>
void Recv(
int pProc, T &pData);
103 void SendRecv(
int pSendProc, T &pSendData,
int pRecvProc, T &pRecvData);
109 template <
class T>
void AlltoAll(T &pSendData, T &pRecvData);
110 template <
class T1,
class T2>
112 T2 &pSendDataSizeMap,
113 T2 &pSendDataOffsetMap,
115 T2 &pRecvDataSizeMap,
116 T2 &pRecvDataOffsetMap);
118 template <
class T>
void AllGather(T &pSendData, T &pRecvData);
129 template <
class T>
void Bcast(T &data,
int rootProc);
134 template <
class T> T
Gather(
const int rootProc, T &val);
135 template <
class T> T
Scatter(
const int rootProc, T &pData);
162 int dest,
void *recvbuf,
int recvcount,
165 int pSendProc,
int pRecvProc) = 0;
169 void *recvbuf,
int recvcount,
171 virtual void v_AlltoAllv(
void *sendbuf,
int sendcounts[],
int sensdispls[],
173 int recvcounts[],
int rdispls[],
176 void *recvbuf,
int recvcount,
179 void *recvbuf,
int recvcounts[],
int rdispls[],
181 virtual void v_AllGatherv(
void *recvbuf,
int recvcounts[],
int rdispls[],
306 "AlltoAll only valid with Array or vector arguments.");
310 "Send and Recv arrays have incompatible sizes in AlltoAll");
312 int count = sendSize /
GetSize();
314 "Array size incompatible with size of communicator");
325 template <
class T1,
class T2>
327 T2 &pSendDataSizeMap,
328 T2 &pSendDataOffsetMap,
330 T2 &pRecvDataSizeMap,
331 T2 &pRecvDataOffsetMap)
335 "AlltoAllv only valid with Array or vector arguments.");
337 std::is_same<T2, std::vector<int>>::value ||
339 "Alltoallv size and offset maps should be integer vectors.");
353 BOOST_STATIC_ASSERT_MSG(
355 "AllGather only valid with Array or vector arguments.");
358 int recvSize = sendSize;
360 pRecvData = T(recvSize *
GetSize());
377 BOOST_STATIC_ASSERT_MSG(
379 "AllGatherv only valid with Array or vector arguments.");
386 pRecvDataSizeMap.get(),
387 pRecvDataOffsetMap.get(),
399 BOOST_STATIC_ASSERT_MSG(
401 "AllGatherv only valid with Array or vector arguments.");
404 pRecvDataSizeMap.get(),
405 pRecvDataOffsetMap.get(),
424 "Input and output array sizes don't match");
439 "Gather only valid with Array or vector arguments.");
440 bool amRoot = (
GetRank() == rootProc);
443 unsigned nOut = amRoot ?
GetSize() * nEl : 0;
459 "Scatter only valid with Array or vector arguments.");
461 bool amRoot = (
GetRank() == rootProc);
498 return shared_from_this();
514 return shared_from_this();
#define ASSERTL0(condition, msg)
#define LIB_UTILITIES_EXPORT
static void * GetPointer(T &val)
static int GetCount(const T &val)
Base communications class.
void SendRecv(int pSendProc, T &pSendData, int pRecvProc, T &pRecvData)
void AllGather(T &pSendData, T &pRecvData)
virtual CommSharedPtr v_CommCreateIf(int flag)=0
void AlltoAll(T &pSendData, T &pRecvData)
CommSharedPtr m_commColumn
Column communicator.
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
CommSharedPtr CommCreateIf(int flag)
If the flag is non-zero create a new communicator.
CommSharedPtr GetColumnComm()
Retrieve the column communicator to which this process belongs.
void Block()
Block execution until all processes reach this point.
CommSharedPtr GetRowComm()
Retrieve the row communicator to which this process belongs.
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, const enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans)=0
NekDouble Wtime()
Return the time in seconds.
virtual bool v_IsSerial(void)=0
virtual bool v_RemoveExistingFiles(void)
CommSharedPtr m_commRow
Row communicator.
virtual bool v_TreatAsRankZero(void)=0
const std::string & GetType() const
void SendRecvReplace(int pSendProc, int pRecvProc, T &pData)
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source)=0
bool TreatAsRankZero(void)
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)=0
T Scatter(const int rootProc, T &pData)
virtual void v_Recv(void *buf, int count, CommDataType dt, int source)=0
virtual void v_Send(void *buf, int count, CommDataType dt, int dest)=0
virtual int v_GetRank()=0
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)=0
void AllGatherv(T &pSendData, T &pRecvData, Array< OneD, int > &pRecvDataSizeMap, Array< OneD, int > &pRecvDataOffsetMap)
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc)=0
void Bcast(T &data, int rootProc)
void Send(int pProc, T &pData)
int m_size
Number of processes.
std::string m_type
Type of communication.
void Recv(int pProc, T &pData)
T Gather(const int rootProc, T &val)
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp)=0
virtual NekDouble v_Wtime()=0
void AllReduce(T &pData, enum ReduceOperator pOp)
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
int GetSize()
Returns number of processes.
virtual void v_Finalise()=0
void AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
void Exscan(T &pData, const enum ReduceOperator pOp, T &ans)
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root)=0
void SplitComm(int pRows, int pColumns)
Splits this communicator into a grid of size pRows*pColumns and creates row and column communicators....
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
virtual void v_SplitComm(int pRows, int pColumns)=0
bool RemoveExistingFiles(void)
virtual void v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
Provides a generic Factory class.
LibUtilities::NekFactory< std::string, Comm, int, char ** > CommFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class.
const char *const ReduceOperatorMap[]
CommFactory & GetCommFactory()
ReduceOperator
Type of operation to perform in AllReduce.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.