Nektar++
Loading...
Searching...
No Matches
LocalToGlobalDataWarehouse.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: LocalToGlobalDataWarehouse.hpp
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: Data warehouse keys and creator for the local-to-global
32// assembly tables.
33//
34///////////////////////////////////////////////////////////////////////////////
35
36#pragma once
37
39
40#include <cstdint>
41#include <string>
42#include <type_traits>
43#include <typeindex>
44#include <vector>
45
47{
48
49class ExpList;
50
51/// Shared pointer to an ExpList object.
52typedef std::shared_ptr<ExpList> ExpListSharedPtr;
53
54class AssemblyMapCG;
55
56typedef std::shared_ptr<AssemblyMapCG> AssemblyMapCGSharedPtr;
57
58class LocalToGlobalDataCreator;
59
60/**
61 * @brief Base of the LocalToGlobalDataCreator keys: holds the parameters the
62 * tables depend on and hashes them with the key's tag and padding type.
63 *
64 * All keys of the creator share one map in the data warehouse, so each
65 * derived key passes a unique tag.
66 */
67template <typename TPadding, typename TValue>
69{
70 // The TPadding type is used to determine the padding requirement and must
71 // be of floating point type.
72 static_assert(std::is_floating_point_v<TPadding>,
73 "LocalToGlobalKeyBase: Data type must be float or double.");
74
76
77public:
79 typedef TValue value_type;
80
81 ~LocalToGlobalKeyBase() override = default;
82
83protected:
85 const std::string &tag, const std::vector<std::string> &components,
86 bool zeroDir = false, bool signChange = false, unsigned width = 1,
87 const std::vector<unsigned> &fieldInterleaveWidths = {})
88 : m_zeroDir(zeroDir), m_signChange(signChange), m_width(width),
89 m_components(components),
90 m_fieldInterleaveWidths(fieldInterleaveWidths)
91 {
92 hash_combine(m_hash, tag, std::type_index(typeid(TPadding)), m_zeroDir,
94 for (const auto &component : m_components)
95 {
96 hash_combine(m_hash, component);
97 }
98 for (const auto &fieldInterleaveWidth : m_fieldInterleaveWidths)
99 {
100 hash_combine(m_hash, fieldInterleaveWidth);
101 }
102 }
103
104private:
107 unsigned m_width;
108 std::vector<std::string> m_components;
109 /// Interleave width of each block of the field the tables address.
110 std::vector<unsigned> m_fieldInterleaveWidths;
111};
112
113/// Number of interior global DOFs to assemble.
114template <typename TPadding>
116 : public LocalToGlobalKeyBase<TPadding, unsigned>
117{
118public:
120 bool zeroDir, const std::vector<std::string> &components,
121 unsigned width, const std::vector<unsigned> &fieldInterleaveWidths)
122 : LocalToGlobalKeyBase<TPadding, unsigned>(
123 "DeviceLocalToGlobalNumGidsKey", components, zeroDir, false,
124 width, fieldInterleaveWidths)
125 {
126 }
127};
128
129/// Number of local copies of each interior global DOF.
130template <typename TPadding>
132 : public LocalToGlobalKeyBase<TPadding, unsigned>
133{
134public:
136 bool zeroDir, const std::vector<std::string> &components,
137 unsigned width, const std::vector<unsigned> &fieldInterleaveWidths)
138 : LocalToGlobalKeyBase<TPadding, unsigned>(
139 "DeviceLocalToGlobalNumAssembleKey", components, zeroDir, false,
140 width, fieldInterleaveWidths)
141 {
142 }
143};
144
145/// Local indices of the interior global DOFs, packed width-major.
146template <typename TPadding>
148 : public LocalToGlobalKeyBase<TPadding, unsigned>
149{
150public:
152 bool zeroDir, const std::vector<std::string> &components,
153 unsigned width, const std::vector<unsigned> &fieldInterleaveWidths)
154 : LocalToGlobalKeyBase<TPadding, unsigned>(
155 "DeviceLocalToGlobalIndexKey", components, zeroDir, false, width,
156 fieldInterleaveWidths)
157 {
158 }
159};
160
161/// Offset of each interior global DOF into the index and sign tables.
162template <typename TPadding>
164 : public LocalToGlobalKeyBase<TPadding, unsigned>
165{
166public:
168 bool zeroDir, const std::vector<std::string> &components,
169 unsigned width, const std::vector<unsigned> &fieldInterleaveWidths)
170 : LocalToGlobalKeyBase<TPadding, unsigned>(
171 "DeviceLocalToGlobalIndexOffsetKey", components, zeroDir, false,
172 width, fieldInterleaveWidths)
173 {
174 }
175};
176
177/// Signs of the interior local copies, packed as the index table.
178template <typename TPadding>
179class DeviceLocalToGlobalSignKey : public LocalToGlobalKeyBase<TPadding, int8_t>
180{
181public:
183 bool zeroDir, bool signChange,
184 const std::vector<std::string> &components, unsigned width,
185 const std::vector<unsigned> &fieldInterleaveWidths)
186 : LocalToGlobalKeyBase<TPadding, int8_t>(
187 "DeviceLocalToGlobalSignKey", components, zeroDir, signChange,
188 width, fieldInterleaveWidths)
189 {
190 }
191};
192
193/// Number of parallel-boundary global DOFs to assemble.
194template <typename TPadding>
196 : public LocalToGlobalKeyBase<TPadding, unsigned>
197{
198public:
199 DeviceBndLocalToGlobalNumGidsKey(const std::vector<std::string> &components)
200 : LocalToGlobalKeyBase<TPadding, unsigned>(
201 "DeviceBndLocalToGlobalNumGidsKey", components)
202 {
203 }
204};
205
206/// Number of local copies of each parallel-boundary global DOF.
207template <typename TPadding>
209 : public LocalToGlobalKeyBase<TPadding, unsigned>
210{
211public:
213 const std::vector<std::string> &components)
214 : LocalToGlobalKeyBase<TPadding, unsigned>(
215 "DeviceBndLocalToGlobalNumAssembleKey", components)
216 {
217 }
218};
219
220/// Number of communication buffer slots of each parallel-boundary global DOF.
221template <typename TPadding>
223 : public LocalToGlobalKeyBase<TPadding, unsigned>
224{
225public:
227 const std::vector<std::string> &components)
228 : LocalToGlobalKeyBase<TPadding, unsigned>(
229 "DeviceBndLocalToGlobalNumBndValsKey", components)
230 {
231 }
232};
233
234/// Local indices and buffer slots of the parallel-boundary global DOFs.
235template <typename TPadding>
237 : public LocalToGlobalKeyBase<TPadding, unsigned>
238{
239public:
241 const std::vector<std::string> &components,
242 const std::vector<unsigned> &fieldInterleaveWidths)
243 : LocalToGlobalKeyBase<TPadding, unsigned>(
244 "DeviceBndLocalToGlobalIndexKey", components, false, false, 1,
245 fieldInterleaveWidths)
246 {
247 }
248};
249
250/// Offset of each parallel-boundary global DOF into the index and sign tables.
251template <typename TPadding>
253 : public LocalToGlobalKeyBase<TPadding, unsigned>
254{
255public:
256 DeviceBndLocalToGlobalOffsetKey(const std::vector<std::string> &components)
257 : LocalToGlobalKeyBase<TPadding, unsigned>(
258 "DeviceBndLocalToGlobalOffsetKey", components)
259 {
260 }
261};
262
263/// Position of this rank among the ranks sharing each parallel-boundary
264/// global DOF, which fixes the order of assembly.
265template <typename TPadding>
267 : public LocalToGlobalKeyBase<TPadding, unsigned>
268{
269public:
271 const std::vector<std::string> &components)
272 : LocalToGlobalKeyBase<TPadding, unsigned>(
273 "DeviceBndLocalToGlobalAssembleOrderKey", components)
274 {
275 }
276};
277
278/// Signs of the parallel-boundary local copies, packed as the index table
279/// with zeros in the buffer slots.
280template <typename TPadding>
282 : public LocalToGlobalKeyBase<TPadding, int8_t>
283{
284public:
285 DeviceBndLocalToGlobalSignKey(bool zeroDir, bool signChange,
286 const std::vector<std::string> &components)
287 : LocalToGlobalKeyBase<TPadding, int8_t>(
288 "DeviceBndLocalToGlobalSignKey", components, zeroDir, signChange)
289 {
290 }
291};
292
293/// Mask selecting one local copy of each global DOF this rank owns.
294template <typename TPadding>
295class LocalToGlobalMaskKey : public LocalToGlobalKeyBase<TPadding, std::uint8_t>
296{
297public:
298 LocalToGlobalMaskKey(const std::vector<std::string> &components)
299 : LocalToGlobalKeyBase<TPadding, std::uint8_t>("LocalToGlobalMaskKey",
300 components)
301 {
302 }
303};
304
306{
307public:
308 ~LocalToGlobalDataCreator() override = default;
310 : m_expansionList(expansionList) {};
311
312 template <typename MemSpace, typename TPadding>
316
317 template <typename MemSpace, typename TPadding>
321
322 template <typename MemSpace, typename TPadding>
326
327 template <typename MemSpace, typename TPadding>
331
332 template <typename MemSpace, typename TPadding>
336
337 template <typename MemSpace, typename TPadding>
341
342 template <typename MemSpace, typename TPadding>
346
347 template <typename MemSpace, typename TPadding>
351
352 template <typename MemSpace, typename TPadding>
356
357 template <typename MemSpace, typename TPadding>
361
362 template <typename MemSpace, typename TPadding>
366
367 template <typename MemSpace, typename TPadding>
371
372 template <typename MemSpace, typename TPadding>
375 Create(const LocalToGlobalMaskKey<TPadding> &LocToGloKey);
376
377 inline static const std::string m_name = "LocalToGlobalCreator";
378
379private:
381 std::unordered_map<size_t, std::vector<AssemblyMapCGSharedPtr>>
383 /// Interior gather-scatter tables the interior keys are built from.
384 std::unordered_map<size_t, std::vector<unsigned>> m_gsInfo;
385 /// Parallel-boundary gather-scatter tables the boundary keys are built
386 /// from.
387 std::unordered_map<size_t, std::vector<unsigned>> m_gsBndInfo;
388
389 std::vector<AssemblyMapCGSharedPtr> &GetAssemblyMap(
390 const std::vector<std::string> &components);
391
392 template <typename TPadding>
393 const std::vector<unsigned> &GetGSInfo(
394 bool zeroDir, const std::vector<std::string> &components,
395 unsigned width, const std::vector<unsigned> &fieldInterleaveWidths);
396
397 template <typename TPadding>
398 const std::vector<unsigned> &GetGSBndInfo(
399 const std::vector<std::string> &components);
400
401 template <typename TPadding>
402 void FillSignArray(std::vector<unsigned> &index,
403 const std::vector<AssemblyMapCGSharedPtr> &loc2glo,
404 bool zeroDir, bool signChange, int8_t *out);
405};
406
407} // namespace Nektar::MultiRegions
A MemoryRegion represents a memory region.
Position of this rank among the ranks sharing each parallel-boundary global DOF, which fixes the orde...
DeviceBndLocalToGlobalAssembleOrderKey(const std::vector< std::string > &components)
Local indices and buffer slots of the parallel-boundary global DOFs.
DeviceBndLocalToGlobalIndexKey(const std::vector< std::string > &components, const std::vector< unsigned > &fieldInterleaveWidths)
Number of local copies of each parallel-boundary global DOF.
DeviceBndLocalToGlobalNumAssembleKey(const std::vector< std::string > &components)
Number of communication buffer slots of each parallel-boundary global DOF.
DeviceBndLocalToGlobalNumBndValsKey(const std::vector< std::string > &components)
Number of parallel-boundary global DOFs to assemble.
DeviceBndLocalToGlobalNumGidsKey(const std::vector< std::string > &components)
Offset of each parallel-boundary global DOF into the index and sign tables.
DeviceBndLocalToGlobalOffsetKey(const std::vector< std::string > &components)
Signs of the parallel-boundary local copies, packed as the index table with zeros in the buffer slots...
DeviceBndLocalToGlobalSignKey(bool zeroDir, bool signChange, const std::vector< std::string > &components)
Local indices of the interior global DOFs, packed width-major.
DeviceLocalToGlobalIndexKey(bool zeroDir, const std::vector< std::string > &components, unsigned width, const std::vector< unsigned > &fieldInterleaveWidths)
Offset of each interior global DOF into the index and sign tables.
DeviceLocalToGlobalIndexOffsetKey(bool zeroDir, const std::vector< std::string > &components, unsigned width, const std::vector< unsigned > &fieldInterleaveWidths)
Number of local copies of each interior global DOF.
DeviceLocalToGlobalNumAssembleKey(bool zeroDir, const std::vector< std::string > &components, unsigned width, const std::vector< unsigned > &fieldInterleaveWidths)
DeviceLocalToGlobalNumGidsKey(bool zeroDir, const std::vector< std::string > &components, unsigned width, const std::vector< unsigned > &fieldInterleaveWidths)
Signs of the interior local copies, packed as the index table.
DeviceLocalToGlobalSignKey(bool zeroDir, bool signChange, const std::vector< std::string > &components, unsigned width, const std::vector< unsigned > &fieldInterleaveWidths)
LocalToGlobalDataCreator(const ExpListSharedPtr &expansionList)
const std::vector< unsigned > & GetGSBndInfo(const std::vector< std::string > &components)
Parallel-boundary gather-scatter table, built once per set of components.
std::vector< AssemblyMapCGSharedPtr > & GetAssemblyMap(const std::vector< std::string > &components)
std::unordered_map< size_t, std::vector< unsigned > > m_gsInfo
Interior gather-scatter tables the interior keys are built from.
const std::vector< unsigned > & GetGSInfo(bool zeroDir, const std::vector< std::string > &components, unsigned width, const std::vector< unsigned > &fieldInterleaveWidths)
Interior gather-scatter table, built once per set of parameters.
void FillSignArray(std::vector< unsigned > &index, const std::vector< AssemblyMapCGSharedPtr > &loc2glo, bool zeroDir, bool signChange, int8_t *out)
LibUtilities::MemoryRegion< typename DeviceLocalToGlobalNumGidsKey< TPadding >::value_type > Create(const DeviceLocalToGlobalNumGidsKey< TPadding > &LocToGloKey)
std::unordered_map< size_t, std::vector< AssemblyMapCGSharedPtr > > m_assemblyMaps
std::unordered_map< size_t, std::vector< unsigned > > m_gsBndInfo
Parallel-boundary gather-scatter tables the boundary keys are built from.
Base of the LocalToGlobalDataCreator keys: holds the parameters the tables depend on and hashes them ...
LocalToGlobalKeyBase(const std::string &tag, const std::vector< std::string > &components, bool zeroDir=false, bool signChange=false, unsigned width=1, const std::vector< unsigned > &fieldInterleaveWidths={})
std::vector< unsigned > m_fieldInterleaveWidths
Interleave width of each block of the field the tables address.
Mask selecting one local copy of each global DOF this rank owns.
LocalToGlobalMaskKey(const std::vector< std::string > &components)
std::shared_ptr< AssemblyMapCG > AssemblyMapCGSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
void hash_combine(std::size_t &seed)
Definition HashUtils.hpp:45
STL namespace.