7.0
general documentation
cs_parall.h
Go to the documentation of this file.
1 #ifndef __CS_PARALL_H__
2 #define __CS_PARALL_H__
3 
4 /*============================================================================
5  * Functions dealing with parallelism
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2022 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 "cs_defs.h"
35 
36 /*----------------------------------------------------------------------------*/
37 
39 
40 /*=============================================================================
41  * Public function prototypes
42  *============================================================================*/
43 
44 /*----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------*/
52 
53 #if defined(HAVE_MPI_IN_PLACE)
54 
55 inline static void
57  const int n)
58 {
59  if (cs_glob_n_ranks > 1) {
60  MPI_Allreduce(MPI_IN_PLACE, cpt, n, CS_MPI_GNUM, MPI_SUM,
62  }
63 }
64 
65 #elif defined(HAVE_MPI)
66 
67 void
69  const int n);
70 
71 #else
72 
73 #define cs_parall_counter(_cpt, _n)
74 
75 #endif
76 
77 /*----------------------------------------------------------------------------*/
84 /*----------------------------------------------------------------------------*/
85 
86 #if defined(HAVE_MPI_IN_PLACE)
87 
88 inline static void
90  const int n)
91 {
92  if (cs_glob_n_ranks > 1) {
93  MPI_Allreduce(MPI_IN_PLACE, cpt, n, CS_MPI_LNUM, MPI_MAX,
95  }
96 }
97 
98 #elif defined(HAVE_MPI)
99 
100 void
102  const int n);
103 
104 #else
105 
106 #define cs_parall_counter_max(_cpt, _n)
107 
108 #endif
109 
110 /*----------------------------------------------------------------------------*/
118 /*----------------------------------------------------------------------------*/
119 
120 #if defined(HAVE_MPI_IN_PLACE)
121 
122 inline static void
124  cs_datatype_t datatype,
125  void *val)
126 {
127  if (cs_glob_n_ranks > 1) {
128  MPI_Allreduce(MPI_IN_PLACE, val, n, cs_datatype_to_mpi[datatype], MPI_SUM,
130  }
131 }
132 
133 #elif defined(HAVE_MPI)
134 
135 void
136 cs_parall_sum(int n,
137  cs_datatype_t datatype,
138  void *val);
139 
140 #else
141 
142 #define cs_parall_sum(_n, _datatype, _val) { };
143 
144 #endif
145 
146 /*----------------------------------------------------------------------------*/
155 /*----------------------------------------------------------------------------*/
156 
157 #if defined(HAVE_MPI_IN_PLACE)
158 
159 inline static void
161  cs_datatype_t datatype,
162  void *val)
163 {
164  if (cs_glob_n_ranks > 1) {
165  MPI_Allreduce(MPI_IN_PLACE, val, n, cs_datatype_to_mpi[datatype], MPI_MAX,
167  }
168 }
169 
170 #elif defined(HAVE_MPI)
171 
172 void
173 cs_parall_max(int n,
174  cs_datatype_t datatype,
175  void *val);
176 
177 #else
178 
179 #define cs_parall_max(_n, _datatype, _val);
180 
181 #endif
182 
183 /*----------------------------------------------------------------------------*/
192 /*----------------------------------------------------------------------------*/
193 
194 #if defined(HAVE_MPI_IN_PLACE)
195 
196 inline static void
198  cs_datatype_t datatype,
199  void *val)
200 {
201  if (cs_glob_n_ranks > 1) {
202  MPI_Allreduce(MPI_IN_PLACE, val, n, cs_datatype_to_mpi[datatype], MPI_MIN,
204  }
205 }
206 
207 #elif defined(HAVE_MPI)
208 
209 void
210 cs_parall_min(int n,
211  cs_datatype_t datatype,
212  void *val);
213 
214 #else
215 
216 #define cs_parall_min(_n, _datatype, _val);
217 
218 #endif
219 
220 /*----------------------------------------------------------------------------*/
231 /*----------------------------------------------------------------------------*/
232 
233 #if defined(HAVE_MPI)
234 
235 inline static void
236 cs_parall_bcast(int root_rank,
237  int n,
238  cs_datatype_t datatype,
239  void *val)
240 {
241  if (cs_glob_n_ranks > 1)
242  MPI_Bcast(val, n, cs_datatype_to_mpi[datatype], root_rank,
244 }
245 
246 #else
247 
248 #define cs_parall_bcast(_root_rank, _n, _datatype, _val);
249 
250 #endif
251 
252 /*----------------------------------------------------------------------------
253  * Build a global array from each local array in each domain.
254  *
255  * Local arrays are appended in order of owning MPI rank.
256  * The size of each local array may be different.
257  *
258  * Use of this function may be quite practical, but should be limited
259  * to user functions, as it may limit scalability (especially as regards
260  * memory usage).
261  *
262  * parameters:
263  * n_elts <-- size of the local array
264  * n_g_elts <-- size of the global array
265  * array <-- local array (size: n_elts)
266  * g_array --> global array (size: n_g_elts)
267  *----------------------------------------------------------------------------*/
268 
269 void
270 cs_parall_allgather_r(int n_elts,
271  int n_g_elts,
272  cs_real_t array[],
273  cs_real_t g_array[]);
274 
275 /*----------------------------------------------------------------------------
276  * Maximum value of a real and the value of related array on all
277  * default communicator processes.
278  *
279  * parameters:
280  * n <-- size of the related array
281  * max <-> local max in, global max out
282  * max_loc_vals <-> array values at location of local max in,
283  * and at location of global max out
284  *----------------------------------------------------------------------------*/
285 
286 void
288  cs_real_t *max,
289  cs_real_t max_loc_vals[]);
290 
291 /*----------------------------------------------------------------------------
292  * Minimum value of a real and the value of related array on all
293  * default communicator processes.
294  *
295  * parameters:
296  * n <-- size of the related array
297  * min <-> local min in, global min out
298  * min_loc_vals <-> array values at location of local min in,
299  * and at location of global min out
300  *----------------------------------------------------------------------------*/
301 
302 void
304  cs_real_t *min,
305  cs_real_t min_loc_vals[]);
306 
307 /*----------------------------------------------------------------------------
308  * Given an (id, rank, value) tuple, return the local id and rank
309  * corresponding to the global minimum value.
310  *
311  * parameters:
312  * elt_id <-> element id for which the value is the smallest
313  * (local in, global out)
314  * rank_id <-> rank id for which the value is the smallest
315  * (local in, global out)
316  * val <-- associated local minimum value
317  *----------------------------------------------------------------------------*/
318 
319 void
321  int *rank_id,
322  cs_real_t dis2mn);
323 
324 /*----------------------------------------------------------------------------
325  * Return minimum recommended scatter or gather buffer size.
326  *
327  * This is used by some internal part to block or scatter/gather algorithms,
328  * so as to allow I/O buffer size tuning.
329  *
330  * returns:
331  * minimum recommended part to block or gather buffer size (in bytes)
332  *----------------------------------------------------------------------------*/
333 
334 size_t
336 
337 /*----------------------------------------------------------------------------
338  * Define minimum recommended gather buffer size.
339  *
340  * This is used by some internal part to block or scatter/gather algorithms,
341  * so as to allow I/O buffer size tuning.
342  *
343  * parameters:
344  * minimum recommended part to block or gather buffer size (in bytes)
345  *----------------------------------------------------------------------------*/
346 
347 void
348 cs_parall_set_min_coll_buf_size(size_t buffer_size);
349 
350 /*----------------------------------------------------------------------------*/
351 
353 
354 #endif /* __CS_PARALL_H__ */
static void cs_parall_counter(cs_gnum_t cpt[], const int n)
Sum values of a counter on all default communicator processes.
Definition: cs_parall.h:56
cs_datatype_t
Definition: cs_defs.h:260
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
#define BEGIN_C_DECLS
Definition: cs_defs.h:495
static void cs_parall_counter_max(cs_lnum_t cpt[], const int n)
Maximum values of a counter on all default communicator processes.
Definition: cs_parall.h:89
int cs_glob_n_ranks
Definition: cs_defs.c:175
static void cs_parall_bcast(int root_rank, int n, cs_datatype_t datatype, void *val)
Broadcast values of a given datatype to all default communicator processes.
Definition: cs_parall.h:236
double cs_real_t
Floating-point value.
Definition: cs_defs.h:307
void cs_parall_min_loc_vals(int n, cs_real_t *min, cs_real_t min_loc_vals[])
Minimum value of a real and the value of related array on all default communicator processes...
Definition: cs_parall.c:740
MPI_Datatype cs_datatype_to_mpi[]
Definition: cs_defs.c:157
size_t cs_parall_get_min_coll_buf_size(void)
Return minimum recommended scatter or gather buffer size.
Definition: cs_parall.c:899
void cs_parall_min_id_rank_r(cs_lnum_t *elt_id, int *rank_id, cs_real_t dis2mn)
Given an (id, rank, value) tuple, return the local id and rank corresponding to the global minimum va...
Definition: cs_parall.c:779
#define CS_MPI_GNUM
Definition: cs_defs.h:371
void cs_parall_set_min_coll_buf_size(size_t buffer_size)
Define minimum recommended scatter or gather buffer size.
Definition: cs_parall.c:921
static void cs_parall_max(int n, cs_datatype_t datatype, void *val)
Maximum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:160
MPI_Comm cs_glob_mpi_comm
Definition: cs_defs.c:179
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:301
void cs_parall_max_loc_vals(int n, cs_real_t *max, cs_real_t max_loc_vals[])
Maximum value of a real and the value of related array on all default communicator processes...
Definition: cs_parall.c:702
#define CS_MPI_LNUM
Definition: cs_defs.h:391
#define END_C_DECLS
Definition: cs_defs.h:496
static void cs_parall_sum(int n, cs_datatype_t datatype, void *val)
Sum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:123
void cs_parall_allgather_r(int n_elts, int n_g_elts, cs_real_t array[], cs_real_t g_array[])
Build a global array from each local array in each domain.
Definition: cs_parall.c:833
static void cs_parall_min(int n, cs_datatype_t datatype, void *val)
Minimum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:197