Nektar++
AssemblyCommDG.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: AssemblyCommDG.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: Parallel communication methods for DG with MPI, header file
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef MULTIREGIONS_ASSEMBLY_COMM_DG_H
36#define MULTIREGIONS_ASSEMBLY_COMM_DG_H
37
40
42{
43
44/**
45 * The ExchangeMethod classes contain the required structure to distribute the
46 * Fwd trace of partition edges to the matching locations in the Bwd trace in
47 * the corresponding adjacent partitions. This allows for communication between
48 * neighbouring partitions in the physical mesh by exchanging quadrature point
49 * values.
50 */
52{
53public:
54 /// Default constructor
56
57 /// Default destructor
59
60 /**
61 * Perform MPI comm exchange taking the Fwd trace and
62 * sending partition edge trace values to the matching locations in the
63 * Bwd trace of corresponding adjacent partitions.
64 *
65 * @param[in] testFwd The values to send to adjacent partitions
66 * @param[out] testBwd The values received from adjacent partitions
67 */
69 const Array<OneD, NekDouble> &testFwd,
70 Array<OneD, NekDouble> &testBwd) = 0;
71};
72
73typedef std::shared_ptr<ExchangeMethod> ExchangeMethodSharedPtr;
74
75/**
76 * If parallel operation is not indicated then use the Serial subclass which
77 * does not perform any exchange.
78 */
79class Serial final : public ExchangeMethod
80{
81public:
82 /// Default constructor
84
86 [[maybe_unused]] const Array<OneD, NekDouble> &testFwd,
87 [[maybe_unused]] Array<OneD, NekDouble> &testBwd) final
88 {
89 }
90};
91
92/**
93 * Uses the MPI_AllToAll collective operation to perform the exchange of
94 * quadrature values. This does not allow for varying exchange array sizes so
95 * padding is used to ensure all partitions send/receive the same length array.
96 * All ranks communicate full array sizes to all other ranks. One collective
97 * operation is posted on each rank which requires communication.
98 */
99class AllToAll final : public ExchangeMethod
100{
101public:
102 /// Default constructor.
104 const LibUtilities::CommSharedPtr &comm, const int &maxQuad,
105 const int &nRanks,
106 const std::map<int, std::vector<int>> &rankSharedEdges,
107 const std::map<int, std::vector<int>> &edgeToTrace);
108
110 const Array<OneD, NekDouble> &testFwd,
111 Array<OneD, NekDouble> &testBwd) final;
112
113private:
114 /// Communicator
116 /// Max number of quadrature points in an element
117 int m_maxQuad = 0;
118 /// Number of ranks/processes/partitions
119 int m_nRanks = 0;
120 /// List of trace map indices of the quad points to exchange
121 std::vector<int> m_allEdgeIndex;
122 /// Largest shared partition edge
123 int m_maxCount = 0;
124};
125
126/**
127 * Uses the MPI_AllToAllV collective operation to perform the exchange of
128 * quadrature values. This allows for varying exchange array sizes to minimise
129 * communication data size. All ranks communicate to all other ranks, however
130 * the array size can be 0 to avoid unnecessary data transfer. One collective
131 * peration is posted on each rank which requires communication.
132 */
133class AllToAllV final : public ExchangeMethod
134{
135public:
136 /// Default constructor.
138 const LibUtilities::CommSharedPtr &comm,
139 const std::map<int, std::vector<int>> &rankSharedEdges,
140 const std::map<int, std::vector<int>> &edgeToTrace, const int &nRanks);
141
143 const Array<OneD, NekDouble> &testFwd,
144 Array<OneD, NekDouble> &testBwd) final;
145
146private:
147 /// Communicator
149 /// List of trace map indices of the quad points to exchange
150 std::vector<int> m_allVEdgeIndex;
151 /// List of counts for MPI_alltoallv
153 /// List of displacements for MPI_alltoallv
155};
156
157/**
158 * Uses the MPI_NeighborAllToAllV collective operation to perform the exchange
159 * of quadrature values. This allows for varying exchange array sizes to
160 * minimise communication data size. Ranks only communicate with ranks with
161 * which they need to exchange data, i.e. are adjacent in the mesh or share a
162 * periodic boundary condition, this further minimises unnecessary data transfer
163 * over just reducing array sizes to 0 such as in MPI_AllToAllV. One collective
164 * operation is posted on each rank which requires communication.
165 */
167{
168public:
169 /// Default constructor.
171 const LibUtilities::CommSharedPtr &comm,
172 const std::map<int, std::vector<int>> &rankSharedEdges,
173 const std::map<int, std::vector<int>> &edgeToTrace);
174
176 const Array<OneD, NekDouble> &testFwd,
177 Array<OneD, NekDouble> &testBwd) final;
178
179private:
180 /// Communicator
182 /// List of displacements
184 /// List of trace map indices of the quad points to exchange
185 std::vector<int> m_edgeTraceIndex;
186 /// List of counts
188};
189
190/**
191 * Uses persistent MPI_Irecv and MPI_Isend operations to perform the exchange of
192 * quadrature values. This allows for varying exchange array sizes to minimise
193 * communication data size. Ranks only communicate with ranks with which they
194 * need to exchange data, i.e. are adjacent in the mesh or share a periodic
195 * boundary condition. On each rank there are 'n' receives and 'n' sends posted
196 * where 'n' is the number of other ranks with which communication is needed.
197 * We use persistent communication methods to reduce overhead.
198 */
199class Pairwise final : public ExchangeMethod
200{
201public:
203 const LibUtilities::CommSharedPtr &comm,
204 const std::map<int, std::vector<int>> &rankSharedEdges,
205 const std::map<int, std::vector<int>> &edgeToTrace);
206
208 const Array<OneD, NekDouble> &testFwd,
209 Array<OneD, NekDouble> &testBwd) final;
210
211private:
212 /// Communicator
214 /// List of trace index locations in recv/send buff
216 /// Receive buffer for exchange
218 /// Send buffer for exchange
220 /// List of receive requests
222 /// List of send requests
224};
225
226/**
227 * @brief Implements communication for populating forward and backwards spaces
228 * across processors in the discontinuous Galerkin routines.
229 *
230 * The AssemblyCommDG class constructs various exchange methods for performing
231 * the action of communicating trace data from the forwards space of one
232 * processor to the backwards space of the corresponding neighbour element, and
233 * vice versa.
234 *
235 * This class initialises the structure for all exchange methods and then times
236 * to determine the fastest method for the particular system configuration, if
237 * running in serial configuration it assigns the #Serial exchange method. It
238 * then acts as a pass through to the chosen exchange method for the
239 * #PerformExchange function.
240 */
242{
243public:
244 /// Default destructor
246
247 // Constructor for MPI communication methods
249 const ExpList &locExp, const ExpListSharedPtr &trace,
251 &elmtToTrace,
252 const Array<OneD, const ExpListSharedPtr> &bndCondExp,
254 &bndCond,
255 const PeriodicMap &perMap);
256
257 /**
258 * @brief Perform the trace exchange between processors, given the forwards
259 * and backwards spaces.
260 *
261 * @param testFwd Local forwards space of the trace (which will be sent)
262 * @param testBwd Local backwards space of the trace (which will receive
263 * contributions)
264 */
266 const Array<OneD, NekDouble> &testFwd, Array<OneD, NekDouble> &testBwd)
267 {
268 m_exchange->PerformExchange(testFwd, testBwd);
269 }
270
271private:
272 /// Chosen exchange method (either fastest parallel or serial)
274 /// Max number of quadrature points in an element
275 int m_maxQuad = 0;
276 /// Number of ranks/processes/partitions
277 int m_nRanks = 0;
278 /// Map of process to shared edge IDs
279 std::map<int, std::vector<int>> m_rankSharedEdges;
280 /// Map of edge ID to quad point trace indices
281 std::map<int, std::vector<int>> m_edgeToTrace;
282
283 /// Initalises the structure for the MPI communication
285 const ExpList &locExp, const ExpListSharedPtr &trace,
287 &elmtToTrace,
288 const Array<OneD, const ExpListSharedPtr> &bndCondExp,
290 &bndCond,
291 const PeriodicMap &perMap, const LibUtilities::CommSharedPtr &comm);
292
293 /// Timing of the MPI exchange method.
294 static std::tuple<NekDouble, NekDouble, NekDouble> Timing(
295 const LibUtilities::CommSharedPtr &comm, const int &count,
296 const int &num, const ExchangeMethodSharedPtr &f);
297};
298
299typedef std::shared_ptr<AssemblyCommDG> AssemblyCommDGSharedPtr;
300
301} // namespace Nektar::MultiRegions
302
303#endif
#define MULTI_REGIONS_EXPORT
LibUtilities::CommSharedPtr m_comm
Communicator.
std::vector< int > m_allEdgeIndex
List of trace map indices of the quad points to exchange.
AllToAll(const LibUtilities::CommSharedPtr &comm, const int &maxQuad, const int &nRanks, const std::map< int, std::vector< int > > &rankSharedEdges, const std::map< int, std::vector< int > > &edgeToTrace)
Default constructor.
int m_nRanks
Number of ranks/processes/partitions.
int m_maxQuad
Max number of quadrature points in an element.
void PerformExchange(const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd) final
int m_maxCount
Largest shared partition edge.
AllToAllV(const LibUtilities::CommSharedPtr &comm, const std::map< int, std::vector< int > > &rankSharedEdges, const std::map< int, std::vector< int > > &edgeToTrace, const int &nRanks)
Default constructor.
std::vector< int > m_allVEdgeIndex
List of trace map indices of the quad points to exchange.
void PerformExchange(const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd) final
LibUtilities::CommSharedPtr m_comm
Communicator.
Array< OneD, int > m_allVSendCount
List of counts for MPI_alltoallv.
Array< OneD, int > m_allVSendDisp
List of displacements for MPI_alltoallv.
Implements communication for populating forward and backwards spaces across processors in the discont...
void PerformExchange(const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd)
Perform the trace exchange between processors, given the forwards and backwards spaces.
int m_maxQuad
Max number of quadrature points in an element.
std::map< int, std::vector< int > > m_edgeToTrace
Map of edge ID to quad point trace indices.
AssemblyCommDG(const ExpList &locExp, const ExpListSharedPtr &trace, const Array< OneD, Array< OneD, LocalRegions::ExpansionSharedPtr > > &elmtToTrace, const Array< OneD, const ExpListSharedPtr > &bndCondExp, const Array< OneD, const SpatialDomains::BoundaryConditionShPtr > &bndCond, const PeriodicMap &perMap)
int m_nRanks
Number of ranks/processes/partitions.
~AssemblyCommDG()=default
Default destructor.
static std::tuple< NekDouble, NekDouble, NekDouble > Timing(const LibUtilities::CommSharedPtr &comm, const int &count, const int &num, const ExchangeMethodSharedPtr &f)
Timing of the MPI exchange method.
void InitialiseStructure(const ExpList &locExp, const ExpListSharedPtr &trace, const Array< OneD, Array< OneD, LocalRegions::ExpansionSharedPtr > > &elmtToTrace, const Array< OneD, const ExpListSharedPtr > &bndCondExp, const Array< OneD, const SpatialDomains::BoundaryConditionShPtr > &bndCond, const PeriodicMap &perMap, const LibUtilities::CommSharedPtr &comm)
Initalises the structure for the MPI communication.
std::map< int, std::vector< int > > m_rankSharedEdges
Map of process to shared edge IDs.
ExchangeMethodSharedPtr m_exchange
Chosen exchange method (either fastest parallel or serial)
ExchangeMethod()=default
Default constructor.
virtual ~ExchangeMethod()=default
Default destructor.
virtual void PerformExchange(const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd)=0
Base class for all multi-elemental spectral/hp expansions.
Definition: ExpList.h:98
NeighborAllToAllV(const LibUtilities::CommSharedPtr &comm, const std::map< int, std::vector< int > > &rankSharedEdges, const std::map< int, std::vector< int > > &edgeToTrace)
Default constructor.
void PerformExchange(const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd) final
std::vector< int > m_edgeTraceIndex
List of trace map indices of the quad points to exchange.
Array< OneD, int > m_sendDisp
List of displacements.
LibUtilities::CommSharedPtr m_comm
Communicator.
Array< OneD, int > m_sendCount
List of counts.
LibUtilities::CommRequestSharedPtr m_sendRequest
List of send requests.
Pairwise(const LibUtilities::CommSharedPtr &comm, const std::map< int, std::vector< int > > &rankSharedEdges, const std::map< int, std::vector< int > > &edgeToTrace)
Array< OneD, NekDouble > m_sendBuff
Send buffer for exchange.
Array< OneD, NekDouble > m_recvBuff
Receive buffer for exchange.
LibUtilities::CommRequestSharedPtr m_recvRequest
List of receive requests.
Array< OneD, int > m_edgeTraceIndex
List of trace index locations in recv/send buff.
void PerformExchange(const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd) final
LibUtilities::CommSharedPtr m_comm
Communicator.
void PerformExchange(const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd) final
Serial()=default
Default constructor.
std::shared_ptr< CommRequest > CommRequestSharedPtr
Definition: Comm.h:84
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
std::shared_ptr< AssemblyCommDG > AssemblyCommDGSharedPtr
std::shared_ptr< ExchangeMethod > ExchangeMethodSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::map< int, std::vector< PeriodicEntity > > PeriodicMap