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[],
198 virtual void v_SplitComm(
int pRows,
int pColumns) = 0;
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;
447 v_Gather(CommDataTypeTraits<T>::GetPointer(val), nEl,
459 "Scatter only valid with Array or vector arguments.");
461 bool amRoot = (
GetRank() == rootProc);
468 CommDataTypeTraits<T>::GetPointer(ans), nEl,
498 return shared_from_this();
514 return shared_from_this();
void Exscan(T &pData, const enum ReduceOperator pOp, T &ans)
void Recv(int pProc, T &pData)
void AllReduce(T &pData, enum ReduceOperator pOp)
#define ASSERTL0(condition, msg)
virtual void v_Recv(void *buf, int count, CommDataType dt, int source)=0
ReduceOperator
Type of operation to perform in AllReduce.
virtual bool v_IsSerial(void)=0
CommSharedPtr m_commColumn
Column communicator.
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)=0
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp)=0
std::string m_type
Type of communication.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
bool TreatAsRankZero(void)
void AllGatherv(T &pSendData, T &pRecvData, Array< OneD, int > &pRecvDataSizeMap, Array< OneD, int > &pRecvDataOffsetMap)
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
static int GetCount(const T &val)
virtual void v_Send(void *buf, int count, CommDataType dt, int dest)=0
CommFactory & GetCommFactory()
CommSharedPtr m_commRow
Row communicator.
void AlltoAll(T &pSendData, T &pRecvData)
void SendRecv(int pSendProc, T &pSendData, int pRecvProc, T &pRecvData)
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source)=0
virtual bool v_RemoveExistingFiles(void)
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, const enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans)=0
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root)=0
NekDouble Wtime()
Return the time in seconds.
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
CommSharedPtr GetRowComm()
Retrieve the row communicator to which this process belongs.
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
virtual CommSharedPtr v_CommCreateIf(int flag)=0
T Scatter(const int rootProc, T &pData)
LibUtilities::NekFactory< std::string, Comm, int, char ** > CommFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class...
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
#define LIB_UTILITIES_EXPORT
virtual int v_GetRank()=0
void Bcast(T &data, int rootProc)
virtual bool v_TreatAsRankZero(void)=0
virtual void v_Finalise()=0
void Send(int pProc, T &pData)
static CommDataType & GetDataType()
void AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
void SplitComm(int pRows, int pColumns)
Splits this communicator into a grid of size pRows*pColumns and creates row and column communicators...
Base communications class.
const char *const ReduceOperatorMap[]
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)=0
void Block()
Block execution until all processes reach this point.
T Gather(const int rootProc, T &val)
const std::string & GetType() const
void AllGather(T &pSendData, T &pRecvData)
void SendRecvReplace(int pSendProc, int pRecvProc, T &pData)
int GetSize()
Returns number of processes.
static void * GetPointer(T &val)
virtual void v_SplitComm(int pRows, int pColumns)=0
CommSharedPtr CommCreateIf(int flag)
If the flag is non-zero create a new communicator.
virtual NekDouble v_Wtime()=0
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc)=0
int m_size
Number of processes.
bool RemoveExistingFiles(void)
Provides a generic Factory class.
CommSharedPtr GetColumnComm()
Retrieve the column communicator to which this process belongs.