34#ifndef NEKTAR_LIB_UTILITIES_COMM_H
35#define NEKTAR_LIB_UTILITIES_COMM_H
87class Comm :
public std::enable_shared_from_this<Comm>
111 template <
class T>
void Send(
int pProc, T &pData);
112 template <
class T>
void Recv(
int pProc, T &pData);
114 void SendRecv(
int pSendProc, T &pSendData,
int pRecvProc, T &pRecvData);
118 template <
class T>
void AlltoAll(T &pSendData, T &pRecvData);
119 template <
class T1,
class T2>
120 void AlltoAllv(T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap,
121 T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap);
123 template <
class T>
void AllGather(T &pSendData, T &pRecvData);
132 template <
class T>
void Bcast(T &pData,
int pRoot);
133 template <
class T> T
Gather(
int rootProc, T &val);
134 template <
class T> T
Scatter(
int rootProc, T &pData);
138 template <
class T1,
class T2>
140 T2 &pSendDataOffsetMap, T1 &pRecvData,
141 T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap);
144 void Irsend(
int pProc, T &pData,
int count,
147 void Isend(
int pProc, T &pData,
int count,
150 void SendInit(
int pProc, T &pData,
int count,
153 void Irecv(
int pProc, T &pData,
int count,
156 void RecvInit(
int pProc, T &pData,
int count,
194 int dest,
void *recvbuf,
int recvcount,
199 void *recvbuf,
int recvcount,
201 virtual void v_AlltoAllv(
void *sendbuf,
int sendcounts[],
int sensdispls[],
203 int recvcounts[],
int rdispls[],
210 int recvcounts[],
int rdispls[],
212 virtual void v_AllGatherv(
void *recvbuf,
int recvcounts[],
int rdispls[],
224 const int sourceweights[],
229 void *recvbuf,
int recvcounts[],
383 "AlltoAll only valid with Array or vector arguments.");
387 "Send and Recv arrays have incompatible sizes in AlltoAll");
389 int count = sendSize /
GetSize();
391 "Array size incompatible with size of communicator");
402template <
class T1,
class T2>
404 T2 &pSendDataOffsetMap, T1 &pRecvData,
405 T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
408 "AlltoAllv only valid with Array or vector arguments.");
409 static_assert(std::is_same<T2, std::vector<int>>::value ||
410 std::is_same<T2, Array<OneD, int>>::value,
411 "Alltoallv size and offset maps should be integer vectors.");
427 BOOST_STATIC_ASSERT_MSG(
429 "AllGather only valid with Array or vector arguments.");
432 int recvSize = sendSize;
434 pRecvData = T(recvSize *
GetSize());
450 BOOST_STATIC_ASSERT_MSG(
452 "AllGatherv only valid with Array or vector arguments.");
459 pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
470 BOOST_STATIC_ASSERT_MSG(
472 "AllGatherv only valid with Array or vector arguments.");
475 pRecvDataSizeMap.get(), pRecvDataOffsetMap.get(),
496 "Gather only valid with Array or vector arguments.");
497 bool amRoot = (
GetRank() == rootProc);
500 unsigned nOut = amRoot ?
GetSize() * nEl : 0;
516 "Scatter only valid with Array or vector arguments.");
518 bool amRoot = (
GetRank() == rootProc);
548 "DistGraphCreateAdjacent only valid with Array or vector arguments.");
552 "Sources and weights array sizes don't match");
579template <
class T1,
class T2>
581 T2 &pSendDataOffsetMap, T1 &pRecvData,
582 T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
586 "NeighbourAlltoAllv only valid with Array or vector arguments.");
588 std::is_same<T2, std::vector<int>>::value ||
589 std::is_same<T2, Array<OneD, int>>::value,
590 "NeighborAllToAllv size and offset maps should be integer vectors.");
744 return shared_from_this();
760 return shared_from_this();
776 return shared_from_this();
792 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 std::tuple< int, int, int > v_GetVersion()=0
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)
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
CommSharedPtr m_commRow
Row communicator.
const std::string & GetType() const
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)
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
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.