CEPS  24.01
Cardiac ElectroPhysiology Simulator
DistributedInfos.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 #pragma once
31 
32 #include <array>
33 
35 
36 class DistributedFactory;
37 
43 template <class _Tp>
44 void
46 {
47  obj->setGlobalIndex (idx);
48  return;
49 }
50 
54 template <class _Type, class _Hash=CepsHash>
56 {
57  public:
58 
61 
64 
68 
71 
72  // -----------------------------------------------------------------
73 
77 
81 
82  // -----------------------------------------------------------------
83 
85  CepsBool
86  hasHash(const _Hash &hashValue, const CepsUInt &pId) const;
87 
89  _Type &
90  atHash(const _Hash &hashValue, const CepsUInt &pId, const _Type &def);
91 
93  const _Type &
94  atHash(const _Hash &hashValue, const CepsUInt &pId, const _Type &def) const;
95 
97  CepsBool
98  hasLocal(const CepsLocalIndex &localId, const CepsUInt &pId) const;
99 
101  _Type &
102  atLocal(const CepsLocalIndex &localId, const CepsUInt &pId, const _Type &def);
103 
105  const _Type &
106  atLocal(const CepsLocalIndex &localId, const CepsUInt &pId, const _Type &def) const;
107 
109  CepsBool
110  hasGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId) const;
111 
113  _Type &
114  atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId);
115 
117  const _Type &
118  atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId) const;
119 
121  _Type &
122  atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId, const _Type &def);
123 
125  const _Type &
126  atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId, const _Type &def) const;
127 
129  const CepsVector<_Type> &
130  getOwned() const;
131 
135 
137  const _Type &
138  getOwned(CepsUInt i) const;
139 
141  _Type &
143 
145  const CepsVector<_Type> &
146  getHalo() const;
147 
151 
153  const _Type &
154  getHalo(CepsUInt i) const;
155 
157  _Type &
159 
160  // -----------------------------------------------------------------
161 
164  void
165  add(const _Type& x, const _Hash& hashValue, const CepsGlobalIndex& globalId,
166  const CepsUInt& pId);
167 
169  void
170  addOwned(const _Type &x, const _Hash &hashValue, const CepsGlobalIndex &globalId);
171 
172 
174  void
176  const _Type& x,
177  const _Hash& hashValue,
178  const CepsGlobalIndex& globalId,
179  const CepsUInt& fromProcId
180  );
181 
182  // -----------------------------------------------------------------
183 
185  void
186  add(const _Type &x, const _Hash &hashValue, const CepsUInt &pId);
187 
189  void
190  addOwned(const _Type &x, const _Hash &hashValue);
191 
193  void
194  addHalo(const _Type &x, const _Hash &hashValue, const CepsUInt &fromProcId);
195 
196  // -----------------------------------------------------------------
197 
199  void
201 
203  void
204  reset();
205 
207  void
209  CepsBool setGlobalIndicesFromLocals,
210  std::function<void (_Type &, CepsGlobalIndex)> update = nullptr
211  );
212 
214  void
216 
218  CepsUInt
220 
222  CepsUInt
224 
226  CepsUInt
228 
232  CepsUInt
234 
235  protected:
236 
243 };
244 
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
CepsIndex CepsGlobalIndex
Many uses. Has to be signed for PETSc.
Definition: CepsTypes.hpp:218
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
CepsIndex CepsLocalIndex
To use when the indexing is only on one process.
Definition: CepsTypes.hpp:219
CepsUInt CepsProcId
For CPU indices.
Definition: CepsTypes.hpp:123
void setGlobalIndexFunction(_Tp *&obj, CepsGlobalIndex idx)
Sets the ID of data to the passed idx.
A class that manages data that is distributed between processors, not only real values (as in Distrib...
CepsUInt getGlobalIndexOffset(CepsProcId pId) const
Return the number of elements on the processes before pId This supposes that synchronizeTotalSize has...
const _Type & getOwned(CepsUInt i) const
Get data owned by the processor with id i, const.
CepsBool hasLocal(const CepsLocalIndex &localId, const CepsUInt &pId) const
Check if container has data with given local ID.
CepsUInt m_nbGlobalHalo
sum of size(m_halo) on whole communicator
CepsUInt getTotalNumberOfEntities() const
Total number of distributed data amongst all process.
void reset()
Clears the container.
LocalGlobalMapping< _Type, _Hash > * m_halo
Proc halo _Type object.
void addHalo(const _Type &x, const _Hash &hashValue, const CepsGlobalIndex &globalId, const CepsUInt &fromProcId)
Add entry with global ID to the container, halo data, hash must be provided.
const CepsVector< _Type > & getOwned() const
Get data owned by the processor, const.
~DistributedInfos()
Destructor.
CepsUInt getNumberOfHalo() const
Number of shared data from other process stored.
LocalGlobalMapping< _Type, _Hash > * getHaloMapping()
Mapping between global and local index of halo data.
DistributedInfos & operator=(const DistributedInfos &)
Default assignment operator.
CepsVector< CepsVector< _Hash > > m_toReceiveFrom
Local Halo hash to receive, grouped by origin processor.
DistributedInfos()
Constructor.
void add(const _Type &x, const _Hash &hashValue, const CepsGlobalIndex &globalId, const CepsUInt &pId)
Add entry with global ID to the container, hash must be provided, pId selects owned or halo.
void addOwned(const _Type &x, const _Hash &hashValue, const CepsGlobalIndex &globalId)
Add entry with global ID to the container, owned data, hash must be provided.
void synchronize(CepsBool setGlobalIndicesFromLocals, std::function< void(_Type &, CepsGlobalIndex)> update=nullptr)
Recomputes global indices from all local indices, build correct halo global indices.
CepsBool hasHash(const _Hash &hashValue, const CepsUInt &pId) const
Check if container has data with given hash.
const _Type & atHash(const _Hash &hashValue, const CepsUInt &pId, const _Type &def) const
const access with given hash
void addOwned(const _Type &x, const _Hash &hashValue)
Add an entry to the container, hash must be provided, owned data.
void synchronizeTotalSize()
Compute the total number of owned elements.
CepsUInt m_nbGlobalOwned
sum of size(m_owned) on whole communicator
CepsUInt getNumberOfOwned() const
Number of owned data stored.
LocalGlobalMapping< _Type, _Hash > * getOwnedMapping()
Mapping between global and local index of owned data.
CepsVector< _Type > & getHalo()
Get halo data owned by neighbor processor, const.
_Type & getHalo(CepsUInt i)
Get halo data owned by neighbor processor with ID i, const.
void add(const _Type &x, const _Hash &hashValue, const CepsUInt &pId)
Add an entry to the container, hash must be provided.
_Type & atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId)
Access with given global ID.
_Type & atHash(const _Hash &hashValue, const CepsUInt &pId, const _Type &def)
Access with given hash.
LocalGlobalMapping< _Type, _Hash > * m_owned
Proc owned _Type object.
CepsBool hasGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId) const
Check if container has data with given global ID.
_Type & getOwned(CepsUInt i)
Get data owned by the processor with id i.
const CepsVector< _Type > & getHalo() const
Get halo data owned by neighbor processor, const.
void destroyObjects()
Clears the contents, keeps structure.
_Type & atLocal(const CepsLocalIndex &localId, const CepsUInt &pId, const _Type &def)
Access with given local ID.
_Type & atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId, const _Type &def)
Access with given global ID.
const _Type & getHalo(CepsUInt i) const
Get halo data owned by neighbor processor with ID i, const.
void addHalo(const _Type &x, const _Hash &hashValue, const CepsUInt &fromProcId)
Add an entry to the container, hash must be provided, halo data.
const _Type & atLocal(const CepsLocalIndex &localId, const CepsUInt &pId, const _Type &def) const
const access with given local ID
const _Type & atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId) const
Access with given global ID.
DistributedInfos(const DistributedInfos &)
Default copy constructor.
CepsVector< CepsUInt > m_elementsOffset
sum of size(m_owned) on processes before owner
CepsVector< _Type > & getOwned()
Get data owned by the processor.
const _Type & atGlobal(const CepsGlobalIndex &globalId, const CepsUInt &pId, const _Type &def) const
const access with given global ID
A map destined for things that have (or could have) a global index and must be distributed amongst CP...