34 #ifndef NEKTAR_LIB_UTILITIES_COMM_H
35 #define NEKTAR_LIB_UTILITIES_COMM_H
38 #include <type_traits>
51 namespace LibUtilities
89 class Comm :
public std::enable_shared_from_this<Comm>
108 template <
class T>
void Send(
int pProc, T &pData);
109 template <
class T>
void Recv(
int pProc, T &pData);
111 void SendRecv(
int pSendProc, T &pSendData,
int pRecvProc, T &pRecvData);
117 template <
class T>
void AlltoAll(T &pSendData, T &pRecvData);
118 template <
class T1,
class T2>
119 void AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap,
120 T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap);
122 template <
class T>
void AllGather(T &pSendData, T &pRecvData);
131 template <
class T>
void Bcast(T &pData,
int pRoot);
135 template <
class T> T
Gather(
int rootProc, T &val);
136 template <
class T> T
Scatter(
int rootProc, T &pData);
140 template <
class T1,
class T2>
142 T2 &pSendDataOffsetMap, T1 &pRecvData,
143 T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap);
145 void Irsend(
int pProc, T &pData,
int count,
148 void Isend(
int pProc, T &pData,
int count,
151 void SendInit(
int pProc, T &pData,
int count,
154 void Irecv(
int pProc, T &pData,
int count,
157 void RecvInit(
int pProc, T &pData,
int count,
197 int dest,
void *recvbuf,
int recvcount,
200 int pSendProc,
int pRecvProc) = 0;
204 void *recvbuf,
int recvcount,
206 virtual void v_AlltoAllv(
void *sendbuf,
int sendcounts[],
int sensdispls[],
208 int recvcounts[],
int rdispls[],
215 int recvcounts[],
int rdispls[],
217 virtual void v_AllGatherv(
void *recvbuf,
int recvcounts[],
int rdispls[],
236 const int sourceweights[],
241 void *recvbuf,
int recvcounts[],
369 "AlltoAll only valid with Array or vector arguments.");
373 "Send and Recv arrays have incompatible sizes in AlltoAll");
375 int count = sendSize /
GetSize();
377 "Array size incompatible with size of communicator");
388 template <
class T1,
class T2>
390 T2 &pSendDataOffsetMap, T1 &pRecvData,
391 T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
394 "AlltoAllv only valid with Array or vector arguments.");
395 static_assert(std::is_same<T2, std::vector<int>>::value ||
397 "Alltoallv size and offset maps should be integer vectors.");
410 BOOST_STATIC_ASSERT_MSG(
412 "AllGather only valid with Array or vector arguments.");
415 int recvSize = sendSize;
417 pRecvData = T(recvSize *
GetSize());
433 BOOST_STATIC_ASSERT_MSG(
435 "AllGatherv only valid with Array or vector arguments.");
442 pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
453 BOOST_STATIC_ASSERT_MSG(
455 "AllGatherv only valid with Array or vector arguments.");
458 pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
477 "Input and output array sizes don't match");
491 "Gather only valid with Array or vector arguments.");
492 bool amRoot = (
GetRank() == rootProc);
495 unsigned nOut = amRoot ?
GetSize() * nEl : 0;
510 "Scatter only valid with Array or vector arguments.");
512 bool amRoot = (
GetRank() == rootProc);
542 "DistGraphCreateAdjacent only valid with Array or vector arguments.");
546 "Sources and weights array sizes don't match");
573 template <
class T1,
class T2>
575 T2 &pSendDataOffsetMap, T1 &pRecvData,
576 T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
580 "NeighbourAlltoAllv only valid with Array or vector arguments.");
582 std::is_same<T2, std::vector<int>>::value ||
584 "NeighborAllToAllv size and offset maps should be integer vectors.");
738 return shared_from_this();
754 return shared_from_this();
770 return shared_from_this();
786 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 GetSpaceComm()
Retrieve the space communicator to which this process belongs.
void Isend(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
virtual std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode()
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.
bool RemoveExistingFiles()
T Gather(int rootProc, T &val)
virtual bool v_RemoveExistingFiles()
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans)=0
void Block()
Block execution until all processes reach this point.
CommSharedPtr GetRowComm()
Retrieve the row communicator to which this process belongs.
CommRequestSharedPtr CreateRequest(int num)
NekDouble Wtime()
Return the time in seconds.
void StartAll(const CommRequestSharedPtr &request)
virtual void v_Isend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc)=0
virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
void Exscan(T &pData, enum ReduceOperator pOp, T &ans)
CommSharedPtr m_commRow
Row communicator.
const std::string & GetType() const
void SendRecvReplace(int pSendProc, int pRecvProc, T &pData)
virtual void v_WaitAll(CommRequestSharedPtr request)=0
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source)=0
void Bcast(T &pData, int pRoot)
int GetSize() const
Returns number of processes.
void SendInit(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
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
void SplitComm(int pRows, int pColumns, int pTime=1)
Splits this communicator into a grid of size pRows*pColumns and creates row and column communicators....
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 Send(int pProc, T &pData)
int m_size
Number of processes.
std::string m_type
Type of communication.
void Recv(int pProc, T &pData)
void WaitAll(const CommRequestSharedPtr &request)
virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc)=0
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp)=0
virtual NekDouble v_Wtime()=0
virtual CommRequestSharedPtr v_CreateRequest(int num)=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
std::pair< CommSharedPtr, CommSharedPtr > SplitCommNode()
virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc)=0
virtual std::tuple< int, int, int > v_GetVersion()=0
void RecvInit(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
std::tuple< int, int, int > GetVersion()
void Irecv(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
virtual void v_Finalise()=0
CommSharedPtr GetTimeComm()
Retrieve the time communicator to which this process belongs.
void AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[], const int sourceweights[], int reorder)=0
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root)=0
void DistGraphCreateAdjacent(T &sources, T &sourceweights, int reorder)
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
virtual void v_StartAll(CommRequestSharedPtr request)=0
void Irsend(int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
T Scatter(int rootProc, T &pData)
virtual bool v_TreatAsRankZero()=0
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc)=0
virtual bool v_IsSerial()=0
CommSharedPtr m_commSpace
virtual void v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc)=0
void NeighborAlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
virtual void v_SplitComm(int pRows, int pColumns, int pTime)=0
Class for communicator request type.
virtual ~CommRequest()=default
Default destructor.
CommRequest()=default
Default constructor.
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[]
unsigned int CommDataType
std::shared_ptr< CommRequest > CommRequestSharedPtr
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.