Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Nektar::LibUtilities::Comm Class Referenceabstract

Base communications class. More...

#include <Comm.h>

Inheritance diagram for Nektar::LibUtilities::Comm:
Inheritance graph
[legend]
Collaboration diagram for Nektar::LibUtilities::Comm:
Collaboration graph
[legend]

Public Member Functions

 Comm (int narg, char *arg[])
 
virtual ~Comm ()
 
void Finalise ()
 
int GetSize ()
 Returns number of processes. More...
 
int GetRank ()
 
const std::string & GetType () const
 
void Block ()
 Block execution until all processes reach this point. More...
 
NekDouble Wtime ()
 Return the time in seconds. More...
 
template<class T >
void Send (int pProc, T &pData)
 
template<class T >
void Recv (int pProc, T &pData)
 
template<class T >
void SendRecv (int pSendProc, T &pSendData, int pRecvProc, T &pRecvData)
 
template<class T >
void SendRecvReplace (int pSendProc, int pRecvProc, T &pData)
 
template<class T >
void AllReduce (T &pData, enum ReduceOperator pOp)
 
template<class T >
void AlltoAll (T &pSendData, T &pRecvData)
 
template<class T >
void AlltoAllv (Array< OneD, T > &pSendData, Array< OneD, int > &pSendDataSizeMap, Array< OneD, int > &pSendDataOffsetMap, Array< OneD, T > &pRecvData, Array< OneD, int > &pRecvDataSizeMap, Array< OneD, int > &pRecvDataOffsetMap)
 
template<class T >
void Bcast (T &data, int rootProc)
 
template<class T >
void Exscan (T &pData, const enum ReduceOperator pOp, T &ans)
 
template<class T >
Gather (const int rootProc, T &val)
 
template<class T >
Scatter (const int rootProc, T &pData)
 
CommSharedPtr CommCreateIf (int flag)
 If the flag is non-zero create a new communicator. More...
 
void SplitComm (int pRows, int pColumns)
 Splits this communicator into a grid of size pRows*pColumns and creates row and column communicators. By default the communicator is a single row. More...
 
CommSharedPtr GetRowComm ()
 Retrieve the row communicator to which this process belongs. More...
 
CommSharedPtr GetColumnComm ()
 Retrieve the column communicator to which this process belongs. More...
 
bool TreatAsRankZero (void)
 
bool RemoveExistingFiles (void)
 

Protected Member Functions

 Comm ()
 
virtual void v_Finalise ()=0
 
virtual int v_GetRank ()=0
 
virtual void v_Block ()=0
 
virtual NekDouble v_Wtime ()=0
 
virtual void v_Send (void *buf, int count, CommDataType dt, int dest)=0
 
virtual void v_Recv (void *buf, int count, CommDataType dt, int source)=0
 
virtual void v_SendRecv (void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source)=0
 
virtual void v_SendRecvReplace (void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc)=0
 
virtual void v_AllReduce (void *buf, int count, CommDataType dt, enum ReduceOperator pOp)=0
 
virtual void v_AlltoAll (void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)=0
 
virtual void v_AlltoAllv (void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
 
virtual void v_Bcast (void *buffer, int count, CommDataType dt, int root)=0
 
virtual void v_Exscan (Array< OneD, unsigned long long > &pData, const enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans)=0
 
virtual void v_Gather (void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
 
virtual void v_Scatter (void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
 
virtual CommSharedPtr v_CommCreateIf (int flag)=0
 
virtual void v_SplitComm (int pRows, int pColumns)=0
 
virtual bool v_TreatAsRankZero (void)=0
 
virtual bool v_RemoveExistingFiles (void)
 

Protected Attributes

int m_size
 Number of processes. More...
 
std::string m_type
 Type of communication. More...
 
CommSharedPtr m_commRow
 Row communicator. More...
 
CommSharedPtr m_commColumn
 Column communicator. More...
 

Detailed Description

Base communications class.

Definition at line 75 of file Comm.h.

Constructor & Destructor Documentation

Nektar::LibUtilities::Comm::Comm ( int  narg,
char *  arg[] 
)

Definition at line 43 of file Comm.cpp.

44 {
45 }
Nektar::LibUtilities::Comm::~Comm ( )
virtual

Definition at line 51 of file Comm.cpp.

52 {
53 }
Nektar::LibUtilities::Comm::Comm ( )
protected

Definition at line 47 of file Comm.cpp.

48 {
49 }

Member Function Documentation

template<class T >
void Nektar::LibUtilities::Comm::AllReduce ( T &  pData,
enum ReduceOperator  pOp 
)

Definition at line 268 of file Comm.h.

References v_AllReduce().

269 {
270  v_AllReduce(CommDataTypeTraits<T>::GetPointer(pData),
271  CommDataTypeTraits<T>::GetCount(pData),
272  CommDataTypeTraits<T>::GetDataType(), pOp);
273 }
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp)=0
template<class T >
void Nektar::LibUtilities::Comm::AlltoAll ( T &  pSendData,
T &  pRecvData 
)

Definition at line 275 of file Comm.h.

References ASSERTL0, Nektar::LibUtilities::CommDataTypeTraits< T >::GetCount(), GetSize(), and v_AlltoAll().

276 {
277  BOOST_STATIC_ASSERT_MSG(
278  CommDataTypeTraits<T>::IsVector,
279  "AlltoAll only valid with Array or vector arguments.");
280  int sendSize = CommDataTypeTraits<T>::GetCount(pSendData);
281  int recvSize = CommDataTypeTraits<T>::GetCount(pRecvData);
282  ASSERTL0(sendSize == recvSize,
283  "Send and Recv arrays have incompatible sizes in AlltoAll");
284 
285  int count = sendSize / GetSize();
286  ASSERTL0(count * GetSize() == sendSize,
287  "Array size incompatible with size of communicator");
288 
289  v_AlltoAll(CommDataTypeTraits<T>::GetPointer(pSendData), count,
290  CommDataTypeTraits<T>::GetDataType(),
291  CommDataTypeTraits<T>::GetPointer(pRecvData), count,
292  CommDataTypeTraits<T>::GetDataType());
293 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
static int GetCount(const T &val)
Definition: CommDataType.h:96
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype)=0
int GetSize()
Returns number of processes.
Definition: Comm.h:188
template<class T >
void Nektar::LibUtilities::Comm::AlltoAllv ( Array< OneD, T > &  pSendData,
Array< OneD, int > &  pSendDataSizeMap,
Array< OneD, int > &  pSendDataOffsetMap,
Array< OneD, T > &  pRecvData,
Array< OneD, int > &  pRecvDataSizeMap,
Array< OneD, int > &  pRecvDataOffsetMap 
)

Definition at line 299 of file Comm.h.

References Nektar::LibUtilities::CommDataTypeTraits< T >::GetDataType(), and v_AlltoAllv().

305 {
306  v_AlltoAllv(pSendData.get(), pSendDataSizeMap.get(),
307  pSendDataOffsetMap.get(), CommDataTypeTraits<T>::GetDataType(),
308  pRecvData.get(), pRecvDataSizeMap.get(),
309  pRecvDataOffsetMap.get(), CommDataTypeTraits<T>::GetDataType());
310 }
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype)=0
template<class T >
void Nektar::LibUtilities::Comm::Bcast ( T &  data,
int  rootProc 
)

Definition at line 315 of file Comm.h.

References v_Bcast().

316 {
317  v_Bcast(CommDataTypeTraits<T>::GetPointer(pData),
318  CommDataTypeTraits<T>::GetCount(pData),
319  CommDataTypeTraits<T>::GetDataType(), pRoot);
320 }
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root)=0
void Nektar::LibUtilities::Comm::Block ( )
inline

Block execution until all processes reach this point.

Definition at line 212 of file Comm.h.

References v_Block().

213 {
214  v_Block();
215 }
virtual void v_Block()=0
CommSharedPtr Nektar::LibUtilities::Comm::CommCreateIf ( int  flag)
inline

If the flag is non-zero create a new communicator.

Definition at line 379 of file Comm.h.

References v_CommCreateIf().

380 {
381  return v_CommCreateIf(flag);
382 }
virtual CommSharedPtr v_CommCreateIf(int flag)=0
template<class T >
void Nektar::LibUtilities::Comm::Exscan ( T &  pData,
const enum ReduceOperator  pOp,
T &  ans 
)

Definition at line 323 of file Comm.h.

References ASSERTL0, and v_Exscan().

324 {
325  ASSERTL0(CommDataTypeTraits<T>::GetCount(pData) ==
326  CommDataTypeTraits<T>::GetCount(ans),
327  "Input and output array sizes don't match");
328  v_Exscan(CommDataTypeTraits<T>::GetPointer(pData),
329  CommDataTypeTraits<T>::GetPointer(ans),
330  CommDataTypeTraits<T>::GetCount(pData),
331  CommDataTypeTraits<T>::GetDataType(), pOp);
332 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, const enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans)=0
void Nektar::LibUtilities::Comm::Finalise ( )
inline

Definition at line 180 of file Comm.h.

References v_Finalise().

181 {
182  v_Finalise();
183 }
virtual void v_Finalise()=0
template<class T >
T Nektar::LibUtilities::Comm::Gather ( const int  rootProc,
T &  val 
)

Concatenate all the input arrays, in rank order, onto the process with rank == rootProc

Definition at line 338 of file Comm.h.

References Nektar::LibUtilities::CommDataTypeTraits< T >::GetCount(), Nektar::LibUtilities::CommDataTypeTraits< T >::GetPointer(), GetRank(), GetSize(), and v_Gather().

339 {
340  BOOST_STATIC_ASSERT_MSG(
341  CommDataTypeTraits<T>::IsVector,
342  "Gather only valid with Array or vector arguments.");
343  bool amRoot = (GetRank() == rootProc);
344  unsigned nEl = CommDataTypeTraits<T>::GetCount(val);
345 
346  unsigned nOut = amRoot ? GetSize() * nEl : 0;
347  T ans(nOut);
348  void *recvbuf = amRoot ? CommDataTypeTraits<T>::GetPointer(ans) : NULL;
349 
350  v_Gather(CommDataTypeTraits<T>::GetPointer(val), nEl,
351  CommDataTypeTraits<T>::GetDataType(), recvbuf, nEl,
352  CommDataTypeTraits<T>::GetDataType(), rootProc);
353  return ans;
354 }
static int GetCount(const T &val)
Definition: CommDataType.h:96
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
int GetSize()
Returns number of processes.
Definition: Comm.h:188
CommSharedPtr Nektar::LibUtilities::Comm::GetColumnComm ( )
inline

Retrieve the column communicator to which this process belongs.

Definition at line 413 of file Comm.h.

References m_commColumn.

414 {
415  if (!m_commColumn.get())
416  {
417  return shared_from_this();
418  }
419  else
420  {
421  return m_commColumn;
422  }
423 }
CommSharedPtr m_commColumn
Column communicator.
Definition: Comm.h:133
int Nektar::LibUtilities::Comm::GetRank ( )
inline

Definition at line 196 of file Comm.h.

References v_GetRank().

Referenced by Gather(), and Scatter().

197 {
198  return v_GetRank();
199 }
virtual int v_GetRank()=0
CommSharedPtr Nektar::LibUtilities::Comm::GetRowComm ( )
inline

Retrieve the row communicator to which this process belongs.

Definition at line 397 of file Comm.h.

References m_commRow.

398 {
399  if (!m_commRow.get())
400  {
401  return shared_from_this();
402  }
403  else
404  {
405  return m_commRow;
406  }
407 }
CommSharedPtr m_commRow
Row communicator.
Definition: Comm.h:132
int Nektar::LibUtilities::Comm::GetSize ( )
inline

Returns number of processes.

Definition at line 188 of file Comm.h.

References m_size.

Referenced by AlltoAll(), Gather(), Scatter(), and Nektar::LibUtilities::CommMpi::v_AllReduce().

189 {
190  return m_size;
191 }
int m_size
Number of processes.
Definition: Comm.h:130
const std::string & Nektar::LibUtilities::Comm::GetType ( ) const
inline

Definition at line 204 of file Comm.h.

References m_type.

205 {
206  return m_type;
207 }
std::string m_type
Type of communication.
Definition: Comm.h:131
template<class T >
void Nektar::LibUtilities::Comm::Recv ( int  pProc,
T &  pData 
)

Definition at line 232 of file Comm.h.

References v_Recv().

233 {
234  v_Recv(CommDataTypeTraits<T>::GetPointer(pData),
235  CommDataTypeTraits<T>::GetCount(pData),
236  CommDataTypeTraits<T>::GetDataType(), pProc);
237 }
virtual void v_Recv(void *buf, int count, CommDataType dt, int source)=0
bool Nektar::LibUtilities::Comm::RemoveExistingFiles ( void  )
inline

Definition at line 430 of file Comm.h.

References v_RemoveExistingFiles().

431 {
432  return v_RemoveExistingFiles();
433 }
virtual bool v_RemoveExistingFiles(void)
Definition: Comm.cpp:56
template<class T >
T Nektar::LibUtilities::Comm::Scatter ( const int  rootProc,
T &  pData 
)

Scatter pData across ranks in chunks of len(pData)/num_ranks

Definition at line 358 of file Comm.h.

References Nektar::LibUtilities::CommDataTypeTraits< T >::GetCount(), Nektar::LibUtilities::CommDataTypeTraits< T >::GetPointer(), GetRank(), GetSize(), and v_Scatter().

359 {
360  BOOST_STATIC_ASSERT_MSG(
361  CommDataTypeTraits<T>::IsVector,
362  "Scatter only valid with Array or vector arguments.");
363 
364  bool amRoot = (GetRank() == rootProc);
365  unsigned nEl = CommDataTypeTraits<T>::GetCount(pData) / GetSize();
366 
367  void *sendbuf = amRoot ? CommDataTypeTraits<T>::GetPointer(pData) : NULL;
368  T ans(nEl);
369 
370  v_Scatter(sendbuf, nEl, CommDataTypeTraits<T>::GetDataType(),
371  CommDataTypeTraits<T>::GetPointer(ans), nEl,
372  CommDataTypeTraits<T>::GetDataType(), rootProc);
373  return ans;
374 }
static int GetCount(const T &val)
Definition: CommDataType.h:96
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root)=0
int GetSize()
Returns number of processes.
Definition: Comm.h:188
template<class T >
void Nektar::LibUtilities::Comm::Send ( int  pProc,
T &  pData 
)

Definition at line 225 of file Comm.h.

References v_Send().

226 {
227  v_Send(CommDataTypeTraits<T>::GetPointer(pData),
228  CommDataTypeTraits<T>::GetCount(pData),
229  CommDataTypeTraits<T>::GetDataType(), pProc);
230 }
virtual void v_Send(void *buf, int count, CommDataType dt, int dest)=0
template<class T >
void Nektar::LibUtilities::Comm::SendRecv ( int  pSendProc,
T &  pSendData,
int  pRecvProc,
T &  pRecvData 
)

Definition at line 243 of file Comm.h.

References v_SendRecv().

244 {
245  v_SendRecv(CommDataTypeTraits<T>::GetPointer(pSendData),
246  CommDataTypeTraits<T>::GetCount(pSendData),
247  CommDataTypeTraits<T>::GetDataType(), pSendProc,
248  CommDataTypeTraits<T>::GetPointer(pRecvData),
249  CommDataTypeTraits<T>::GetCount(pRecvData),
250  CommDataTypeTraits<T>::GetDataType(), pRecvProc);
251 }
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source)=0
template<class T >
void Nektar::LibUtilities::Comm::SendRecvReplace ( int  pSendProc,
int  pRecvProc,
T &  pData 
)

Definition at line 257 of file Comm.h.

References v_SendRecvReplace().

258 {
259  v_SendRecvReplace(CommDataTypeTraits<T>::GetPointer(pData),
260  CommDataTypeTraits<T>::GetCount(pData),
261  CommDataTypeTraits<T>::GetDataType(), pSendProc,
262  pRecvProc);
263 }
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc)=0
void Nektar::LibUtilities::Comm::SplitComm ( int  pRows,
int  pColumns 
)
inline

Splits this communicator into a grid of size pRows*pColumns and creates row and column communicators. By default the communicator is a single row.

Definition at line 389 of file Comm.h.

References v_SplitComm().

390 {
391  v_SplitComm(pRows, pColumns);
392 }
virtual void v_SplitComm(int pRows, int pColumns)=0
bool Nektar::LibUtilities::Comm::TreatAsRankZero ( void  )
inline

Definition at line 425 of file Comm.h.

References v_TreatAsRankZero().

426 {
427  return v_TreatAsRankZero();
428 }
virtual bool v_TreatAsRankZero(void)=0
virtual void Nektar::LibUtilities::Comm::v_AllReduce ( void buf,
int  count,
CommDataType  dt,
enum ReduceOperator  pOp 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_AlltoAll ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
void recvbuf,
int  recvcount,
CommDataType  recvtype 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_AlltoAllv ( void sendbuf,
int  sendcounts[],
int  sensdispls[],
CommDataType  sendtype,
void recvbuf,
int  recvcounts[],
int  rdispls[],
CommDataType  recvtype 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_Bcast ( void buffer,
int  count,
CommDataType  dt,
int  root 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_Block ( )
protectedpure virtual
virtual CommSharedPtr Nektar::LibUtilities::Comm::v_CommCreateIf ( int  flag)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_Exscan ( Array< OneD, unsigned long long > &  pData,
const enum ReduceOperator  pOp,
Array< OneD, unsigned long long > &  ans 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_Finalise ( )
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_Gather ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
void recvbuf,
int  recvcount,
CommDataType  recvtype,
int  root 
)
protectedpure virtual
virtual int Nektar::LibUtilities::Comm::v_GetRank ( )
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_Recv ( void buf,
int  count,
CommDataType  dt,
int  source 
)
protectedpure virtual
bool Nektar::LibUtilities::Comm::v_RemoveExistingFiles ( void  )
protectedvirtual

Reimplemented in Nektar::FieldUtils::FieldConvertComm.

Definition at line 56 of file Comm.cpp.

Referenced by RemoveExistingFiles().

57 {
58  return true;
59 }
virtual void Nektar::LibUtilities::Comm::v_Scatter ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
void recvbuf,
int  recvcount,
CommDataType  recvtype,
int  root 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_Send ( void buf,
int  count,
CommDataType  dt,
int  dest 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_SendRecv ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
int  dest,
void recvbuf,
int  recvcount,
CommDataType  recvtype,
int  source 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_SendRecvReplace ( void buf,
int  count,
CommDataType  dt,
int  pSendProc,
int  pRecvProc 
)
protectedpure virtual
virtual void Nektar::LibUtilities::Comm::v_SplitComm ( int  pRows,
int  pColumns 
)
protectedpure virtual
virtual bool Nektar::LibUtilities::Comm::v_TreatAsRankZero ( void  )
protectedpure virtual
virtual NekDouble Nektar::LibUtilities::Comm::v_Wtime ( )
protectedpure virtual
double Nektar::LibUtilities::Comm::Wtime ( )
inline

Return the time in seconds.

Definition at line 220 of file Comm.h.

References v_Wtime().

221 {
222  return v_Wtime();
223 }
virtual NekDouble v_Wtime()=0

Member Data Documentation

CommSharedPtr Nektar::LibUtilities::Comm::m_commColumn
protected

Column communicator.

Definition at line 133 of file Comm.h.

Referenced by GetColumnComm(), and Nektar::LibUtilities::CommMpi::v_SplitComm().

CommSharedPtr Nektar::LibUtilities::Comm::m_commRow
protected

Row communicator.

Definition at line 132 of file Comm.h.

Referenced by GetRowComm(), and Nektar::LibUtilities::CommMpi::v_SplitComm().

int Nektar::LibUtilities::Comm::m_size
protected
std::string Nektar::LibUtilities::Comm::m_type
protected

Type of communication.

Definition at line 131 of file Comm.h.

Referenced by Nektar::LibUtilities::CommMpi::CommMpi(), Nektar::LibUtilities::CommSerial::CommSerial(), and GetType().