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