9.1
general documentation
cs_array_reduce.h
Go to the documentation of this file.
1#ifndef CS_ARRAY_REDUCE_H
2#define CS_ARRAY_REDUCE_H
3
4/*============================================================================
5 * Common array reduction operations.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 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#include "base/cs_dispatch.h"
36#include "base/cs_reducers.h"
37
38/*----------------------------------------------------------------------------*/
39
40/*=============================================================================
41 * Macro definitions
42 *============================================================================*/
43
44/*============================================================================
45 * Type definitions
46 *============================================================================*/
47
48#ifdef __cplusplus
49
50/*=============================================================================
51 * Public function prototypes
52 *============================================================================*/
53
54/*----------------------------------------------------------------------------*/
55/*
56 * \brief Compute the min./max. of a 1-dimensional array.
57 *
58 * \param[in] n local number of elements
59 * \param[in] v pointer to values (size: n)
60 * \param[out] vmin minimum value
61 * \param[out] vmax maximum value
62 */
63/*----------------------------------------------------------------------------*/
64
65void
67 const cs_real_t v[],
68 cs_real_t &vmin,
69 cs_real_t &vmax);
70
71/*----------------------------------------------------------------------------*/
89/*----------------------------------------------------------------------------*/
90
91template <size_t stride>
92void
94 cs_lnum_t n_elts,
95 const cs_lnum_t *v_elt_list,
96 const cs_real_t v[],
97 double vsum[])
98{
99 struct cs_double_n<stride> rd;
100 struct cs_reduce_sum_nr<stride> reducer;
101
102 /* If all values are defined on same list */
103 if (v_elt_list == nullptr) {
104 ctx.parallel_for_reduce(n_elts, rd, reducer,
106 for (size_t k = 0; k < stride; k++)
107 res.r[k] = v[stride*i + k];
108 });
109 }
110 /* If values are defined on parent list */
111 else {
112 ctx.parallel_for_reduce(n_elts, rd, reducer,
114 for (size_t k = 0; k < stride; k++)
115 res.r[k] = v[stride*v_elt_list[i] + k];
116 });
117 }
118 ctx.wait();
119
120 for (size_t k = 0; k < stride; k++)
121 vsum[k] = rd.r[k];
122}
123
124/*----------------------------------------------------------------------------*/
148/*----------------------------------------------------------------------------*/
149
150void
152 const cs_lnum_t n_elts,
153 const int dim,
154 const cs_lnum_t *v_elt_list,
155 const cs_real_t v[],
156 double vmin[],
157 double vmax[],
158 double vsum[]);
159
160/*----------------------------------------------------------------------------*/
187/*----------------------------------------------------------------------------*/
188
189void
191 int dim,
192 const cs_lnum_t *v_elt_list,
193 const cs_lnum_t *w_elt_list,
194 const cs_real_t v[],
195 const cs_real_t w[],
196 double wsum[]);
197
198/*----------------------------------------------------------------------------*/
228/*----------------------------------------------------------------------------*/
229
230void
232 int dim,
233 const cs_lnum_t *v_elt_list,
234 const cs_lnum_t *w_elt_list,
235 const cs_real_t v[],
236 const cs_real_t w[],
237 double wsum[],
238 double wtot[]);
239
240/*----------------------------------------------------------------------------*/
260/*----------------------------------------------------------------------------*/
261
262void
264 int dim,
265 const cs_lnum_t *v_elt_list,
266 const cs_real_t v[],
267 cs_real_t vmin[],
268 cs_real_t vmax[]);
269
270/*----------------------------------------------------------------------------*/
302/*----------------------------------------------------------------------------*/
303
304void
306 cs_lnum_t n_elts,
307 int dim,
308 const cs_lnum_t *v_elt_list,
309 const cs_lnum_t *w_elt_list,
310 const cs_real_t v[],
311 const cs_real_t w[],
312 double vmin[],
313 double vmax[],
314 double vsum[],
315 double wsum[]);
316
317/*----------------------------------------------------------------------------*/
352/*----------------------------------------------------------------------------*/
353
354void
356 int dim,
357 const cs_lnum_t *v_elt_list,
358 const cs_lnum_t *w_elt_list,
359 const cs_real_t v[],
360 const cs_real_t w[],
361 double vmin[],
362 double vmax[],
363 double vsum[],
364 double wsum[],
365 double asum[],
366 double ssum[],
367 double wssum[]);
368
369/*----------------------------------------------------------------------------*/
399/*----------------------------------------------------------------------------*/
400
401void
403 const cs_lnum_t *src2v_idx,
404 const cs_lnum_t *src2v_ids,
405 const cs_lnum_t *filter_list,
406 int dim,
407 cs_lnum_t n_v_elts,
408 const cs_real_t v[],
409 const cs_real_t w[],
410 double vsum[],
411 double asum[],
412 double ssum[]);
413
414/*----------------------------------------------------------------------------*/
415
416#endif // __cplusplus
417
418#endif /*CS_ARRAY_REDUCE_H */
auto parallel_for_reduce(cs_lnum_t n, T &result, R &reducer, F &&f, Args &&... args)
Definition: cs_dispatch.h:1619
void wait(void)
Wait (synchronize) until launched computations have finished.
Definition: cs_dispatch.h:1635
Definition: cs_dispatch.h:1711
void cs_array_reduce_sum_l(cs_dispatch_context ctx, cs_lnum_t n_elts, const cs_lnum_t *v_elt_list, const cs_real_t v[], double vsum[])
Compute sums of an n-dimensional cs_real_t array's components.
Definition: cs_array_reduce.h:93
void cs_array_reduce_minmax(cs_lnum_t n, const cs_real_t v[], cs_real_t &vmin, cs_real_t &vmax)
Compute the min./max. of a 1-dimensional array.
Definition: cs_array_reduce.cpp:2669
void cs_array_reduce_simple_norms_l(cs_lnum_t n_elts, int dim, const cs_lnum_t *v_elt_list, const cs_lnum_t *w_elt_list, const cs_real_t v[], const cs_real_t w[], double vmin[], double vmax[], double vsum[], double wsum[], double asum[], double ssum[], double wssum[])
Compute simple local stats and norms (minima, maxima, sum, weighted sum, sum of absolute values,...
Definition: cs_array_reduce.cpp:3122
void cs_array_reduce_wsum_components_l(cs_lnum_t n_elts, int dim, const cs_lnum_t *v_elt_list, const cs_lnum_t *w_elt_list, const cs_real_t v[], const cs_real_t w[], double wsum[], double wtot[])
Compute weighted sums of an n-dimensional cs_real_t array's components. Output is both weighted sum a...
Definition: cs_array_reduce.cpp:2881
void cs_array_reduce_simple_stats_l(cs_dispatch_context ctx, const cs_lnum_t n_elts, const int dim, const cs_lnum_t *v_elt_list, const cs_real_t v[], double vmin[], double vmax[], double vsum[])
Compute simple local stats (minima, maxima, sum) of an n-dimensional cs_real_t array's components.
Definition: cs_array_reduce.cpp:2732
void cs_array_reduce_simple_stats_l_w(cs_dispatch_context ctx, cs_lnum_t n_elts, int dim, const cs_lnum_t *v_elt_list, const cs_lnum_t *w_elt_list, const cs_real_t v[], const cs_real_t w[], double vmin[], double vmax[], double vsum[], double wsum[])
Compute simple local stats (minima, maxima, sum, weighted sum) of an n-dimensional cs_real_t array's ...
Definition: cs_array_reduce.cpp:3021
void cs_array_reduce_minmax_l(cs_lnum_t n_elts, int dim, const cs_lnum_t *v_elt_list, const cs_real_t v[], cs_real_t vmin[], cs_real_t vmax[])
Compute sums of an n-dimensional cs_real_t array's components.
Definition: cs_array_reduce.cpp:2953
void cs_array_reduce_wsum_l(cs_lnum_t n_elts, int dim, const cs_lnum_t *v_elt_list, const cs_lnum_t *w_elt_list, const cs_real_t v[], const cs_real_t w[], double wsum[])
Compute weighted sums of an n-dimensional cs_real_t array's components.
Definition: cs_array_reduce.cpp:2800
void cs_array_scatter_reduce_norms_l(cs_lnum_t n_src_elts, const cs_lnum_t *src2v_idx, const cs_lnum_t *src2v_ids, const cs_lnum_t *filter_list, int dim, cs_lnum_t n_v_elts, const cs_real_t v[], const cs_real_t w[], double vsum[], double asum[], double ssum[])
Compute simple local weighted norms (l1, l2) of an n-dimensional cs_real_t array's components The wei...
Definition: cs_array_reduce.cpp:3212
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:585
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
@ k
Definition: cs_field_pointer.h:72
Definition: cs_reducers.h:66
double r[stride]
Definition: cs_reducers.h:67
Definition: cs_reducers.h:203