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 SendInit(
int pProc, T &pData,
int count,
151 void Irecv(
int pProc, T &pData,
int count,
154 void RecvInit(
int pProc, T &pData,
int count,
189 int dest,
void *recvbuf,
int recvcount,
192 int pSendProc,
int pRecvProc) = 0;
196 void *recvbuf,
int recvcount,
198 virtual void v_AlltoAllv(
void *sendbuf,
int sendcounts[],
int sensdispls[],
200 int recvcounts[],
int rdispls[],
207 int recvcounts[],
int rdispls[],
209 virtual void v_AllGatherv(
void *recvbuf,
int recvcounts[],
int rdispls[],
228 const int sourceweights[],
233 void *recvbuf,
int recvcounts[],
359 "AlltoAll only valid with Array or vector arguments.");
363 "Send and Recv arrays have incompatible sizes in AlltoAll");
365 int count = sendSize /
GetSize();
367 "Array size incompatible with size of communicator");
378 template <
class T1,
class T2>
380 T2 &pSendDataOffsetMap, T1 &pRecvData,
381 T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
384 "AlltoAllv only valid with Array or vector arguments.");
385 static_assert(std::is_same<T2, std::vector<int>>::value ||
387 "Alltoallv size and offset maps should be integer vectors.");
400 BOOST_STATIC_ASSERT_MSG(
402 "AllGather only valid with Array or vector arguments.");
405 int recvSize = sendSize;
407 pRecvData = T(recvSize *
GetSize());
423 BOOST_STATIC_ASSERT_MSG(
425 "AllGatherv only valid with Array or vector arguments.");
432 pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
443 BOOST_STATIC_ASSERT_MSG(
445 "AllGatherv only valid with Array or vector arguments.");
448 pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
467 "Input and output array sizes don't match");
481 "Gather only valid with Array or vector arguments.");
482 bool amRoot = (
GetRank() == rootProc);
485 unsigned nOut = amRoot ?
GetSize() * nEl : 0;
500 "Scatter only valid with Array or vector arguments.");
502 bool amRoot = (
GetRank() == rootProc);
532 "DistGraphCreateAdjacent only valid with Array or vector arguments.");
536 "Sources and weights array sizes don't match");
563 template <
class T1,
class T2>
565 T2 &pSendDataOffsetMap, T1 &pRecvData,
566 T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
570 "NeighbourAlltoAllv only valid with Array or vector arguments.");
572 std::is_same<T2, std::vector<int>>::value ||
574 "NeighborAllToAllv size and offset maps should be integer vectors.");
711 return shared_from_this();
727 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)
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_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
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
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 SplitComm(int pRows, int pColumns)
Splits this communicator into a grid of size pRows*pColumns and creates row and column communicators....
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 void v_SplitComm(int pRows, int pColumns)=0
virtual bool v_IsSerial()=0
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)
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.