Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Nektar::LibUtilities::CommMpi Class Reference

A global linear system. More...

#include <CommMpi.h>

Inheritance diagram for Nektar::LibUtilities::CommMpi:
[legend]

Public Member Functions

 CommMpi (int narg, char *arg[])
 
virtual ~CommMpi () override
 
MPI_Comm GetComm ()
 
- Public Member Functions inherited from Nektar::LibUtilities::Comm
 Comm (int narg, char *arg[])
 
virtual ~Comm ()
 
void Finalise ()
 
int GetSize () const
 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 T1 , class T2 >
void AlltoAllv (T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
 
template<class T >
void AllGather (T &pSendData, T &pRecvData)
 
template<class T >
void AllGatherv (T &pSendData, T &pRecvData, Array< OneD, int > &pRecvDataSizeMap, Array< OneD, int > &pRecvDataOffsetMap)
 
template<class T >
void AllGatherv (T &pRecvData, Array< OneD, int > &pRecvDataSizeMap, Array< OneD, int > &pRecvDataOffsetMap)
 
template<class T >
void Bcast (T &pData, int pRoot)
 
template<class T >
void Exscan (T &pData, enum ReduceOperator pOp, T &ans)
 
template<class T >
Gather (int rootProc, T &val)
 
template<class T >
Scatter (int rootProc, T &pData)
 
template<class T >
void DistGraphCreateAdjacent (T &sources, T &sourceweights, int reorder)
 
template<class T1 , class T2 >
void NeighborAlltoAllv (T1 &pSendData, T2 &pSendDataSizeMap, T2 &pSendDataOffsetMap, T1 &pRecvData, T2 &pRecvDataSizeMap, T2 &pRecvDataOffsetMap)
 
template<class T >
void Irsend (int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
 
template<class T >
void SendInit (int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
 
template<class T >
void Irecv (int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
 
template<class T >
void RecvInit (int pProc, T &pData, int count, const CommRequestSharedPtr &request, int loc)
 
void StartAll (const CommRequestSharedPtr &request)
 
void WaitAll (const CommRequestSharedPtr &request)
 
CommRequestSharedPtr CreateRequest (int num)
 
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 ()
 
bool IsSerial ()
 
std::tuple< int, int, int > GetVersion ()
 
bool RemoveExistingFiles ()
 
std::pair< CommSharedPtr, CommSharedPtrSplitCommNode ()
 

Static Public Member Functions

static CommSharedPtr create (int narg, char *arg[])
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of class. More...
 

Protected Member Functions

 CommMpi (MPI_Comm pComm)
 
virtual void v_Finalise () override
 
virtual int v_GetRank () final
 
virtual void v_Block () final
 
virtual double v_Wtime () final
 
virtual bool v_TreatAsRankZero () final
 
virtual bool v_IsSerial () final
 
virtual std::tuple< int, int, int > v_GetVersion () final
 
virtual void v_Send (void *buf, int count, CommDataType dt, int dest) final
 
virtual void v_Recv (void *buf, int count, CommDataType dt, int source) final
 
virtual void v_SendRecv (void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
 
virtual void v_SendRecvReplace (void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc) final
 
virtual void v_AllReduce (void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
 
virtual void v_AlltoAll (void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
 
virtual void v_AlltoAllv (void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
 
virtual void v_AllGather (void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
 
virtual void v_AllGatherv (void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
 
virtual void v_AllGatherv (void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
 
virtual void v_Bcast (void *buffer, int count, CommDataType dt, int root) final
 
virtual void v_Exscan (Array< OneD, unsigned long long > &pData, enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans) final
 
virtual void v_Gather (void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
 
virtual void v_Scatter (void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
 
virtual void v_DistGraphCreateAdjacent (int indegree, const int sources[], const int sourceweights[], int reorder) final
 
virtual void v_NeighborAlltoAllv (void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
 
virtual void v_Irsend (void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
 
virtual void v_SendInit (void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
 
virtual void v_Irecv (void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
 
virtual void v_RecvInit (void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
 
virtual void v_StartAll (CommRequestSharedPtr request) final
 
virtual void v_WaitAll (CommRequestSharedPtr request) final
 
virtual CommRequestSharedPtr v_CreateRequest (int num) final
 
virtual void v_SplitComm (int pRows, int pColumns) override
 
virtual CommSharedPtr v_CommCreateIf (int flag) final
 
virtual std::pair< CommSharedPtr, CommSharedPtrv_SplitCommNode () final
 
- Protected Member Functions inherited from Nektar::LibUtilities::Comm
 Comm ()
 
virtual bool v_RemoveExistingFiles ()
 

Protected Attributes

MPI_Comm m_comm
 
int m_rank {}
 
- Protected Attributes inherited from Nektar::LibUtilities::Comm
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

A global linear system.

Definition at line 91 of file CommMpi.h.

Constructor & Destructor Documentation

◆ CommMpi() [1/2]

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

Definition at line 53 of file CommMpi.cpp.

53  : Comm(narg, arg)
54 {
55  int init = 0;
56  MPI_Initialized(&init);
57  ASSERTL0(!init, "MPI has already been initialised.");
58 
59  int retval = MPI_Init(&narg, &arg);
60  if (retval != MPI_SUCCESS)
61  {
62  ASSERTL0(false, "Failed to initialise MPI");
63  }
64 
65  m_comm = MPI_COMM_WORLD;
66  MPI_Comm_size(m_comm, &m_size);
67  MPI_Comm_rank(m_comm, &m_rank);
68 
69 #ifdef NEKTAR_USING_PETSC
70  PetscInitializeNoArguments();
71 #endif
72 
73  m_type = "Parallel MPI";
74 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
int m_size
Number of processes.
Definition: Comm.h:175
std::string m_type
Type of communication.
Definition: Comm.h:176

References ASSERTL0, m_comm, m_rank, Nektar::LibUtilities::Comm::m_size, and Nektar::LibUtilities::Comm::m_type.

Referenced by v_CommCreateIf(), v_SplitComm(), and v_SplitCommNode().

◆ ~CommMpi()

Nektar::LibUtilities::CommMpi::~CommMpi ( )
overridevirtual

Definition at line 91 of file CommMpi.cpp.

92 {
93  int flag;
94  MPI_Finalized(&flag);
95  if (!flag && m_comm != MPI_COMM_WORLD)
96  {
97  MPI_Comm_free(&m_comm);
98  }
99 }

References m_comm.

◆ CommMpi() [2/2]

Nektar::LibUtilities::CommMpi::CommMpi ( MPI_Comm  pComm)
explicitprotected

Definition at line 79 of file CommMpi.cpp.

79  : Comm()
80 {
81  m_comm = pComm;
82  MPI_Comm_size(m_comm, &m_size);
83  MPI_Comm_rank(m_comm, &m_rank);
84 
85  m_type = "Parallel MPI";
86 }

References m_comm, m_rank, Nektar::LibUtilities::Comm::m_size, and Nektar::LibUtilities::Comm::m_type.

Member Function Documentation

◆ create()

static CommSharedPtr Nektar::LibUtilities::CommMpi::create ( int  narg,
char *  arg[] 
)
inlinestatic

Creates an instance of this class.

Definition at line 95 of file CommMpi.h.

96  {
98  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ GetComm()

MPI_Comm Nektar::LibUtilities::CommMpi::GetComm ( )

Definition at line 104 of file CommMpi.cpp.

105 {
106  return m_comm;
107 }

References m_comm.

◆ v_AllGather()

void Nektar::LibUtilities::CommMpi::v_AllGather ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
void recvbuf,
int  recvcount,
CommDataType  recvtype 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 288 of file CommMpi.cpp.

290 {
291  int retval = MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
292  recvtype, m_comm);
293 
294  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing Allgather.");
295 }

References ASSERTL0, and m_comm.

◆ v_AllGatherv() [1/2]

void Nektar::LibUtilities::CommMpi::v_AllGatherv ( void recvbuf,
int  recvcounts[],
int  rdispls[],
CommDataType  recvtype 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 307 of file CommMpi.cpp.

309 {
310  int retval = MPI_Allgatherv(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, recvbuf,
311  recvcounts, rdispls, recvtype, m_comm);
312 
313  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing Allgatherv.");
314 }

References ASSERTL0, and m_comm.

◆ v_AllGatherv() [2/2]

void Nektar::LibUtilities::CommMpi::v_AllGatherv ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
void recvbuf,
int  recvcounts[],
int  rdispls[],
CommDataType  recvtype 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 297 of file CommMpi.cpp.

300 {
301  int retval = MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf,
302  recvcounts, rdispls, recvtype, m_comm);
303 
304  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing Allgather.");
305 }

References ASSERTL0, and m_comm.

◆ v_AllReduce()

void Nektar::LibUtilities::CommMpi::v_AllReduce ( void buf,
int  count,
CommDataType  dt,
enum ReduceOperator  pOp 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 232 of file CommMpi.cpp.

234 {
235  if (GetSize() == 1)
236  {
237  return;
238  }
239 
240  MPI_Op vOp;
241  switch (pOp)
242  {
243  case ReduceMax:
244  vOp = MPI_MAX;
245  break;
246  case ReduceMin:
247  vOp = MPI_MIN;
248  break;
249  case ReduceSum:
250  default:
251  vOp = MPI_SUM;
252  break;
253  }
254  int retval = MPI_Allreduce(MPI_IN_PLACE, buf, count, dt, vOp, m_comm);
255 
256  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing All-reduce.");
257 }
int GetSize() const
Returns number of processes.
Definition: Comm.h:269

References ASSERTL0, Nektar::LibUtilities::Comm::GetSize(), m_comm, Nektar::LibUtilities::ReduceMax, Nektar::LibUtilities::ReduceMin, and Nektar::LibUtilities::ReduceSum.

◆ v_AlltoAll()

void Nektar::LibUtilities::CommMpi::v_AlltoAll ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
void recvbuf,
int  recvcount,
CommDataType  recvtype 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 262 of file CommMpi.cpp.

264 {
265  int retval = MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount,
266  recvtype, m_comm);
267 
268  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing All-to-All.");
269 }

References ASSERTL0, and m_comm.

◆ v_AlltoAllv()

void Nektar::LibUtilities::CommMpi::v_AlltoAllv ( void sendbuf,
int  sendcounts[],
int  sensdispls[],
CommDataType  sendtype,
void recvbuf,
int  recvcounts[],
int  rdispls[],
CommDataType  recvtype 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 274 of file CommMpi.cpp.

278 {
279  int retval = MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
280  recvcounts, rdispls, recvtype, m_comm);
281 
282  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing All-to-All-v.");
283 }

References ASSERTL0, and m_comm.

◆ v_Bcast()

void Nektar::LibUtilities::CommMpi::v_Bcast ( void buffer,
int  count,
CommDataType  dt,
int  root 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 316 of file CommMpi.cpp.

317 {
318  int retval = MPI_Bcast(buffer, count, dt, root, m_comm);
319  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing Bcast-v.");
320 }
array buffer
Definition: GsLib.hpp:61

References ASSERTL0, and m_comm.

◆ v_Block()

void Nektar::LibUtilities::CommMpi::v_Block ( )
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 162 of file CommMpi.cpp.

163 {
164  MPI_Barrier(m_comm);
165 }

References m_comm.

◆ v_CommCreateIf()

CommSharedPtr Nektar::LibUtilities::CommMpi::v_CommCreateIf ( int  flag)
finalprotectedvirtual

Create a new communicator if the flag is non-zero.

Implements Nektar::LibUtilities::Comm.

Definition at line 488 of file CommMpi.cpp.

489 {
490  MPI_Comm newComm;
491  // color == MPI_UNDEF => not in the new communicator
492  // key == 0 on all => use rank to order them. OpenMPI, at least,
493  // implies this is faster than ordering them ourselves.
494  MPI_Comm_split(m_comm, flag ? 0 : MPI_UNDEFINED, 0, &newComm);
495 
496  if (flag == 0)
497  {
498  // flag == 0 => get back MPI_COMM_NULL, return a null ptr instead.
499  return std::shared_ptr<Comm>();
500  }
501  else
502  {
503  // Return a real communicator
504  return std::shared_ptr<Comm>(new CommMpi(newComm));
505  }
506 }
CommMpi(int narg, char *arg[])
Definition: CommMpi.cpp:53

References CommMpi(), and m_comm.

Referenced by v_SplitCommNode().

◆ v_CreateRequest()

CommRequestSharedPtr Nektar::LibUtilities::CommMpi::v_CreateRequest ( int  num)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 450 of file CommMpi.cpp.

451 {
452  return std::shared_ptr<CommRequest>(new CommRequestMpi(num));
453 }

◆ v_DistGraphCreateAdjacent()

void Nektar::LibUtilities::CommMpi::v_DistGraphCreateAdjacent ( int  indegree,
const int  sources[],
const int  sourceweights[],
int  reorder 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 368 of file CommMpi.cpp.

370 {
371 #if MPI_VERSION < 3
372  boost::ignore_unused(indegree, sources, sourceweights, reorder);
373  ASSERTL0(false, "MPI_Dist_graph_create_adjacent is not supported in your "
374  "installed MPI version.");
375 #else
376  int retval = MPI_Dist_graph_create_adjacent(
377  m_comm, indegree, sources, sourceweights, indegree, sources,
378  sourceweights, MPI_INFO_NULL, reorder, &m_comm);
379 
380  ASSERTL0(retval == MPI_SUCCESS,
381  "MPI error performing Dist_graph_create_adjacent.")
382 #endif
383 }

References ASSERTL0, and m_comm.

◆ v_Exscan()

void Nektar::LibUtilities::CommMpi::v_Exscan ( Array< OneD, unsigned long long > &  pData,
enum ReduceOperator  pOp,
Array< OneD, unsigned long long > &  ans 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 322 of file CommMpi.cpp.

325 {
326  int n = pData.size();
327  ASSERTL0(n == ans.size(), "Array sizes differ in Exscan");
328 
329  MPI_Op vOp;
330  switch (pOp)
331  {
332  case ReduceMax:
333  vOp = MPI_MAX;
334  break;
335  case ReduceMin:
336  vOp = MPI_MIN;
337  break;
338  case ReduceSum:
339  default:
340  vOp = MPI_SUM;
341  break;
342  }
343 
344  int retval = MPI_Exscan(pData.get(), ans.get(), n, MPI_UNSIGNED_LONG_LONG,
345  vOp, m_comm);
346  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing Exscan-v.");
347 }
#define MPI_UNSIGNED_LONG_LONG
Definition: CommDataType.h:97

References ASSERTL0, m_comm, MPI_UNSIGNED_LONG_LONG, Nektar::LibUtilities::ReduceMax, Nektar::LibUtilities::ReduceMin, and Nektar::LibUtilities::ReduceSum.

◆ v_Finalise()

void Nektar::LibUtilities::CommMpi::v_Finalise ( )
overrideprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Reimplemented in Nektar::LibUtilities::CommCwipi.

Definition at line 112 of file CommMpi.cpp.

113 {
114 #ifdef NEKTAR_USING_PETSC
115  PetscFinalize();
116 #endif
117  int flag;
118  MPI_Finalized(&flag);
119  if (!flag)
120  {
121  MPI_Finalize();
122  }
123 }

Referenced by Nektar::LibUtilities::CommCwipi::v_Finalise().

◆ v_Gather()

void Nektar::LibUtilities::CommMpi::v_Gather ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
void recvbuf,
int  recvcount,
CommDataType  recvtype,
int  root 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 349 of file CommMpi.cpp.

352 {
353  int retval = MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
354  recvtype, root, m_comm);
355 
356  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing Gather.");
357 }

References ASSERTL0, and m_comm.

◆ v_GetRank()

int Nektar::LibUtilities::CommMpi::v_GetRank ( void  )
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 128 of file CommMpi.cpp.

129 {
130  return m_rank;
131 }

References m_rank.

◆ v_GetVersion()

std::tuple< int, int, int > Nektar::LibUtilities::CommMpi::v_GetVersion ( )
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 149 of file CommMpi.cpp.

150 {
151  int version, subversion;
152  int retval = MPI_Get_version(&version, &subversion);
153 
154  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing GetVersion.");
155 
156  return std::make_tuple(version, subversion, 0);
157 }

References ASSERTL0.

◆ v_Irecv()

void Nektar::LibUtilities::CommMpi::v_Irecv ( void buf,
int  count,
CommDataType  dt,
int  source,
CommRequestSharedPtr  request,
int  loc 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 420 of file CommMpi.cpp.

422 {
424  std::static_pointer_cast<CommRequestMpi>(request);
425  MPI_Irecv(buf, count, dt, source, 0, m_comm, req->GetRequest(loc));
426 }
std::shared_ptr< CommRequestMpi > CommRequestMpiSharedPtr
Definition: CommMpi.h:88

References CG_Iterations::loc, and m_comm.

◆ v_Irsend()

void Nektar::LibUtilities::CommMpi::v_Irsend ( void buf,
int  count,
CommDataType  dt,
int  dest,
CommRequestSharedPtr  request,
int  loc 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 404 of file CommMpi.cpp.

406 {
408  std::static_pointer_cast<CommRequestMpi>(request);
409  MPI_Irsend(buf, count, dt, dest, 0, m_comm, req->GetRequest(loc));
410 }

References CG_Iterations::loc, and m_comm.

◆ v_IsSerial()

bool Nektar::LibUtilities::CommMpi::v_IsSerial ( void  )
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 144 of file CommMpi.cpp.

145 {
146  return m_size == 1;
147 }

References Nektar::LibUtilities::Comm::m_size.

◆ v_NeighborAlltoAllv()

void Nektar::LibUtilities::CommMpi::v_NeighborAlltoAllv ( void sendbuf,
int  sendcounts[],
int  sensdispls[],
CommDataType  sendtype,
void recvbuf,
int  recvcounts[],
int  rdispls[],
CommDataType  recvtype 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 385 of file CommMpi.cpp.

389 {
390 #if MPI_VERSION < 3
391  boost::ignore_unused(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
392  recvcounts, rdispls, recvtype);
393  ASSERTL0(false, "MPI_Neighbor_alltoallv is not supported in your "
394  "installed MPI version.");
395 #else
396  int retval =
397  MPI_Neighbor_alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf,
398  recvcounts, rdispls, recvtype, m_comm);
399 
400  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing NeighborAllToAllV.");
401 #endif
402 }

References ASSERTL0, and m_comm.

◆ v_Recv()

void Nektar::LibUtilities::CommMpi::v_Recv ( void buf,
int  count,
CommDataType  dt,
int  source 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 193 of file CommMpi.cpp.

194 {
195  MPI_Recv(buf, count, dt, source, 0, m_comm, MPI_STATUS_IGNORE);
196  // ASSERTL0(status.MPI_ERROR == MPI_SUCCESS,
197  // "MPI error receiving data.");
198 }

References m_comm.

◆ v_RecvInit()

void Nektar::LibUtilities::CommMpi::v_RecvInit ( void buf,
int  count,
CommDataType  dt,
int  source,
CommRequestSharedPtr  request,
int  loc 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 428 of file CommMpi.cpp.

430 {
432  std::static_pointer_cast<CommRequestMpi>(request);
433  MPI_Recv_init(buf, count, dt, source, 0, m_comm, req->GetRequest(loc));
434 }

References CG_Iterations::loc, and m_comm.

◆ v_Scatter()

void Nektar::LibUtilities::CommMpi::v_Scatter ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
void recvbuf,
int  recvcount,
CommDataType  recvtype,
int  root 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 359 of file CommMpi.cpp.

362 {
363  int retval = MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
364  recvtype, root, m_comm);
365  ASSERTL0(retval == MPI_SUCCESS, "MPI error performing Scatter.");
366 }

References ASSERTL0, and m_comm.

◆ v_Send()

void Nektar::LibUtilities::CommMpi::v_Send ( void buf,
int  count,
CommDataType  dt,
int  dest 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 178 of file CommMpi.cpp.

179 {
180  if (MPISYNC)
181  {
182  MPI_Ssend(buf, count, dt, dest, 0, m_comm);
183  }
184  else
185  {
186  MPI_Send(buf, count, dt, dest, 0, m_comm);
187  }
188 }
#define MPISYNC
Definition: CommMpi.h:45

References m_comm, and MPISYNC.

◆ v_SendInit()

void Nektar::LibUtilities::CommMpi::v_SendInit ( void buf,
int  count,
CommDataType  dt,
int  dest,
CommRequestSharedPtr  request,
int  loc 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 412 of file CommMpi.cpp.

414 {
416  std::static_pointer_cast<CommRequestMpi>(request);
417  MPI_Send_init(buf, count, dt, dest, 0, m_comm, req->GetRequest(loc));
418 }

References CG_Iterations::loc, and m_comm.

◆ v_SendRecv()

void Nektar::LibUtilities::CommMpi::v_SendRecv ( void sendbuf,
int  sendcount,
CommDataType  sendtype,
int  dest,
void recvbuf,
int  recvcount,
CommDataType  recvtype,
int  source 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 203 of file CommMpi.cpp.

206 {
207  MPI_Status status;
208  int retval = MPI_Sendrecv(sendbuf, sendcount, sendtype, dest, 0, recvbuf,
209  recvcount, recvtype, source, 0, m_comm, &status);
210 
211  ASSERTL0(retval == MPI_SUCCESS,
212  "MPI error performing send-receive of data.");
213 }

References ASSERTL0, and m_comm.

◆ v_SendRecvReplace()

void Nektar::LibUtilities::CommMpi::v_SendRecvReplace ( void buf,
int  count,
CommDataType  dt,
int  pSendProc,
int  pRecvProc 
)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 218 of file CommMpi.cpp.

220 {
221  MPI_Status status;
222  int retval = MPI_Sendrecv_replace(buf, count, dt, pRecvProc, 0, pSendProc,
223  0, m_comm, &status);
224 
225  ASSERTL0(retval == MPI_SUCCESS,
226  "MPI error performing Send-Receive-Replace of data.");
227 }

References ASSERTL0, and m_comm.

◆ v_SplitComm()

void Nektar::LibUtilities::CommMpi::v_SplitComm ( int  pRows,
int  pColumns 
)
overrideprotectedvirtual

Processes are considered as a grid of size pRows*pColumns. Comm objects are created corresponding to the rows and columns of this grid. The row and column to which this process belongs is stored in m_commRow and m_commColumn.

Implements Nektar::LibUtilities::Comm.

Definition at line 461 of file CommMpi.cpp.

462 {
463  ASSERTL0(pRows * pColumns == m_size,
464  "Rows/Columns do not match comm size.");
465 
466  MPI_Comm newComm;
467 
468  // Compute row and column in grid.
469  int myCol = m_rank % pColumns;
470  int myRow = (m_rank - myCol) / pColumns;
471 
472  // Split Comm into rows - all processes with same myRow are put in
473  // the same communicator. The rank within this communicator is the
474  // column index.
475  MPI_Comm_split(m_comm, myRow, myCol, &newComm);
476  m_commRow = std::shared_ptr<Comm>(new CommMpi(newComm));
477 
478  // Split Comm into columns - all processes with same myCol are put
479  // in the same communicator. The rank within this communicator is
480  // the row index.
481  MPI_Comm_split(m_comm, myCol, myRow, &newComm);
482  m_commColumn = std::shared_ptr<Comm>(new CommMpi(newComm));
483 }
CommSharedPtr m_commColumn
Column communicator.
Definition: Comm.h:178
CommSharedPtr m_commRow
Row communicator.
Definition: Comm.h:177

References ASSERTL0, CommMpi(), m_comm, Nektar::LibUtilities::Comm::m_commColumn, Nektar::LibUtilities::Comm::m_commRow, m_rank, and Nektar::LibUtilities::Comm::m_size.

◆ v_SplitCommNode()

std::pair< CommSharedPtr, CommSharedPtr > Nektar::LibUtilities::CommMpi::v_SplitCommNode ( )
finalprotectedvirtual

Reimplemented from Nektar::LibUtilities::Comm.

Definition at line 508 of file CommMpi.cpp.

509 {
510  std::pair<CommSharedPtr, CommSharedPtr> ret;
511 
512 #if MPI_VERSION < 3
513  ASSERTL0(false, "Not implemented for non-MPI-3 versions.");
514 #else
515  // Create an intra-node communicator.
516  MPI_Comm nodeComm;
517  MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, m_rank,
518  MPI_INFO_NULL, &nodeComm);
519 
520  // For rank 0 of the intra-node communicator, split the main
521  // communicator. Everyone else will get a null communicator.
522  ret.first = std::shared_ptr<Comm>(new CommMpi(nodeComm));
523  ret.second = CommMpi::v_CommCreateIf(ret.first->GetRank() == 0);
524  if(ret.first->GetRank() == 0)
525  {
526  ret.second->SplitComm(1, ret.second->GetSize());
527  }
528 #endif
529 
530  return ret;
531 }
virtual CommSharedPtr v_CommCreateIf(int flag) final
Definition: CommMpi.cpp:488

References ASSERTL0, CommMpi(), m_rank, and v_CommCreateIf().

◆ v_StartAll()

void Nektar::LibUtilities::CommMpi::v_StartAll ( CommRequestSharedPtr  request)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 436 of file CommMpi.cpp.

437 {
439  std::static_pointer_cast<CommRequestMpi>(request);
440  MPI_Startall(req->GetNumRequest(), req->GetRequest(0));
441 }

◆ v_TreatAsRankZero()

bool Nektar::LibUtilities::CommMpi::v_TreatAsRankZero ( void  )
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 136 of file CommMpi.cpp.

137 {
138  return m_rank == 0;
139 }

References m_rank.

◆ v_WaitAll()

void Nektar::LibUtilities::CommMpi::v_WaitAll ( CommRequestSharedPtr  request)
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 443 of file CommMpi.cpp.

444 {
446  std::static_pointer_cast<CommRequestMpi>(request);
447  MPI_Waitall(req->GetNumRequest(), req->GetRequest(0), MPI_STATUSES_IGNORE);
448 }

◆ v_Wtime()

double Nektar::LibUtilities::CommMpi::v_Wtime ( )
finalprotectedvirtual

Implements Nektar::LibUtilities::Comm.

Definition at line 170 of file CommMpi.cpp.

171 {
172  return MPI_Wtime();
173 }

Member Data Documentation

◆ className

std::string Nektar::LibUtilities::CommMpi::className
static
Initial value:
"ParallelMPI", CommMpi::create, "Parallel communication using MPI.")
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
Definition: CommMpi.h:95
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
CommFactory & GetCommFactory()

Name of class.

Definition at line 101 of file CommMpi.h.

◆ m_comm

MPI_Comm Nektar::LibUtilities::CommMpi::m_comm
protected

◆ m_rank

int Nektar::LibUtilities::CommMpi::m_rank {}
protected