Nektar++
Loading...
Searching...
No Matches
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(const 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(const 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(const void *sendbuf, int sendcount, CommDataType sendtype,
131 void *recvbuf, int recvcount, CommDataType recvtype) final;
132 void v_AlltoAllv(const void *sendbuf, const int *sendcounts,
133 const int *senddispls, CommDataType sendtype,
134 void *recvbuf, const int *recvcounts,
135 const int *recvdispls, CommDataType recvtype) final;
136
137 void v_AllGather(const void *sendbuf, int sendcount, CommDataType sendtype,
138 void *recvbuf, int recvcount, CommDataType recvtype) final;
139 void v_AllGatherv(const void *sendbuf, int sendcount, CommDataType sendtype,
140 void *recvbuf, const int *recvcounts,
141 const int *recvdispls, CommDataType recvtype) final;
142 void v_AllGatherv(void *recvbuf, const int *recvcounts,
143 const int *recvdispls, CommDataType recvtype) final;
144
145 void v_Bcast(void *buffer, int count, CommDataType dt, int root) final;
146 void v_Gather(const void *sendbuf, int sendcount, CommDataType sendtype,
147 void *recvbuf, int recvcount, CommDataType recvtype,
148 int root) final;
149 void v_Scatter(const void *sendbuf, int sendcount, CommDataType sendtype,
150 void *recvbuf, int recvcount, CommDataType recvtype,
151 int root) final;
152
153 void v_DistGraphCreateAdjacent(int indegree, const int *sources,
154 const int *sourceweights, int reorder) final;
155 void v_NeighborAlltoAllv(const void *sendbuf, const int *sendcounts,
156 const int *senddispls, CommDataType sendtype,
157 void *recvbuf, const int *recvcounts,
158 const int *recvdispls,
159 CommDataType recvtype) final;
160
161 void v_Irsend(const void *buf, int count, CommDataType dt, int dest,
162 CommRequestSharedPtr request, int loc) final;
163 void v_Isend(const void *buf, int count, CommDataType dt, int dest,
164 CommRequestSharedPtr request, int loc) final;
165 void v_SendInit(const void *buf, int count, CommDataType dt, int dest,
166 CommRequestSharedPtr request, int loc) final;
167 void v_Irecv(void *buf, int count, CommDataType dt, int source,
168 CommRequestSharedPtr request, int loc) final;
169 void v_RecvInit(void *buf, int count, CommDataType dt, int source,
170 CommRequestSharedPtr request, int loc) final;
171
172 void v_StartAll(CommRequestSharedPtr request) final;
173 void v_WaitAll(CommRequestSharedPtr request) final;
174
176 void v_SplitComm(int pRows, int pColumns, int pTime) override;
177 CommSharedPtr v_CommCreateIf(int flag) final;
179};
180} // namespace Nektar::LibUtilities
181
182#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:477
void v_Gather(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition CommMpi.cpp:339
void v_SendInit(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition CommMpi.cpp:431
CommRequestSharedPtr v_CreateRequest(int num) final
Definition CommMpi.cpp:491
void v_AllGather(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition CommMpi.cpp:290
void v_Isend(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition CommMpi.cpp:420
void v_Bcast(void *buffer, int count, CommDataType dt, int root) final
Definition CommMpi.cpp:329
void v_Scatter(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype, int root) final
Definition CommMpi.cpp:352
void v_AllGatherv(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
Definition CommMpi.cpp:303
CommSharedPtr v_CommCreateIf(int flag) final
Definition CommMpi.cpp:571
void v_Send(const void *buf, int count, CommDataType dt, int dest) final
Definition CommMpi.cpp:194
std::pair< CommSharedPtr, CommSharedPtr > v_SplitCommNode() final
Definition CommMpi.cpp:594
void v_SendRecv(const void *sendbuf, int sendcount, CommDataType sendtype, int dest, void *recvbuf, int recvcount, CommDataType recvtype, int source) final
Definition CommMpi.cpp:217
void v_NeighborAlltoAllv(const void *sendbuf, const int *sendcounts, const int *senddispls, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
Definition CommMpi.cpp:385
void v_AlltoAllv(const void *sendbuf, const int *sendcounts, const int *senddispls, CommDataType sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, CommDataType recvtype) final
Definition CommMpi.cpp:275
void v_Recv(void *buf, int count, CommDataType dt, int source) final
Definition CommMpi.cpp:209
void v_StartAll(CommRequestSharedPtr request) final
Definition CommMpi.cpp:464
void v_Irsend(const void *buf, int count, CommDataType dt, int dest, CommRequestSharedPtr request, int loc) final
Definition CommMpi.cpp:409
void v_DistGraphCreateAdjacent(int indegree, const int *sources, const int *sourceweights, int reorder) final
Definition CommMpi.cpp:365
void v_AllReduce(void *buf, int count, CommDataType dt, enum ReduceOperator pOp) final
Definition CommMpi.cpp:232
void v_Irecv(void *buf, int count, CommDataType dt, int source, CommRequestSharedPtr request, int loc) final
Definition CommMpi.cpp:442
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:453
static CommSharedPtr create(int narg, char *arg[])
Creates an instance of this class.
Definition CommMpi.h:93
void v_AlltoAll(const void *sendbuf, int sendcount, CommDataType sendtype, void *recvbuf, int recvcount, CommDataType recvtype) final
Definition CommMpi.cpp:262
void v_SplitComm(int pRows, int pColumns, int pTime) override
Definition CommMpi.cpp:502
std::tuple< int, int, int > v_GetVersion() final
Definition CommMpi.cpp:165
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.
unsigned int CommDataType
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
STL namespace.