9.2
general documentation
cs_range_set.h
Go to the documentation of this file.
1#ifndef CS_RANGE_SET_H
2#define CS_RANGE_SET_H
3
4/*============================================================================
5 * Operations related to handling of an owning rank for distributed entities.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_defs.h"
35
36#include "fvm/fvm_group.h"
37#include "fvm/fvm_selector.h"
38#include "fvm/fvm_periodicity.h"
39
40#include "base/cs_base.h"
41#include "base/cs_halo.h"
42#include "base/cs_interface.h"
43#include "base/cs_numbering.h"
44
46
47/*=============================================================================
48 * Macro definitions
49 *============================================================================*/
50
53typedef struct {
54
55 cs_lnum_t n_elts[3];
59 cs_gnum_t l_range[2];
61 const cs_gnum_t *g_id;
67 const cs_halo_t *halo;
70
71/*============================================================================
72 * Type definitions
73 *============================================================================*/
74
75/*============================================================================
76 * Static global variables
77 *============================================================================*/
78
79/*=============================================================================
80 * Public function prototypes
81 *============================================================================*/
82
83/*----------------------------------------------------------------------------*/
84/*
85 * \brief Define global ids and a partitioning of data based on local ranges
86 * for elements which may be shared across ranks or have halo elements.
87 *
88 * This is a utility function, allowing a similar call for cases where matching
89 * elements or parallel ranks are identified using an interface set (for
90 * elements which may be on rank boundaries, such as vertices or faces),
91 * elements with an associated a halo (such as for cells), or neither
92 * (in the single-rank case).
93 *
94 * Global id ranges are assigned to each rank, and global ids are defined
95 * by a parallel scan type operation counting elements on parallel
96 * interfaces only once. Each element will appear inside one rank's range
97 * and outside the range of all other ranks.
98 * Ranges across different ranks are contiguous.
99 *
100 * This allows building distribution information such as that used in many
101 * external libraries, such as PETSc, HYPRE, and may also simplify many
102 * internal operations, where it is needed that elements have a unique owner
103 * rank, and are ghosted on others (such as linear solvers operating on
104 * elements which may be on parallel boundaries, such as vertices, edges,
105 * and faces).
106 *
107 * Elements and their periodic matches will have identical or distinct
108 * global ids depending on the tr_ignore argument.
109 *
110 * \param[in] ifs pointer to interface set structure, or nullptr
111 * \param[in] halo pointer to halo structure, or nullptr
112 * \param[in] n_elts number of elements
113 * \param[in] balance try to balance shared elements across ranks ?
114 * (for elements shared across an interface set)
115 * \param[in] tr_ignore 0: periodic elements will share global ids
116 * > 0: ignore periodicity with rotation;
117 * > 1: ignore all periodic transforms
118 * \param[in] g_id_base global id base index (usually 0, but 1
119 * could be used to generate an IO numbering)
120 * \param[out] l_range global id range assigned to local rank:
121 * [start, past-the-end[
122 * \param[out] g_id global id assigned to elements
123 */
124/*----------------------------------------------------------------------------*/
125
126void
128 const cs_halo_t *halo,
129 cs_lnum_t n_elts,
130 bool balance,
131 int tr_ignore,
132 cs_gnum_t g_id_base,
133 cs_gnum_t l_range[2],
134 cs_gnum_t *g_id);
135
136/*----------------------------------------------------------------------------*/
137/*
138 * \brief Create a range set (with associated range and global ids) for the
139 * partitioning of data based on local ranges for elements which may
140 * be shared across ranks or have halo elements.
141 *
142 * Global id ranges are assigned to each rank of the interface set's associated
143 * communicator, and global ids are defined by a parallel scan type operation
144 * counting elements on parallel interfaces only once. Each element will
145 * appear inside one rank's range and outside the range of all other ranks.
146 * Ranges across different ranks are contiguous.
147 *
148 * Elements and their periodic matches will have identical or distinct
149 * global ids depending on the tr_ignore argument.
150 *
151 * The range set maintains pointers to the optional interface set and halo
152 * structures, but does not copy them, so those structures should have a
153 * lifetime at least as long as the returned range set.
154 *
155 * \param[in] ifs pointer to interface set structure, or nullptr
156 * \param[in] halo pointer to halo structure, or nullptr
157 * \param[in] n_elts number of elements
158 * \param[in] balance try to balance shared elements across ranks?
159 * (for elements shared across an interface set)
160 * \param[in] tr_ignore 0: periodic elements will share global ids
161 * > 0: ignore periodicity with rotation;
162 * > 1: ignore all periodic transforms
163 * \param[in] g_id_base global id base index (usually 0, but 1
164 * could be used to generate an IO numbering)
165 *
166 * \return pointer to created range set structure
167 */
168/*----------------------------------------------------------------------------*/
169
172 const cs_halo_t *halo,
173 cs_lnum_t n_elts,
174 bool balance,
175 int tr_ignore,
176 cs_gnum_t g_id_base);
177
178/*----------------------------------------------------------------------------*/
179/*
180 * \brief Create a range set (with associated range and global ids) from
181 * an existing partition of data based on local ranges for elements
182 * which may be shared across ranks or have halo elements.
183 *
184 * The optional interface set, halo, and global element id array are only
185 * shared by the range set, not copied, so they should have a lifetime at
186 * least as long as the returned range set.
187 *
188 * \param[in] ifs pointer to interface set structure, or nullptr
189 * \param[in] halo pointer to halo structure, or nullptr
190 * \param[in] n_elts number of elements
191 * \param[in] l_range global id range assigned to local rank:
192 * [start, past-the-end[
193 * \param[in] g_id global id assigned to elements
194 *
195 * \return pointer to created range set structure
196 */
197/*----------------------------------------------------------------------------*/
198
201 const cs_halo_t *halo,
202 cs_lnum_t n_elts,
203 cs_gnum_t l_range[2],
204 cs_gnum_t *g_id);
205
206/*----------------------------------------------------------------------------*/
207/*
208 * \brief Destroy a range set structure.
209 *
210 * \param[in, out] rs pointer to pointer to structure to destroy
211 */
212/*----------------------------------------------------------------------------*/
213
214void
216
217/*----------------------------------------------------------------------------*/
218/*
219 * \brief Set values of a given array to zero for indexes of elements
220 * outside the local range.
221 *
222 * If an interface set used to define the range set is available, it may be
223 * used to accelerate this operation, as only elements on that interface need
224 * to be checked.
225 *
226 * \param[in] rs pointer to range set structure, or nullptr
227 * \param[in] datatype type of data considered
228 * \param[in] stride number of values per entity (interlaced)
229 * \param[in, out] val pointer to array values
230 */
231/*----------------------------------------------------------------------------*/
232
233void
235 cs_datatype_t datatype,
236 cs_lnum_t stride,
237 void *val);
238
239/*----------------------------------------------------------------------------*/
240/*
241 * \brief Synchronize values elements associated with a range set, using
242 * either a halo or an interface set.
243 *
244 * \param[in] rs pointer to range set structure, or nullptr
245 * \param[in] datatype type of data considered
246 * \param[in] stride number of values per entity (interlaced)
247 * \param[in, out] val values buffer
248 */
249/*----------------------------------------------------------------------------*/
250
251void
253 cs_datatype_t datatype,
254 cs_lnum_t stride,
255 void *val);
256
257/*----------------------------------------------------------------------------*/
258/*
259 * \brief Gather element values associated with a range set to a compact set.
260 *
261 * \param[in] rs pointer to range set structure, or nullptr
262 * \param[in] datatype type of data considered
263 * \param[in] stride number of values per entity (interlaced)
264 * \param[in] src_val source values buffer
265 * \param[out] dest_val destination values buffer (may be identical to
266 * src_val, in which case operation is "in-place")
267 */
268/*----------------------------------------------------------------------------*/
269
270void
272 cs_datatype_t datatype,
273 cs_lnum_t stride,
274 const void *src_val,
275 void *dest_val);
276
277/*----------------------------------------------------------------------------*/
278/*
279 * \brief Scatter element values associated with a range set to the full set.
280 *
281 * This includes parallel synchronization when the range set is associated
282 * with a halo or interface set structure.
283 *
284 * \param[in] rs pointer to range set structure, or nullptr
285 * \param[in] datatype type of data considered
286 * \param[in] stride number of values per entity (interlaced)
287 * \param[in] src_val source values buffer
288 * \param[out] dest_val destination values buffer (may be identical to
289 * src_val, in which case operation is "in-place")
290 */
291/*----------------------------------------------------------------------------*/
292
293void
295 cs_datatype_t datatype,
296 cs_lnum_t stride,
297 const void *src_val,
298 void *dest_val);
299
300/*----------------------------------------------------------------------------*/
301
302#endif /* CS_RANGE_SET_H */
cs_datatype_t
Definition: cs_defs.h:290
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:317
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:57
cs_range_set_t * cs_range_set_create_from_shared(const cs_interface_set_t *ifs, const cs_halo_t *halo, cs_lnum_t n_elts, cs_gnum_t l_range[2], cs_gnum_t *g_id)
Create a range set (with associated range and global ids) from an existing partition of data based on...
Definition: cs_range_set.cpp:732
void cs_range_set_scatter(const cs_range_set_t *rs, cs_datatype_t datatype, cs_lnum_t stride, const void *src_val, void *dest_val)
Scatter element values associated with a range set to the full set.
Definition: cs_range_set.cpp:1056
cs_range_set_t * cs_range_set_create(const cs_interface_set_t *ifs, const cs_halo_t *halo, cs_lnum_t n_elts, bool balance, int tr_ignore, cs_gnum_t g_id_base)
Create a range set (with associated range and global ids) for the partitioning of data based on local...
Definition: cs_range_set.cpp:678
void cs_range_set_destroy(cs_range_set_t **rs)
Destroy a range set structure.
Definition: cs_range_set.cpp:778
void cs_range_set_sync(const cs_range_set_t *rs, cs_datatype_t datatype, cs_lnum_t stride, void *val)
Synchronize values elements associated with a range set, using either a halo or an interface set.
Definition: cs_range_set.cpp:926
void cs_range_set_gather(const cs_range_set_t *rs, cs_datatype_t datatype, cs_lnum_t stride, const void *src_val, void *dest_val)
Gather element values associated with a range set to a compact set.
Definition: cs_range_set.cpp:983
void cs_range_set_define(const cs_interface_set_t *ifs, const cs_halo_t *halo, cs_lnum_t n_elts, bool balance, int tr_ignore, cs_gnum_t g_id_base, cs_gnum_t l_range[2], cs_gnum_t *g_id)
Define global ids and a partitioning of data based on local ranges for elements which may be shared a...
Definition: cs_range_set.cpp:574
void cs_range_set_zero_out_of_range(const cs_range_set_t *rs, cs_datatype_t datatype, cs_lnum_t stride, void *val)
Set values of a given array to zero for indexes of elements outside the local range.
Definition: cs_range_set.cpp:806
Definition: cs_halo.h:74
Definition: cs_range_set.h:53
const cs_interface_set_t * ifs
Definition: cs_range_set.h:66
const cs_halo_t * halo
Definition: cs_range_set.h:67
const cs_gnum_t * g_id
Definition: cs_range_set.h:61
cs_gnum_t * _g_id
Definition: cs_range_set.h:63