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{};
112 
113  explicit CommMpi(MPI_Comm pComm);
114 
115  virtual void v_Finalise() override;
116  virtual int v_GetRank() final;
117  virtual void v_Block() final;
118  virtual double v_Wtime() final;
119  virtual bool v_TreatAsRankZero() final;
120  virtual bool v_IsSerial() final;
121  virtual std::tuple<int, int, int> v_GetVersion() final;
122  virtual void v_Send(void *buf, int count, CommDataType dt, int dest) final;
123  virtual void v_Recv(void *buf, int count, CommDataType dt,
124  int source) final;
125  virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype,
126  int dest, void *recvbuf, int recvcount,
127  CommDataType recvtype, int source) final;
128  virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt,
129  int pSendProc, int pRecvProc) final;
130  virtual void v_AllReduce(void *buf, int count, CommDataType dt,
131  enum ReduceOperator pOp) final;
132  virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
133  void *recvbuf, int recvcount,
134  CommDataType recvtype) final;
135  virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[],
136  CommDataType sendtype, void *recvbuf,
137  int recvcounts[], int rdispls[],
138  CommDataType recvtype) final;
139  virtual void v_AllGather(void *sendbuf, int sendcount,
140  CommDataType sendtype, void *recvbuf,
141  int recvcount, CommDataType recvtype) final;
142  virtual void v_AllGatherv(void *sendbuf, int sendcount,
143  CommDataType sendtype, void *recvbuf,
144  int recvcounts[], int rdispls[],
145  CommDataType recvtype) final;
146  virtual void v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[],
147  CommDataType recvtype) final;
148  virtual void v_Bcast(void *buffer, int count, CommDataType dt,
149  int root) final;
150  virtual void v_Exscan(Array<OneD, unsigned long long> &pData,
151  enum ReduceOperator pOp,
152  Array<OneD, unsigned long long> &ans) final;
153 
154  virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype,
155  void *recvbuf, int recvcount, CommDataType recvtype,
156  int root) final;
157  virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype,
158  void *recvbuf, int recvcount, CommDataType recvtype,
159  int root) final;
160 
161  virtual void v_DistGraphCreateAdjacent(int indegree, const int sources[],
162  const int sourceweights[],
163  int reorder) final;
164  virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[],
165  int sensdispls[], CommDataType sendtype,
166  void *recvbuf, int recvcounts[],
167  int rdispls[],
168  CommDataType recvtype) final;
169  virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest,
170  CommRequestSharedPtr request, int loc) final;
171  virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest,
172  CommRequestSharedPtr request, int loc) final;
173  virtual void v_Irecv(void *buf, int count, CommDataType dt, int source,
174  CommRequestSharedPtr request, int loc) final;
175  virtual void v_RecvInit(void *buf, int count, CommDataType dt, int source,
176  CommRequestSharedPtr request, int loc) final;
177  virtual void v_StartAll(CommRequestSharedPtr request) final;
178  virtual void v_WaitAll(CommRequestSharedPtr request) final;
179  virtual CommRequestSharedPtr v_CreateRequest(int num) final;
180 
181  virtual void v_SplitComm(int pRows, int pColumns) override;
182  virtual CommSharedPtr v_CommCreateIf(int flag) final;
183 
184  virtual std::pair<CommSharedPtr, CommSharedPtr> v_SplitCommNode() final;
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:169
virtual void v_WaitAll(CommRequestSharedPtr request) final
Definition: CommMpi.cpp:450
virtual bool v_IsSerial() final
Definition: CommMpi.cpp:151
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition: CommMpi.cpp:269
virtual CommRequestSharedPtr v_CreateRequest(int num) final
Definition: CommMpi.cpp:457
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:375
virtual void v_Bcast(void *buffer, int count, CommDataType dt, int root) final
Definition: CommMpi.cpp:323
virtual void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:304
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt, int pSendProc, int pRecvProc) final
Definition: CommMpi.cpp:225
virtual CommSharedPtr v_CommCreateIf(int flag) final
Definition: CommMpi.cpp:495
virtual std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode() final
Definition: CommMpi.cpp:515
virtual void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
Definition: CommMpi.cpp:210
virtual double v_Wtime() final
Definition: CommMpi.cpp:177
virtual void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:392
virtual void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition: CommMpi.cpp:295
virtual void v_Recv(void *buf, int count, CommDataType dt, int source) final
Definition: CommMpi.cpp:200
virtual void v_StartAll(CommRequestSharedPtr request) final
Definition: CommMpi.cpp:443
virtual void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
Definition: CommMpi.cpp:239
virtual void v_Finalise() override
Definition: CommMpi.cpp:119
virtual void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:427
virtual void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:411
virtual int v_GetRank() final
Definition: CommMpi.cpp:135
virtual void v_Exscan(Array< OneD, unsigned long long > &pData, enum ReduceOperator pOp, Array< OneD, unsigned long long > &ans) final
Definition: CommMpi.cpp:329
virtual void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition: CommMpi.cpp:356
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:435
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:468
virtual void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:281
virtual bool v_TreatAsRankZero() final
Definition: CommMpi.cpp:143
virtual void v_Send(void *buf, int count, CommDataType dt, int dest) final
Definition: CommMpi.cpp:185
virtual void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition: CommMpi.cpp:366
virtual ~CommMpi() override
Definition: CommMpi.cpp:98
virtual std::tuple< int, int, int > v_GetVersion() final
Definition: CommMpi.cpp:156
virtual void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:419
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:83
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