Code_Saturne
CFD tool
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-2012 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 
37 #include "fvm_periodicity.h"
38 
39 /*----------------------------------------------------------------------------*/
40 
42 
43 /*=============================================================================
44  * Local Type definitions
45  *============================================================================*/
46 
47 /* Halo type */
48 
49 typedef enum {
50 
54 
56 
57 /* Options for cs_halo_sync_component(). */
58 
59 typedef enum {
60 
61  CS_HALO_ROTATION_COPY, /* Copy halo */
62  CS_HALO_ROTATION_ZERO, /* Set rotation halo values to zero */
63  CS_HALO_ROTATION_IGNORE /* Do not modify rotation halo values */
64 
66 
67 
68 /*============================================================================
69  * Type definition
70  *============================================================================*/
71 
72 /* Structure for halo management */
73 /* ----------------------------- */
74 
75 typedef struct {
76 
77  int n_c_domains; /* Number of communicating domains. */
78  int n_transforms; /* Number of periodic transformations */
79 
80  int *c_domain_rank; /* List of communicating ranks */
81 
82  const fvm_periodicity_t * periodicity; /* Pointer to periodicity
83  structure describing transforms */
84 
85  int n_rotations; /* Number of periodic transformations
86  involving rotations */
87 
88  cs_int_t n_local_elts; /* Number of local elements */
89 
90  /* send_halo features : send to distant ranks */
91 
92  cs_int_t n_send_elts[2]; /* Numer of ghost elements in send_list
93  n_elts[0] = standard elements
94  n_elts[1] = extended + standard elements */
95 
96  cs_int_t *send_list; /* List of local elements in distant halos
97  (0 to n-1 numbering) */
98 
99  cs_int_t *send_index; /* Index on send_list
100  Size = 2*n_c_domains + 1. For each rank, we
101  have an index for standard halo and one
102  for extended halo. */
103 
104  cs_int_t *send_perio_lst ; /* For each transformation and for each type of
105  halo on each communicating rank, we store
106  2 values:
107  - start index,
108  - number of elements. */
109 
110  /* halo features : receive from distant ranks */
111 
112  cs_int_t n_elts[2]; /* Numer of ghost elements in halo
113  n_elts[0] = standard elements
114  n_elts[1] = extended + standard elements */
115 
116  cs_int_t *index; /* Index on halo sections;
117  Size = 2*n_c_domains. For each rank, we
118  have an index for the standard halo and one
119  for the extended halo. */
120 
121  cs_int_t *perio_lst; /* For each transformation and for each type of halo
122  on each communicating rank, we store 2 values:
123  - start index,
124  - number of elements. */
125 
126  /* Organisation of perio_lst:
127 
128  -------------------------------------------------
129  T1: | | | | | | | | | | | | |
130  -------------------------------------------------
131  idx n idx n idx n idx n idx n idx n
132  ______ ______ ______ ______ ______ ______
133  std ext std ext std ext
134  ___________ ___________ ___________
135  rank 0 rank 1 rank 2
136 
137  -------------------------------------------------
138  T2: | | | | | | | | | | | | |
139  -------------------------------------------------
140  idx n idx n idx n idx n idx n idx n
141  ______ ______ ______ ______ ______ ______
142  std ext std ext std ext
143  ___________ ___________ ___________
144  rank 0 rank 1 rank 2
145 
146  -------------------------------------------------
147  T3: | | | | | | | | | | | | |
148  -------------------------------------------------
149  idx n idx n idx n idx n idx n idx n
150  ______ ______ ______ ______ ______ ______
151  std ext std ext std ext
152  ___________ ___________ ___________
153  rank 0 rank 1 rank 2
154 
155  etc...
156 
157  */
158 
159 } cs_halo_t;
160 
161 /*=============================================================================
162  * Global static variables
163  *============================================================================*/
164 
165 /*============================================================================
166  * Public function header for Fortran API
167  *============================================================================*/
168 
169 /*=============================================================================
170  * Public function prototypes
171  *============================================================================*/
172 
173 /*----------------------------------------------------------------------------
174  * Create a halo structure.
175  *
176  * parameters:
177  * ifs <-- pointer to a fvm_interface_set structure
178  *
179  * returns:
180  * pointer to created cs_halo_t structure
181  *---------------------------------------------------------------------------*/
182 
183 cs_halo_t *
185 
186 /*----------------------------------------------------------------------------
187  * Create a halo structure, using a reference halo
188  *
189  * parameters:
190  * ref <-- pointer to reference halo
191  *
192  * returns:
193  * pointer to created cs_halo_t structure
194  *---------------------------------------------------------------------------*/
195 
196 cs_halo_t *
198 
199 /*----------------------------------------------------------------------------
200  * Destroy a halo structure.
201  *
202  * parameters:
203  * this_halo <-- pointer to cs_halo structure to destroy
204  *
205  * returns:
206  * pointer to deleted halo structure (NULL)
207  *---------------------------------------------------------------------------*/
208 
209 cs_halo_t *
210 cs_halo_destroy(cs_halo_t *this_halo);
211 
212 /*----------------------------------------------------------------------------
213  * Update global buffer sizes so as to be usable with a given halo.
214  *
215  * Calls to halo synchronizations with variable strides up to 3 are
216  * expected. For strides greater than 3, the halo will be resized if
217  * necessary directly by the synchronization function.
218  *
219  * This function should be called at the end of any halo creation,
220  * so that buffer sizes are increased if necessary.
221  *
222  * parameters:
223  * halo <-- pointer to cs_halo_t structure.
224  *---------------------------------------------------------------------------*/
225 
226 void
227 cs_halo_update_buffers(const cs_halo_t *halo);
228 
229 /*----------------------------------------------------------------------------
230  * Free global halo backup buffer.
231  *---------------------------------------------------------------------------*/
232 
233 void
234 cs_halo_free_buffer(void);
235 
236 /*----------------------------------------------------------------------------
237  * Apply cell renumbering to a halo
238  *
239  * parameters:
240  * halo <-- pointer to halo structure
241  * new_cell_id <-- array indicating old -> new cell id (0 to n-1)
242  *---------------------------------------------------------------------------*/
243 
244 void
246  const cs_int_t new_cell_id[]);
247 
248 /*----------------------------------------------------------------------------
249  * Update array of any type of halo values in case of parallelism or
250  * periodicity.
251  *
252  * Data is untyped; only its size is given, so this function may also
253  * be used to synchronize interleaved multidimendsional data, using
254  * size = element_size*dim (assuming a homogeneous environment, at least
255  * as far as data encoding goes).
256  *
257  * This function aims at copying main values from local elements
258  * (id between 1 and n_local_elements) to ghost elements on distant ranks
259  * (id between n_local_elements + 1 to n_local_elements_with_halo).
260  *
261  * parameters:
262  * halo <-- pointer to halo structure
263  * sync_mode <-- synchronization mode (standard or extended)
264  * num <-> pointer to local number value array
265  *----------------------------------------------------------------------------*/
266 
267 void
268 cs_halo_sync_untyped(const cs_halo_t *halo,
269  cs_halo_type_t sync_mode,
270  size_t size,
271  void *val);
272 
273 /*----------------------------------------------------------------------------
274  * Update array of integer halo values in case of parallelism or periodicity.
275  *
276  * This function aims at copying main values from local elements
277  * (id between 1 and n_local_elements) to ghost elements on distant ranks
278  * (id between n_local_elements + 1 to n_local_elements_with_halo).
279  *
280  * parameters:
281  * halo <-- pointer to halo structure
282  * sync_mode <-- synchronization mode (standard or extended)
283  * num <-> pointer to local number value array
284  *----------------------------------------------------------------------------*/
285 
286 void
287 cs_halo_sync_num(const cs_halo_t *halo,
288  cs_halo_type_t sync_mode,
289  cs_int_t num[]);
290 
291 /*----------------------------------------------------------------------------
292  * Update array of variable (floating-point) halo values in case of
293  * parallelism or periodicity.
294  *
295  * This function aims at copying main values from local elements
296  * (id between 1 and n_local_elements) to ghost elements on distant ranks
297  * (id between n_local_elements + 1 to n_local_elements_with_halo).
298  *
299  * parameters:
300  * halo <-- pointer to halo structure
301  * sync_mode <-- synchronization mode (standard or extended)
302  * var <-> pointer to variable value array
303  *----------------------------------------------------------------------------*/
304 
305 void
306 cs_halo_sync_var(const cs_halo_t *halo,
307  cs_halo_type_t sync_mode,
308  cs_real_t var[]);
309 
310 /*----------------------------------------------------------------------------
311  * Update array of strided variable (floating-point) halo values in case
312  * of parallelism or periodicity.
313  *
314  * This function aims at copying main values from local elements
315  * (id between 1 and n_local_elements) to ghost elements on distant ranks
316  * (id between n_local_elements + 1 to n_local_elements_with_halo).
317  *
318  * parameters:
319  * halo <-- pointer to halo structure
320  * sync_mode <-- synchronization mode (standard or extended)
321  * var <-> pointer to variable value array
322  * stride <-- number of (interlaced) values by entity
323  *----------------------------------------------------------------------------*/
324 
325 void
327  cs_halo_type_t sync_mode,
328  cs_real_t var[],
329  int stride);
330 
331 /*----------------------------------------------------------------------------
332  * Update array of vector variable component (floating-point) halo values
333  * in case of parallelism or periodicity.
334  *
335  * This function aims at copying main values from local elements
336  * (id between 1 and n_local_elements) to ghost elements on distant ranks
337  * (id between n_local_elements + 1 to n_local_elements_with_halo).
338  *
339  * If rotation_op is equal to CS_HALO_ROTATION_IGNORE, halo values
340  * corresponding to periodicity with rotation are left unchanged from their
341  * previous values.
342  *
343  * If rotation_op is equal to CS_HALO_ROTATION_ZERO, halo values
344  * corresponding to periodicity with rotation are set to 0.
345  *
346  * If rotation_op is equal to CS_HALO_ROTATION_COPY, halo values
347  * corresponding to periodicity with rotation are exchanged normally, so
348  * the behavior is the same as that of cs_halo_sync_var().
349  *
350  * parameters:
351  * halo <-- pointer to halo structure
352  * sync_mode <-- synchronization mode (standard or extended)
353  * rotation_op <-- rotation operation
354  * var <-> pointer to variable value array
355  *----------------------------------------------------------------------------*/
356 
357 void
359  cs_halo_type_t sync_mode,
360  cs_halo_rotation_t rotation_op,
361  cs_real_t var[]);
362 
363 /*----------------------------------------------------------------------------
364  * Update array of strided vector variable components (floating-point)
365  * halo values in case of parallelism or periodicity.
366  *
367  * This function aims at copying main values from local elements
368  * (id between 1 and n_local_elements) to ghost elements on distant ranks
369  * (id between n_local_elements + 1 to n_local_elements_with_halo).
370  *
371  * If rotation_op is equal to CS_HALO_ROTATION_IGNORE, halo values
372  * corresponding to periodicity with rotation are left unchanged from their
373  * previous values.
374  *
375  * If rotation_op is equal to CS_HALO_ROTATION_ZERO, halo values
376  * corresponding to periodicity with rotation are set to 0.
377  *
378  * If rotation_op is equal to CS_HALO_ROTATION_COPY, halo values
379  * corresponding to periodicity with rotation are exchanged normally, so
380  * the behavior is the same as that of cs_halo_sync_var_strided().
381  *
382  * parameters:
383  * halo <-- pointer to halo structure
384  * sync_mode <-- synchronization mode (standard or extended)
385  * rotation_op <-- rotation operation
386  * var <-> pointer to variable value array
387  * stride <-- number of (interlaced) values by entity
388  *----------------------------------------------------------------------------*/
389 
390 void
392  cs_halo_type_t sync_mode,
393  cs_halo_rotation_t rotation_op,
394  cs_real_t var[],
395  int stride);
396 
397 /*----------------------------------------------------------------------------
398  * Set MPI_Barrier usage flag.
399  *
400  * parameters:
401  * use_barrier <-- if 1, use MPI barriers after posting receives and
402  * before posting sends. if 0, do not use barriers;
403  *---------------------------------------------------------------------------*/
404 
405 void
406 cs_halo_set_use_barrier(int use_barrier);
407 
408 /*----------------------------------------------------------------------------
409  * Dump a cs_halo_t structure.
410  *
411  * parameters:
412  * halo <-- pointer to cs_halo_t struture
413  * print_level <-- 0 only dimensions and indexes are printed, else (1)
414  * everything is printed
415  *---------------------------------------------------------------------------*/
416 
417 void
418 cs_halo_dump(const cs_halo_t *halo,
419  cs_int_t print_level);
420 
421 /*----------------------------------------------------------------------------*/
422 
424 
425 #endif /* __CS_HALO_H__ */
Definition: fvm_periodicity.c:123
void cs_halo_free_buffer(void)
Definition: cs_halo.c:664
cs_halo_rotation_t
Definition: cs_halo.h:59
cs_int_t * perio_lst
Definition: cs_halo.h:121
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:1346
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
void cs_halo_sync_var(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[])
Definition: cs_halo.c:1017
Definition: cs_halo.h:52
Definition: cs_halo.h:75
cs_int_t * send_list
Definition: cs_halo.h:96
cs_halo_t * cs_halo_create_from_ref(const cs_halo_t *ref)
Definition: cs_halo.c:462
int cs_int_t
Definition: cs_defs.h:263
int * c_domain_rank
Definition: cs_halo.h:80
void cs_halo_set_use_barrier(int use_barrier)
Definition: cs_halo.c:1423
void cs_halo_update_buffers(const cs_halo_t *halo)
Definition: cs_halo.c:585
cs_int_t * send_perio_lst
Definition: cs_halo.h:104
void cs_halo_renumber_cells(cs_halo_t *halo, const cs_int_t new_cell_id[])
Definition: cs_halo.c:681
Definition: cs_halo.h:62
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:1148
Definition: cs_halo.h:61
int n_transforms
Definition: cs_halo.h:78
int n_rotations
Definition: cs_halo.h:85
cs_halo_type_t
Definition: cs_halo.h:49
cs_int_t * send_index
Definition: cs_halo.h:99
cs_halo_t * cs_halo_create(cs_interface_set_t *ifs)
Definition: cs_halo.c:328
void cs_halo_dump(const cs_halo_t *halo, cs_int_t print_level)
Definition: cs_halo.c:1438
int n_c_domains
Definition: cs_halo.h:77
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:1393
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:715
Definition: cs_halo.h:51
const fvm_periodicity_t * periodicity
Definition: cs_halo.h:82
cs_int_t n_local_elts
Definition: cs_halo.h:88
#define END_C_DECLS
Definition: cs_defs.h:366
double cs_real_t
Definition: cs_defs.h:264
void cs_halo_sync_num(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_int_t num[])
Definition: cs_halo.c:881
Definition: cs_interface.c:106
cs_halo_t * cs_halo_destroy(cs_halo_t *this_halo)
Definition: cs_halo.c:526
Definition: cs_halo.h:63
cs_int_t * index
Definition: cs_halo.h:116
Definition: cs_halo.h:53