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
51{
52// Forward declarations
53class CommMpi;
54
55/// Pointer to a Communicator object.
56typedef std::shared_ptr<CommMpi> CommMpiSharedPtr;
57
58/// Class for communicator request type
59class CommRequestMpi final : public CommRequest
60{
61public:
62 /// Creates an instance of this class
63 inline explicit CommRequestMpi(int num) : m_num(num)
64 {
65 m_request = Array<OneD, MPI_Request>(num, MPI_REQUEST_NULL);
66 }
67
68 /// Default destructor
69 inline ~CommRequestMpi() final = default;
70
71 inline MPI_Request *GetRequest(int i)
72 {
73 return &m_request[i];
74 }
75
76 inline int &GetNumRequest()
77 {
78 return m_num;
79 }
80
81private:
82 int m_num;
84};
85
86typedef std::shared_ptr<CommRequestMpi> CommRequestMpiSharedPtr;
87
88/// A global linear system.
89class CommMpi : public Comm
90{
91public:
92 /// Creates an instance of this class
93 static CommSharedPtr create(int narg, char *arg[])
94 {
96 }
97
98 /// Name of class
99 LIB_UTILITIES_EXPORT static std::string className;
100
101 LIB_UTILITIES_EXPORT CommMpi(int narg, char *arg[]);
103
104 LIB_UTILITIES_EXPORT MPI_Comm GetComm();
105
106protected:
107 MPI_Comm m_comm;
108 int m_rank{};
110
111 explicit CommMpi(MPI_Comm pComm);
112
113 void v_Finalise() override;
114 int v_GetRank() final;
115 bool v_TreatAsRankZero() final;
116 bool v_IsSerial() final;
117 std::tuple<int, int, int> v_GetVersion() final;
118 void v_Block() final;
119 double v_Wtime() final;
120
121 void v_Send(void *buf, int count, CommDataType dt, int dest) final;
122 void v_Recv(void *buf, int count, CommDataType dt, int source) final;
123 void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype,
124 int dest, void *recvbuf, int recvcount,
125 CommDataType recvtype, int source) final;
126
127 void v_AllReduce(void *buf, int count, CommDataType dt,
128 enum ReduceOperator pOp) final;
129
130 void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
131 void *recvbuf, int recvcount, CommDataType recvtype) final;
132 void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[],
133 CommDataType sendtype, void *recvbuf, int recvcounts[],
134 int rdispls[], CommDataType recvtype) final;
135
136 void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype,
137 void *recvbuf, int recvcount, CommDataType recvtype) final;
138 void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype,
139 void *recvbuf, int recvcounts[], int rdispls[],
140 CommDataType recvtype) final;
141 void v_AllGatherv(void *recvbuf, int recvcounts[], int rdispls[],
142 CommDataType recvtype) final;
143
144 void v_Bcast(void *buffer, int count, CommDataType dt, int root) final;
145 void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype,
146 void *recvbuf, int recvcount, CommDataType recvtype,
147 int root) final;
148 void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype,
149 void *recvbuf, int recvcount, CommDataType recvtype,
150 int root) final;
151
152 void v_DistGraphCreateAdjacent(int indegree, const int sources[],
153 const int sourceweights[],
154 int reorder) final;
155 void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[],
156 CommDataType sendtype, void *recvbuf,
157 int recvcounts[], int rdispls[],
158 CommDataType recvtype) final;
159
160 void v_Irsend(void *buf, int count, CommDataType dt, int dest,
161 CommRequestSharedPtr request, int loc) final;
162 void v_Isend(void *buf, int count, CommDataType dt, int dest,
163 CommRequestSharedPtr request, int loc) final;
164 void v_SendInit(void *buf, int count, CommDataType dt, int dest,
165 CommRequestSharedPtr request, int loc) final;
166 void v_Irecv(void *buf, int count, CommDataType dt, int source,
167 CommRequestSharedPtr request, int loc) final;
168 void v_RecvInit(void *buf, int count, CommDataType dt, int source,
169 CommRequestSharedPtr request, int loc) final;
170
171 void v_StartAll(CommRequestSharedPtr request) final;
172 void v_WaitAll(CommRequestSharedPtr request) final;
173
175 void v_SplitComm(int pRows, int pColumns, int pTime) override;
176 CommSharedPtr v_CommCreateIf(int flag) final;
177 std::pair<CommSharedPtr, CommSharedPtr> v_SplitCommNode() final;
178};
179} // namespace Nektar::LibUtilities
180
181#endif
#define LIB_UTILITIES_EXPORT
Base communications class.
Definition: Comm.h:88
A global linear system.
Definition: CommMpi.h:90
void v_WaitAll(CommRequestSharedPtr request) final
Definition: CommMpi.cpp:461
void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition: CommMpi.cpp:253
CommRequestSharedPtr v_CreateRequest(int num) final
Definition: CommMpi.cpp:475
CommMpi(int narg, char *arg[])
Definition: CommMpi.cpp:50
void v_DistGraphCreateAdjacent(int indegree, const int sources[], const int sourceweights[], int reorder) final
Definition: CommMpi.cpp:352
void v_Bcast(void *buffer, int count, CommDataType dt, int root) final
Definition: CommMpi.cpp:316
void v_AllGatherv(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:291
CommSharedPtr v_CommCreateIf(int flag) final
Definition: CommMpi.cpp:549
std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode() final
Definition: CommMpi.cpp:572
void v_SendRecv(void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
Definition: CommMpi.cpp:208
void v_NeighborAlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:372
void v_AllGather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition: CommMpi.cpp:279
void v_Recv(void *buf, int count, CommDataType dt, int source) final
Definition: CommMpi.cpp:200
void v_StartAll(CommRequestSharedPtr request) final
Definition: CommMpi.cpp:448
void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
Definition: CommMpi.cpp:223
void v_Finalise() override
Definition: CommMpi.cpp:116
void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:426
void v_Irsend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:393
void v_Gather(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition: CommMpi.cpp:326
static std::string className
Name of class.
Definition: CommMpi.h:99
void v_RecvInit(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:437
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
Definition: CommMpi.h:93
void v_Isend(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:404
void v_AlltoAllv(void *sendbuf, int sendcounts[], int sensdispls[], CommDataType sendtype, void *recvbuf, int recvcounts[], int rdispls[], CommDataType recvtype) final
Definition: CommMpi.cpp:265
bool v_TreatAsRankZero() final
Definition: CommMpi.cpp:140
void v_Send(void *buf, int count, CommDataType dt, int dest) final
Definition: CommMpi.cpp:185
void v_SplitComm(int pRows, int pColumns, int pTime) override
Definition: CommMpi.cpp:486
void v_Scatter(void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition: CommMpi.cpp:339
std::tuple< int, int, int > v_GetVersion() final
Definition: CommMpi.cpp:156
void v_SendInit(void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition: CommMpi.cpp:415
Class for communicator request type.
Definition: Comm.h:76
Class for communicator request type.
Definition: CommMpi.h:60
CommRequestMpi(int num)
Creates an instance of this class.
Definition: CommMpi.h:63
MPI_Request * GetRequest(int i)
Definition: CommMpi.h:71
Array< OneD, MPI_Request > m_request
Definition: CommMpi.h:83
~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:81
unsigned int CommDataType
Definition: CommDataType.h:65
std::shared_ptr< CommMpi > CommMpiSharedPtr
Pointer to a Communicator object.
Definition: CommMpi.h:56
std::shared_ptr< CommRequest > CommRequestSharedPtr
Definition: Comm.h:84
std::shared_ptr< CommRequestMpi > CommRequestMpiSharedPtr
Definition: CommMpi.h:86
ReduceOperator
Type of operation to perform in AllReduce.
Definition: Comm.h:65
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55