Nektar++
CommMpi.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File CommMpi.h
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: CommMpi header
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 #ifndef NEKTAR_LIB_UTILITIES_COMMMPI_H
35 #define NEKTAR_LIB_UTILITIES_COMMMPI_H
36 
37 #include <mpi.h>
38 #include <string>
39 
43 
44 #ifndef MPI_SYNC
45 #define MPISYNC 0
46 #else
47 #define MPISYNC 1
48 #endif
49 
50 namespace Nektar
51 {
52 namespace LibUtilities
53 {
54 // Forward declarations
55 class CommMpi;
56 
57 /// Pointer to a Communicator object.
58 typedef std::shared_ptr<CommMpi> CommMpiSharedPtr;
59 
60 /// Class for communicator request type
61 class CommRequestMpi final : public CommRequest
62 {
63 public:
64  /// Creates an instance of this class
65  inline explicit CommRequestMpi(int num) : m_num(num)
66  {
67  m_request = Array<OneD, MPI_Request>(num, MPI_REQUEST_NULL);
68  }
69 
70  /// Default destructor
71  inline ~CommRequestMpi() final = default;
72 
73  inline MPI_Request *GetRequest(int i)
74  {
75  return &m_request[i];
76  }
77 
78  inline int &GetNumRequest()
79  {
80  return m_num;
81  }
82 
83 private:
84  int m_num;
86 };
87 
88 typedef std::shared_ptr<CommRequestMpi> CommRequestMpiSharedPtr;
89 
90 /// A global linear system.
91 class CommMpi : public Comm
92 {
93 public:
94  /// Creates an instance of this class
95  static CommSharedPtr create(int narg, char *arg[])
96  {
98  }
99 
100  /// Name of class
101  LIB_UTILITIES_EXPORT static std::string className;
102 
103  LIB_UTILITIES_EXPORT CommMpi(int narg, char *arg[]);
104  LIB_UTILITIES_EXPORT virtual ~CommMpi() override;
105 
106  LIB_UTILITIES_EXPORT MPI_Comm GetComm();
107 
108 protected:
109  MPI_Comm m_comm;
110  int m_rank{};
111 
112  explicit CommMpi(MPI_Comm pComm);
113 
114  virtual void v_Finalise() override;
115  virtual int v_GetRank() final;
116  virtual void v_Block() final;
117  virtual double v_Wtime() final;
118  virtual bool v_TreatAsRankZero() final;
119  virtual bool v_IsSerial() final;
120  virtual std::tuple<int, int, int> v_GetVersion() final;
121  virtual void v_Send(void *buf, int count, CommDataType dt, int dest) final;
122  virtual void v_Recv(void *buf, int count, CommDataType dt,
123  int source) final;
124  virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype,
125  int dest, void *recvbuf, int recvcount,
126  CommDataType recvtype, int source) final;
127  virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt,
128  int pSendProc, int pRecvProc) final;
129  virtual void v_AllReduce(void *buf, int count, CommDataType dt,
130  enum ReduceOperator pOp) final;
131  virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
132  void *recvbuf, int recvcount,
133  CommDataType recvtype) final;
134  virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[],
135  CommDataType sendtype, void *recvbuf,
136  int recvcounts[], int rdispls[],
137  CommDataType recvtype) final;
138  virtual void v_AllGather(void *sendbuf, int sendcount,
139  CommDataType sendtype, void *recvbuf,
140  int recvcount, CommDataType recvtype) final;
141  virtual void v_AllGatherv(void *sendbuf, int sendcount,
142  CommDataType sendtype, void *recvbuf,
143  int recvcounts[], int rdispls[],
144  CommDataType recvtype) final;
145  virtual void v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[],
146  CommDataType recvtype) final;
147  virtual void v_Bcast(void *buffer, int count, CommDataType dt,
148  int root) final;
149  virtual void v_Exscan(Array<OneD, unsigned long long> &pData,
150  enum ReduceOperator pOp,
151  Array<OneD, unsigned long long> &ans) final;
152 
153  virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype,
154  void *recvbuf, int recvcount, CommDataType recvtype,
155  int root) final;
156  virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype,
157  void *recvbuf, int recvcount, CommDataType recvtype,
158  int root) final;
159 
160  virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[],
161  const int sourceweights[],
162  int reorder) final;
163  virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[],
164  int sensdispls[], CommDataType sendtype,
165  void *recvbuf, int recvcounts[],
166  int rdispls[],
167  CommDataType recvtype) final;
168  virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest,
169  CommRequestSharedPtr request, int loc) final;
170  virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest,
171  CommRequestSharedPtr request, int loc) final;
172  virtual void v_Irecv(void *buf, int count, CommDataType dt, int source,
173  CommRequestSharedPtr request, int loc) final;
174  virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source,
175  CommRequestSharedPtr request, int loc) final;
176  virtual void v_StartAll(CommRequestSharedPtr request) final;
177  virtual void v_WaitAll(CommRequestSharedPtr request) final;
178  virtual CommRequestSharedPtr v_CreateRequest(int num) final;
179 
180  virtual void v_SplitComm(int pRows, int pColumns) override;
181  virtual CommSharedPtr v_CommCreateIf(int flag) final;
182 
183  virtual std::pair<CommSharedPtr, CommSharedPtr> v_SplitCommNode() final;
184 
185 };
186 } // namespace LibUtilities
187 } // namespace Nektar
188 
189 #endif
#define LIB_UTILITIES_EXPORT
Base communications class.
Definition: Comm.h:90
A global linear system.
Definition: CommMpi.h:92
virtual void v_Block() final
Definition: CommMpi.cpp:162
virtual void v_WaitAll(CommRequestSharedPtr request) final
Definition: CommMpi.cpp:443
virtual bool v_IsSerial() final
Definition: CommMpi.cpp:144
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition: CommMpi.cpp:262
virtual CommRequestSharedPtr v_CreateRequest(int num) final
Definition: CommMpi.cpp:450
CommMpi(int narg, char *arg[])
Definition: CommMpi.cpp:53
virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[], const int sourceweights[], int reorder) final
Definition: CommMpi.cpp:368
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root) final
Definition: CommMpi.cpp:316
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:297
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc) final
Definition: CommMpi.cpp:218
virtual CommSharedPtr v_CommCreateIf(int flag) final
Definition: CommMpi.cpp:488
virtual std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode() final
Definition: CommMpi.cpp:508
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
Definition: CommMpi.cpp:203
virtual double v_Wtime() final
Definition: CommMpi.cpp:170
virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:385
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition: CommMpi.cpp:288
virtual void v_Recv(void *buf, int count, CommDataType dt, int source) final
Definition: CommMpi.cpp:193
virtual void v_StartAll(CommRequestSharedPtr request) final
Definition: CommMpi.cpp:436
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
Definition: CommMpi.cpp:232
virtual void v_Finalise() override
Definition: CommMpi.cpp:112
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:420
virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:404
virtual int v_GetRank() final
Definition: CommMpi.cpp:128
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans) final
Definition: CommMpi.cpp:322
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition: CommMpi.cpp:349
static std::string className
Name of class.
Definition: CommMpi.h:101
virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:428
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
Definition: CommMpi.h:95
virtual void v_SplitComm(int pRows, int pColumns) override
Definition: CommMpi.cpp:461
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:274
virtual bool v_TreatAsRankZero() final
Definition: CommMpi.cpp:136
virtual void v_Send(void *buf, int count, CommDataType dt, int dest) final
Definition: CommMpi.cpp:178
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition: CommMpi.cpp:359
virtual ~CommMpi() override
Definition: CommMpi.cpp:91
virtual std::tuple< int, int, int > v_GetVersion() final
Definition: CommMpi.cpp:149
virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:412
Class for communicator request type.
Definition: Comm.h:78
Class for communicator request type.
Definition: CommMpi.h:62
CommRequestMpi(int num)
Creates an instance of this class.
Definition: CommMpi.h:65
Array< OneD, MPI_Request > m_request
Definition: CommMpi.h:85
MPI_Request * GetRequest(int i)
Definition: CommMpi.h:73
~CommRequestMpi() final=default
Default destructor.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
array buffer
Definition: GsLib.hpp:61
unsigned int CommDataType
Definition: CommDataType.h:70
std::shared_ptr< CommMpi > CommMpiSharedPtr
Pointer to a Communicator object.
Definition: CommMpi.h:55
std::shared_ptr< CommRequest > CommRequestSharedPtr
Definition: Comm.h:86
std::shared_ptr< CommRequestMpi > CommRequestMpiSharedPtr
Definition: CommMpi.h:88
ReduceOperator
Type of operation to perform in AllReduce.
Definition: Comm.h:67
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1