Nektar++
Loading...
Searching...
No Matches
GatherScatter.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: GatherScatter.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: Gather-scatter handle selectable between gslib and
32// SharedIdPlan.
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#ifndef NEKTAR_LIBUTILITIES_COMMUNICATION_GATHERSCATTER_H
37#define NEKTAR_LIBUTILITIES_COMMUNICATION_GATHERSCATTER_H
38
39#include <memory>
40#include <string>
41
46
48{
49
50/**
51 * @brief Fold a #GatherScatter applies across every slot sharing an id.
52 *
53 * Mirrors the subset of gslib's `gs_op` Nektar uses, so that no caller needs
54 * gslib's headers to ask for a gather.
55 */
57{
58 eAdd, ///< sum of the contributions
59 eMul, ///< product of the contributions
60 eMin, ///< smallest contribution
61 eMax, ///< largest contribution
62 eAbsMax ///< the contribution of largest magnitude, sign kept
63};
64
65/**
66 * @brief Which implementation a #GatherScatter uses, selected with the
67 * `--gather-scatter` command-line option.
68 */
70{
71 eGslib, ///< gslib's gs_setup / gs_gather / gs_unique (the default)
72 ePairwise, ///< SharedIdPlan over ExchangeBackend::ePairwise
73 eNeighbour, ///< SharedIdPlan over ExchangeBackend::eNeighbourCollective
74 eCrystal ///< SharedIdPlan replaying through a CrystalRouterTransport
75};
76
77/**
78 * @brief Transport a SharedIdPlan's one-off discovery runs over, selected with
79 * `--gather-scatter-discovery`. Ignored for GatherScatterMethod::eGslib.
80 */
82{
83 eCrystalRouter, ///< CrystalRouterTransport: no O(P) arrays (the default)
84 eAlltoallv ///< AlltoallvTransport
85};
86
87/// A gather-scatter method and discovery transport, as chosen on the command
88/// line.
90{
93
94 /**
95 * @brief Read `--gather-scatter` and `--gather-scatter-discovery` from
96 * @p session. Anything not given keeps its default (gslib), as does
97 * everything for a null session.
98 */
101
102 /// @return A one-line description, e.g. for verbose output.
103 LIB_UTILITIES_EXPORT std::string Describe() const;
104};
105
106/**
107 * @class GatherScatter
108 * @brief A gather-scatter over universal ids, mirroring Gs::Init(),
109 * Gs::Gather() and Gs::Unique() behind an implementation-agnostic interface.
110 *
111 * @details
112 * Create() picks the implementation from a #GatherScatterConfig: gslib's
113 * `gs_data`, or a #SharedIdPlan over one of its exchange backends. The
114 * subclasses live entirely in the implementation file, so a caller needs
115 * neither gslib's headers nor the shared-id module's to use one. This is what
116 * lets a solver be benchmarked with and without gslib just by adding, say,
117 * `--gather-scatter pairwise` to its command line.
118 *
119 * On a serial communicator Create() returns the same do-nothing handle
120 * CreateNoOp() gives, as gslib is a no-op there too. Create() and Gather()
121 * are collective over the communicator, as is Unique() for gslib.
122 */
124{
125public:
126 /**
127 * @brief Set up a gather-scatter over @p ids: the Gs::Init() equivalent.
128 *
129 * @param ids One universal id per slot; 0 for slots to skip. The
130 * SharedIdPlan methods also skip negative ids, which
131 * gslib treats as "flagged" (see the implementation).
132 * @param comm Communicator to gather over.
133 * @param config Implementation to use.
134 * @param verbose Print a setup summary on rank 0.
135 * @return A handle, never null.
136 */
137 LIB_UTILITIES_EXPORT static std::shared_ptr<GatherScatter> Create(
138 const Array<OneD, long> &ids, const CommSharedPtr &comm,
139 const GatherScatterConfig &config, bool verbose = false);
140
141 /**
142 * @brief A handle whose Gather() and Unique() do nothing.
143 *
144 * For slots that never had a gather-scatter set up over them, which
145 * callers previously expressed as a null `Gs::gs_data *` and relied on
146 * Gs::Gather() ignoring.
147 */
148 LIB_UTILITIES_EXPORT static std::shared_ptr<GatherScatter> CreateNoOp();
149
151
152 GatherScatter(const GatherScatter &) = delete;
154
155 /**
156 * @brief The Gs::Gather() equivalent: fold the entries of @p u, in
157 * place, across every slot on every rank with the same id.
158 *
159 * As with gslib, a slot whose id is neither shared nor repeated locally
160 * is never accessed, so @p u may be shorter than the id array this
161 * handle was built from provided it covers every other slot.
162 * AssemblyMap's multi-level static condensation relies on this.
163 */
165 GatherScatterOp op) = 0;
166
167 /**
168 * @brief The Gs::Unique() equivalent: negate all but one occurrence of
169 * each id across all ranks, in place. @p ids must hold the ids this
170 * handle was built from. Which occurrence survives differs between
171 * implementations; that exactly one does is what callers rely on.
172 */
174
175protected:
176 GatherScatter() = default;
177};
178
179typedef std::shared_ptr<GatherScatter> GatherScatterSharedPtr;
180
181} // namespace Nektar::LibUtilities
182
183#endif
#define LIB_UTILITIES_EXPORT
LibUtilities::SessionReaderSharedPtr session
A gather-scatter over universal ids, mirroring Gs::Init(), Gs::Gather() and Gs::Unique() behind an im...
GatherScatter & operator=(const GatherScatter &)=delete
virtual void Unique(Array< OneD, long > &ids)=0
The Gs::Unique() equivalent: negate all but one occurrence of each id across all ranks,...
GatherScatter(const GatherScatter &)=delete
static std::shared_ptr< GatherScatter > CreateNoOp()
A handle whose Gather() and Unique() do nothing.
static std::shared_ptr< GatherScatter > Create(const Array< OneD, long > &ids, const CommSharedPtr &comm, const GatherScatterConfig &config, bool verbose=false)
Set up a gather-scatter over ids: the Gs::Init() equivalent.
virtual void Gather(Array< OneD, NekDouble > u, GatherScatterOp op)=0
The Gs::Gather() equivalent: fold the entries of u, in place, across every slot on every rank with th...
GatherScatterMethod
Which implementation a #GatherScatter uses, selected with the --gather-scatter command-line option.
@ eNeighbour
SharedIdPlan over ExchangeBackend::eNeighbourCollective.
@ eGslib
gslib's gs_setup / gs_gather / gs_unique (the default)
@ ePairwise
SharedIdPlan over ExchangeBackend::ePairwise.
@ eCrystal
SharedIdPlan replaying through a CrystalRouterTransport.
GatherScatterDiscovery
Transport a SharedIdPlan's one-off discovery runs over, selected with --gather-scatter-discovery....
@ eCrystalRouter
CrystalRouterTransport: no O(P) arrays (the default)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< GatherScatter > GatherScatterSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition Comm.h:62
GatherScatterOp
Fold a #GatherScatter applies across every slot sharing an id.
@ eAbsMax
the contribution of largest magnitude, sign kept
@ eMul
product of the contributions
@ eAdd
sum of the contributions
A gather-scatter method and discovery transport, as chosen on the command line.
static GatherScatterConfig FromSession(const SessionReaderSharedPtr &session)
Read --gather-scatter and --gather-scatter-discovery from session. Anything not given keeps its defau...