My Project
programmer's documentation
cs_halo.h
Go to the documentation of this file.
1 #ifndef __CS_HALO_H__
2 #define __CS_HALO_H__
3 
4 /*============================================================================
5  * Structure and function headers handling with ghost cells
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_base.h"
35 #include "cs_interface.h"
36 #include "cs_rank_neighbors.h"
37 
38 #include "fvm_periodicity.h"
39 
40 /*----------------------------------------------------------------------------*/
41 
43 
44 /*=============================================================================
45  * Type definitions
46  *============================================================================*/
47 
48 /* Halo type */
49 
50 typedef enum {
51 
55 
57 
58 /* Options for cs_halo_sync_component(). */
59 
60 typedef enum {
61 
62  CS_HALO_ROTATION_COPY, /* Copy halo */
63  CS_HALO_ROTATION_ZERO, /* Set rotation halo values to zero */
64  CS_HALO_ROTATION_IGNORE /* Do not modify rotation halo values */
65 
67 
68 /* Structure for halo management */
69 /* ----------------------------- */
70 
71 typedef struct {
72 
73  int n_c_domains; /* Number of communicating domains. */
74  int n_transforms; /* Number of periodic transformations */
75 
76  int *c_domain_rank; /* List of communicating ranks */
77 
78  const fvm_periodicity_t * periodicity; /* Pointer to periodicity
79  structure describing transforms */
80 
81  int n_rotations; /* Number of periodic transformations
82  involving rotations */
83 
84  cs_lnum_t n_local_elts; /* Number of local elements */
85 
86  /* send_halo features : send to distant ranks */
87 
88  cs_lnum_t n_send_elts[2]; /* Numer of ghost elements in send_list
89  n_elts[0] = standard elements
90  n_elts[1] = extended + standard elements */
91 
92  cs_lnum_t *send_list; /* List of local elements in distant halos
93  (0 to n-1 numbering) */
94 
95  cs_lnum_t *send_index; /* Index on send_list
96  Size = 2*n_c_domains + 1. For each rank, we
97  have an index for standard halo and one
98  for extended halo. */
99 
100  cs_lnum_t *send_perio_lst ; /* For each transformation and for each type of
101  halo on each communicating rank, we store
102  2 values:
103  - start index,
104  - number of elements. */
105 
106  /* halo features : receive from distant ranks */
107 
108  cs_lnum_t n_elts[2]; /* Numer of ghost elements in halo
109  n_elts[0] = standard elements
110  n_elts[1] = extended + standard elements */
111 
112  cs_lnum_t *index; /* Index on halo sections;
113  Size = 2*n_c_domains. For each rank, we
114  have an index for the standard halo and one
115  for the extended halo. */
116 
117  cs_lnum_t *perio_lst; /* For each transformation and for each type of halo
118  on each communicating rank, we store 2 values:
119  - start index,
120  - number of elements. */
121 
122  /* Organisation of perio_lst:
123 
124  -------------------------------------------------
125  T1: | | | | | | | | | | | | |
126  -------------------------------------------------
127  idx n idx n idx n idx n idx n idx n
128  ______ ______ ______ ______ ______ ______
129  std ext std ext std ext
130  ___________ ___________ ___________
131  rank 0 rank 1 rank 2
132 
133  -------------------------------------------------
134  T2: | | | | | | | | | | | | |
135  -------------------------------------------------
136  idx n idx n idx n idx n idx n idx n
137  ______ ______ ______ ______ ______ ______
138  std ext std ext std ext
139  ___________ ___________ ___________
140  rank 0 rank 1 rank 2
141 
142  -------------------------------------------------
143  T3: | | | | | | | | | | | | |
144  -------------------------------------------------
145  idx n idx n idx n idx n idx n idx n
146  ______ ______ ______ ______ ______ ______
147  std ext std ext std ext
148  ___________ ___________ ___________
149  rank 0 rank 1 rank 2
150 
151  etc...
152 
153  */
154 
155 } cs_halo_t;
156 
157 /*=============================================================================
158  * Global static variables
159  *============================================================================*/
160 
161 /*============================================================================
162  * Public function header for Fortran API
163  *============================================================================*/
164 
165 /*=============================================================================
166  * Public function prototypes
167  *============================================================================*/
168 
169 /*----------------------------------------------------------------------------*/
177 /*----------------------------------------------------------------------------*/
178 
179 cs_halo_t *
181 
182 /*----------------------------------------------------------------------------*/
190 /*----------------------------------------------------------------------------*/
191 
192 cs_halo_t *
194 
195 #if defined(HAVE_MPI)
196 
197 /*----------------------------------------------------------------------------*/
221 /*----------------------------------------------------------------------------*/
222 
223 cs_halo_t *
225  cs_lnum_t n_local_elts,
226  cs_lnum_t n_distant_elts,
227  const int elt_rank_id[],
228  const cs_lnum_t elt_id[]);
229 
230 #endif /* HAVE_MPI */
231 
232 /*----------------------------------------------------------------------------*/
238 /*----------------------------------------------------------------------------*/
239 
240 void
241 cs_halo_destroy(cs_halo_t **halo);
242 
243 /*----------------------------------------------------------------------------
244  * Update global buffer sizes so as to be usable with a given halo.
245  *
246  * Calls to halo synchronizations with variable strides up to 3 are
247  * expected. For strides greater than 3, the halo will be resized if
248  * necessary directly by the synchronization function.
249  *
250  * This function should be called at the end of any halo creation,
251  * so that buffer sizes are increased if necessary.
252  *
253  * parameters:
254  * halo <-- pointer to cs_halo_t structure.
255  *---------------------------------------------------------------------------*/
256 
257 void
258 cs_halo_update_buffers(const cs_halo_t *halo);
259 
260 /*----------------------------------------------------------------------------
261  * Free global halo backup buffer.
262  *---------------------------------------------------------------------------*/
263 
264 void
265 cs_halo_free_buffer(void);
266 
267 /*----------------------------------------------------------------------------
268  * Apply local cells renumbering to a halo
269  *
270  * parameters:
271  * halo <-- pointer to halo structure
272  * new_cell_id <-- array indicating old -> new cell id (0 to n-1)
273  *---------------------------------------------------------------------------*/
274 
275 void
277  const cs_lnum_t new_cell_id[]);
278 
279 /*----------------------------------------------------------------------------
280  * Apply ghost cells renumbering to a halo
281  *
282  * parameters:
283  * halo <-- pointer to halo structure
284  * old_cell_id <-- array indicating new -> old cell id (0 to n-1)
285  *---------------------------------------------------------------------------*/
286 
287 void
289  const cs_lnum_t old_cell_id[]);
290 
291 /*----------------------------------------------------------------------------
292  * Update array of any type of halo values in case of parallelism or
293  * periodicity.
294  *
295  * Data is untyped; only its size is given, so this function may also
296  * be used to synchronize interleaved multidimendsional data, using
297  * size = element_size*dim (assuming a homogeneous environment, at least
298  * as far as data encoding goes).
299  *
300  * This function aims at copying main values from local elements
301  * (id between 1 and n_local_elements) to ghost elements on distant ranks
302  * (id between n_local_elements + 1 to n_local_elements_with_halo).
303  *
304  * parameters:
305  * halo <-- pointer to halo structure
306  * sync_mode <-- synchronization mode (standard or extended)
307  * size <-- size of each element
308  * num <-> pointer to local number value array
309  *----------------------------------------------------------------------------*/
310 
311 void
312 cs_halo_sync_untyped(const cs_halo_t *halo,
313  cs_halo_type_t sync_mode,
314  size_t size,
315  void *val);
316 
317 /*----------------------------------------------------------------------------
318  * Update array of integer halo values in case of parallelism or periodicity.
319  *
320  * This function aims at copying main values from local elements
321  * (id between 1 and n_local_elements) to ghost elements on distant ranks
322  * (id between n_local_elements + 1 to n_local_elements_with_halo).
323  *
324  * parameters:
325  * halo <-- pointer to halo structure
326  * sync_mode <-- synchronization mode (standard or extended)
327  * num <-> pointer to local number value array
328  *----------------------------------------------------------------------------*/
329 
330 void
331 cs_halo_sync_num(const cs_halo_t *halo,
332  cs_halo_type_t sync_mode,
333  cs_lnum_t num[]);
334 
335 /*----------------------------------------------------------------------------
336  * Update array of variable (floating-point) halo values in case of
337  * parallelism or periodicity.
338  *
339  * This function aims at copying main values from local elements
340  * (id between 1 and n_local_elements) to ghost elements on distant ranks
341  * (id between n_local_elements + 1 to n_local_elements_with_halo).
342  *
343  * parameters:
344  * halo <-- pointer to halo structure
345  * sync_mode <-- synchronization mode (standard or extended)
346  * var <-> pointer to variable value array
347  *----------------------------------------------------------------------------*/
348 
349 void
350 cs_halo_sync_var(const cs_halo_t *halo,
351  cs_halo_type_t sync_mode,
352  cs_real_t var[]);
353 
354 /*----------------------------------------------------------------------------
355  * Update array of strided variable (floating-point) halo values in case
356  * of parallelism or periodicity.
357  *
358  * This function aims at copying main values from local elements
359  * (id between 1 and n_local_elements) to ghost elements on distant ranks
360  * (id between n_local_elements + 1 to n_local_elements_with_halo).
361  *
362  * parameters:
363  * halo <-- pointer to halo structure
364  * sync_mode <-- synchronization mode (standard or extended)
365  * var <-> pointer to variable value array
366  * stride <-- number of (interlaced) values by entity
367  *----------------------------------------------------------------------------*/
368 
369 void
371  cs_halo_type_t sync_mode,
372  cs_real_t var[],
373  int stride);
374 
375 /*----------------------------------------------------------------------------
376  * Update array of vector variable component (floating-point) halo values
377  * in case of parallelism or periodicity.
378  *
379  * This function aims at copying main values from local elements
380  * (id between 1 and n_local_elements) to ghost elements on distant ranks
381  * (id between n_local_elements + 1 to n_local_elements_with_halo).
382  *
383  * If rotation_op is equal to CS_HALO_ROTATION_IGNORE, halo values
384  * corresponding to periodicity with rotation are left unchanged from their
385  * previous values.
386  *
387  * If rotation_op is equal to CS_HALO_ROTATION_ZERO, halo values
388  * corresponding to periodicity with rotation are set to 0.
389  *
390  * If rotation_op is equal to CS_HALO_ROTATION_COPY, halo values
391  * corresponding to periodicity with rotation are exchanged normally, so
392  * the behavior is the same as that of cs_halo_sync_var().
393  *
394  * parameters:
395  * halo <-- pointer to halo structure
396  * sync_mode <-- synchronization mode (standard or extended)
397  * rotation_op <-- rotation operation
398  * var <-> pointer to variable value array
399  *----------------------------------------------------------------------------*/
400 
401 void
403  cs_halo_type_t sync_mode,
404  cs_halo_rotation_t rotation_op,
405  cs_real_t var[]);
406 
407 /*----------------------------------------------------------------------------
408  * Update array of strided vector variable components (floating-point)
409  * halo values in case of parallelism or periodicity.
410  *
411  * This function aims at copying main values from local elements
412  * (id between 1 and n_local_elements) to ghost elements on distant ranks
413  * (id between n_local_elements + 1 to n_local_elements_with_halo).
414  *
415  * If rotation_op is equal to CS_HALO_ROTATION_IGNORE, halo values
416  * corresponding to periodicity with rotation are left unchanged from their
417  * previous values.
418  *
419  * If rotation_op is equal to CS_HALO_ROTATION_ZERO, halo values
420  * corresponding to periodicity with rotation are set to 0.
421  *
422  * If rotation_op is equal to CS_HALO_ROTATION_COPY, halo values
423  * corresponding to periodicity with rotation are exchanged normally, so
424  * the behavior is the same as that of cs_halo_sync_var_strided().
425  *
426  * parameters:
427  * halo <-- pointer to halo structure
428  * sync_mode <-- synchronization mode (standard or extended)
429  * rotation_op <-- rotation operation
430  * var <-> pointer to variable value array
431  * stride <-- number of (interlaced) values by entity
432  *----------------------------------------------------------------------------*/
433 
434 void
436  cs_halo_type_t sync_mode,
437  cs_halo_rotation_t rotation_op,
438  cs_real_t var[],
439  int stride);
440 
441 /*----------------------------------------------------------------------------
442  * Return MPI_Barrier usage flag.
443  *
444  * returns:
445  * true if MPI barriers are used after posting receives and before posting
446  * sends, false otherwise
447  *---------------------------------------------------------------------------*/
448 
449 bool
451 
452 /*----------------------------------------------------------------------------
453  * Set MPI_Barrier usage flag.
454  *
455  * parameters:
456  * use_barrier <-- true if MPI barriers should be used after posting
457  * receives and before posting sends, false otherwise.
458  *---------------------------------------------------------------------------*/
459 
460 void
461 cs_halo_set_use_barrier(bool use_barrier);
462 
463 /*----------------------------------------------------------------------------
464  * Dump a cs_halo_t structure.
465  *
466  * parameters:
467  * halo <-- pointer to cs_halo_t struture
468  * print_level <-- 0 only dimensions and indexes are printed, else (1)
469  * everything is printed
470  *---------------------------------------------------------------------------*/
471 
472 void
473 cs_halo_dump(const cs_halo_t *halo,
474  int print_level);
475 
476 /*----------------------------------------------------------------------------*/
477 
479 
480 #endif /* __CS_HALO_H__ */
cs_halo_dump
void cs_halo_dump(const cs_halo_t *halo, int print_level)
Definition: cs_halo.c:1825
CS_HALO_ROTATION_ZERO
Definition: cs_halo.h:63
CS_HALO_ROTATION_COPY
Definition: cs_halo.h:62
var
void cs_int_t cs_real_t var[]
Definition: cs_parall.h:63
cs_halo_t::send_perio_lst
cs_lnum_t * send_perio_lst
Definition: cs_halo.h:100
cs_halo_t::n_c_domains
int n_c_domains
Definition: cs_halo.h:73
cs_interface_set_t
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:61
cs_halo_get_use_barrier
bool cs_halo_get_use_barrier(void)
Definition: cs_halo.c:1796
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_halo_set_use_barrier
void cs_halo_set_use_barrier(bool use_barrier)
Definition: cs_halo.c:1810
cs_halo_t::send_index
cs_lnum_t * send_index
Definition: cs_halo.h:95
cs_halo_renumber_ghost_cells
void cs_halo_renumber_ghost_cells(cs_halo_t *halo, const cs_lnum_t old_cell_id[])
Definition: cs_halo.c:939
cs_halo_sync_component
void cs_halo_sync_component(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_halo_rotation_t rotation_op, cs_real_t var[])
Definition: cs_halo.c:1719
cs_halo_t::perio_lst
cs_lnum_t * perio_lst
Definition: cs_halo.h:117
cs_halo_t::c_domain_rank
int * c_domain_rank
Definition: cs_halo.h:76
cs_halo_create_from_ref
cs_halo_t * cs_halo_create_from_ref(const cs_halo_t *ref)
Create a halo structure, given a reference halo.
Definition: cs_halo.c:463
cs_halo_create
cs_halo_t * cs_halo_create(const cs_interface_set_t *ifs)
Create a halo structure given an interface set.
Definition: cs_halo.c:331
cs_halo_sync_num
void cs_halo_sync_num(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_lnum_t num[])
Definition: cs_halo.c:1260
stride
void const cs_int_t const cs_int_t const cs_int_t const cs_int_t * stride
Definition: cs_sat_coupling.h:325
cs_halo_t::n_rotations
int n_rotations
Definition: cs_halo.h:81
cs_halo_t::periodicity
const fvm_periodicity_t * periodicity
Definition: cs_halo.h:78
cs_rank_neighbors_t
Definition: cs_rank_neighbors.h:67
fvm_periodicity_t
struct _fvm_periodicity_t fvm_periodicity_t
Definition: fvm_periodicity.h:67
CS_HALO_ROTATION_IGNORE
Definition: cs_halo.h:64
cs_halo_update_buffers
void cs_halo_update_buffers(const cs_halo_t *halo)
Definition: cs_halo.c:820
CS_HALO_STANDARD
Definition: cs_halo.h:52
cs_halo_t::index
cs_lnum_t * index
Definition: cs_halo.h:112
cs_halo_t::n_transforms
int n_transforms
Definition: cs_halo.h:74
cs_halo_sync_var_strided
void cs_halo_sync_var_strided(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[], int stride)
Definition: cs_halo.c:1530
cs_halo_t::n_local_elts
cs_lnum_t n_local_elts
Definition: cs_halo.h:84
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_interface.h
cs_halo_t::send_list
cs_lnum_t * send_list
Definition: cs_halo.h:92
cs_halo_create_from_rank_neighbors
cs_halo_t * cs_halo_create_from_rank_neighbors(const cs_rank_neighbors_t *rn, cs_lnum_t n_local_elts, cs_lnum_t n_distant_elts, const int elt_rank_id[], const cs_lnum_t elt_id[])
Create a halo structure from distant element distant ranks and ids.
Definition: cs_halo.c:545
cs_halo_t
Definition: cs_halo.h:71
fvm_periodicity.h
cs_halo_type_t
cs_halo_type_t
Definition: cs_halo.h:50
cs_halo_free_buffer
void cs_halo_free_buffer(void)
Definition: cs_halo.c:900
cs_rank_neighbors.h
CS_HALO_N_TYPES
Definition: cs_halo.h:54
cs_halo_sync_components_strided
void cs_halo_sync_components_strided(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_halo_rotation_t rotation_op, cs_real_t var[], int stride)
Definition: cs_halo.c:1766
cs_halo_rotation_t
cs_halo_rotation_t
Definition: cs_halo.h:60
CS_HALO_EXTENDED
Definition: cs_halo.h:53
cs_halo_sync_untyped
void cs_halo_sync_untyped(const cs_halo_t *halo, cs_halo_type_t sync_mode, size_t size, void *val)
Definition: cs_halo.c:1089
cs_base.h
cs_halo_renumber_cells
void cs_halo_renumber_cells(cs_halo_t *halo, const cs_lnum_t new_cell_id[])
Definition: cs_halo.c:917
cs_halo_destroy
void cs_halo_destroy(cs_halo_t **halo)
Definition: cs_halo.c:760
cs_halo_sync_var
void cs_halo_sync_var(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[])
Definition: cs_halo.c:1399