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-2021 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 /*----------------------------------------------------------------------------
45  * Sum values of a counter on all default communicator processes.
46  *
47  * parameters:
48  * cpt <-> local counter in, global counter out (size: n)
49  * n <-- number of values
50  *----------------------------------------------------------------------------*/
51 
52 #if defined(HAVE_MPI_IN_PLACE)
53 
54 inline static void
55 cs_parall_counter(cs_gnum_t cpt[],
56  const int n)
57 {
58  if (cs_glob_n_ranks > 1) {
59  MPI_Allreduce(MPI_IN_PLACE, cpt, n, CS_MPI_GNUM, MPI_SUM,
61  }
62 }
63 
64 #elif defined(HAVE_MPI)
65 
66 void
67 cs_parall_counter(cs_gnum_t cpt[],
68  const int n);
69 
70 #else
71 
72 #define cs_parall_counter(_cpt, _n)
73 
74 #endif
75 
76 /*----------------------------------------------------------------------------
77  * Maximum values of a counter on all default communicator processes.
78  *
79  * parameters:
80  * cpt <-> local counter in, global counter out (size: n)
81  * n <-> number of values
82  *----------------------------------------------------------------------------*/
83 
84 #if defined(HAVE_MPI_IN_PLACE)
85 
86 inline static void
87 cs_parall_counter_max(cs_lnum_t cpt[],
88  const int n)
89 {
90  if (cs_glob_n_ranks > 1) {
91  MPI_Allreduce(MPI_IN_PLACE, cpt, n, CS_MPI_LNUM, MPI_MAX,
93  }
94 }
95 
96 #elif defined(HAVE_MPI)
97 
98 void
99 cs_parall_counter_max(cs_lnum_t cpt[],
100  const int n);
101 
102 #else
103 
104 #define cs_parall_counter_max(_cpt, _n)
105 
106 #endif
107 
108 /*----------------------------------------------------------------------------
109  * Sum values of a given datatype on all default communicator processes.
110  *
111  * parameters:
112  * n <-- number of values
113  * datatype <-- matching Code_Saturne datatype
114  * val <-> local sum in, global sum out (array)
115  *----------------------------------------------------------------------------*/
116 
117 #if defined(HAVE_MPI_IN_PLACE)
118 
119 inline static void
120 cs_parall_sum(int n,
121  cs_datatype_t datatype,
122  void *val)
123 {
124  if (cs_glob_n_ranks > 1) {
125  MPI_Allreduce(MPI_IN_PLACE, val, n, cs_datatype_to_mpi[datatype], MPI_SUM,
127  }
128 }
129 
130 #elif defined(HAVE_MPI)
131 
132 void
133 cs_parall_sum(int n,
134  cs_datatype_t datatype,
135  void *val);
136 
137 #else
138 
139 #define cs_parall_sum(_n, _datatype, _val) { };
140 
141 #endif
142 
143 /*----------------------------------------------------------------------------
144  * Maximum values of a given datatype on all default communicator processes.
145  *
146  * parameters:
147  * n <-- number of values
148  * datatype <-- matching Code_Saturne datatype
149  * val <-> local value input, global value output (array)
150  *----------------------------------------------------------------------------*/
151 
152 #if defined(HAVE_MPI_IN_PLACE)
153 
154 inline static void
155 cs_parall_max(int n,
156  cs_datatype_t datatype,
157  void *val)
158 {
159  if (cs_glob_n_ranks > 1) {
160  MPI_Allreduce(MPI_IN_PLACE, val, n, cs_datatype_to_mpi[datatype], MPI_MAX,
162  }
163 }
164 
165 #elif defined(HAVE_MPI)
166 
167 void
168 cs_parall_max(int n,
169  cs_datatype_t datatype,
170  void *val);
171 
172 #else
173 
174 #define cs_parall_max(_n, _datatype, _val);
175 
176 #endif
177 
178 /*----------------------------------------------------------------------------
179  * Minimum values of a given datatype on all default communicator processes.
180  *
181  * parameters:
182  * n <-- number of values
183  * datatype <-- matching Code_Saturne datatype
184  * val <-> local value input, global value output (array)
185  *----------------------------------------------------------------------------*/
186 
187 #if defined(HAVE_MPI_IN_PLACE)
188 
189 inline static void
190 cs_parall_min(int n,
191  cs_datatype_t datatype,
192  void *val)
193 {
194  if (cs_glob_n_ranks > 1) {
195  MPI_Allreduce(MPI_IN_PLACE, val, n, cs_datatype_to_mpi[datatype], MPI_MIN,
197  }
198 }
199 
200 #elif defined(HAVE_MPI)
201 
202 void
203 cs_parall_min(int n,
204  cs_datatype_t datatype,
205  void *val);
206 
207 #else
208 
209 #define cs_parall_min(_n, _datatype, _val);
210 
211 #endif
212 
213 /*----------------------------------------------------------------------------
214  * Broadcast values of a given datatype to all
215  * default communicator processes.
216  *
217  * parameters:
218  * root_rank <-- rank from which to broadcast
219  * n <-- number of values
220  * datatype <-- matching Code_Saturne datatype
221  * val <-- values to broadcast; input on root_rank,
222  * output on others (size: n)
223  *----------------------------------------------------------------------------*/
224 
225 #if defined(HAVE_MPI)
226 
227 inline static void
228 cs_parall_bcast(int root_rank,
229  int n,
230  cs_datatype_t datatype,
231  void *val)
232 {
233  if (cs_glob_n_ranks > 1)
234  MPI_Bcast(val, n, cs_datatype_to_mpi[datatype], root_rank,
236 }
237 
238 #else
239 
240 #define cs_parall_bcast(_root_rank, _n, _datatype, _val);
241 
242 #endif
243 
244 /*----------------------------------------------------------------------------
245  * Build a global array from each local array in each domain.
246  *
247  * Local arrays are appended in order of owning MPI rank.
248  * The size of each local array may be different.
249  *
250  * Use of this function may be quite practical, but should be limited
251  * to user functions, as it may limit scalability (especially as regards
252  * memory usage).
253  *
254  * parameters:
255  * n_elts <-- size of the local array
256  * n_g_elts <-- size of the global array
257  * array <-- local array (size: n_elts)
258  * g_array --> global array (size: n_g_elts)
259  *----------------------------------------------------------------------------*/
260 
261 void
262 cs_parall_allgather_r(int n_elts,
263  int n_g_elts,
264  cs_real_t array[],
265  cs_real_t g_array[]);
266 
267 /*----------------------------------------------------------------------------
268  * Maximum value of a real and the value of related array on all
269  * default communicator processes.
270  *
271  * parameters:
272  * n <-- size of the related array
273  * max <-> local max in, global max out
274  * max_loc_vals <-> array values at location of local max in,
275  * and at location of global max out
276  *----------------------------------------------------------------------------*/
277 
278 void
280  cs_real_t *max,
281  cs_real_t max_loc_vals[]);
282 
283 /*----------------------------------------------------------------------------
284  * Minimum value of a real and the value of related array on all
285  * default communicator processes.
286  *
287  * parameters:
288  * n <-- size of the related array
289  * min <-> local min in, global min out
290  * min_loc_vals <-> array values at location of local min in,
291  * and at location of global min out
292  *----------------------------------------------------------------------------*/
293 
294 void
296  cs_real_t *min,
297  cs_real_t min_loc_vals[]);
298 
299 /*----------------------------------------------------------------------------
300  * Given an (id, rank, value) tuple, return the local id and rank
301  * corresponding to the global minimum value.
302  *
303  * parameters:
304  * elt_id <-> element id for which the value is the smallest
305  * (local in, global out)
306  * rank_id <-> rank id for which the value is the smallest
307  * (local in, global out)
308  * val <-- associated local minimum value
309  *----------------------------------------------------------------------------*/
310 
311 void
313  int *rank_id,
314  cs_real_t dis2mn);
315 
316 /*----------------------------------------------------------------------------
317  * Return minimum recommended scatter or gather buffer size.
318  *
319  * This is used by some internal part to block or scatter/gather algorithms,
320  * so as to allow I/O buffer size tuning.
321  *
322  * returns:
323  * minimum recommended part to block or gather buffer size (in bytes)
324  *----------------------------------------------------------------------------*/
325 
326 size_t
328 
329 /*----------------------------------------------------------------------------
330  * Define minimum recommended gather buffer size.
331  *
332  * This is used by some internal part to block or scatter/gather algorithms,
333  * so as to allow I/O buffer size tuning.
334  *
335  * parameters:
336  * minimum recommended part to block or gather buffer size (in bytes)
337  *----------------------------------------------------------------------------*/
338 
339 void
340 cs_parall_set_min_coll_buf_size(size_t buffer_size);
341 
342 /*----------------------------------------------------------------------------*/
343 
345 
346 #endif /* __CS_PARALL_H__ */
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
int cs_glob_n_ranks
Definition: cs_defs.c:175
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
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
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