My Project
programmer's documentation
cs_block_to_part.h
Go to the documentation of this file.
1 #ifndef __CS_BLOCK_TO_PART_H__
2 #define __CS_BLOCK_TO_PART_H__
3 
4 /*============================================================================
5  * Convert between block distribution and general domain partition.
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 #if defined(HAVE_MPI)
31 #include <mpi.h>
32 #endif
33 
34 /*----------------------------------------------------------------------------
35  * Local headers
36  *----------------------------------------------------------------------------*/
37 
38 #include "cs_defs.h"
39 #include "cs_block_dist.h"
40 
41 /*----------------------------------------------------------------------------*/
42 
44 
45 /*=============================================================================
46  * Macro definitions
47  *============================================================================*/
48 
49 /*============================================================================
50  * Type definitions
51  *============================================================================*/
52 
53 /* Opaque block to general domain partitioning distribution structure */
54 
55 #if defined(HAVE_MPI)
56 
57 typedef struct _cs_block_to_part_t cs_block_to_part_t;
58 
59 #endif
60 
61 /*=============================================================================
62  * Public function prototypes
63  *============================================================================*/
64 
65 #if defined(HAVE_MPI)
66 
67 /*----------------------------------------------------------------------------
68  * Create block to partition distributor using entity destination rank array.
69  *
70  * arguments:
71  * comm <-- communicator
72  * block <-- block to partition range and size info
73  * ent_rank <-- destination rank for each entity
74  * (size: block.gnum_range[1] - block.gnum_range[0])
75  *
76  * returns:
77  * initialized block to partition distributor
78  *----------------------------------------------------------------------------*/
79 
83  int ent_rank[]);
84 
85 /*----------------------------------------------------------------------------
86  * Initialize block to partition distributor with block data using
87  * strided adjacency array.
88  *
89  * The adjacency array uses 1-n based global numbers. 0 values are
90  * allowed and may be used to represent empty adjacencies.
91  *
92  * For example, in a face -> element adjacency relation, each face
93  * is adjacent to 2 elements (thus a stride of 2), except for
94  * boundary faces which are adjacent to only 1 element; in this case,
95  * the adjacent element number for the exterior side of the face is 0.
96  *
97  * It is also possible to define a default destination rank,
98  * so that elements with no adjacency are redistributed.
99  * If the default rank for a given element is < 0, or no default
100  * ranks are defined, elements with no adjacency are not distributed.
101  *
102  * arguments:
103  * comm <-- communicator
104  * block <-- block size and range info
105  * adjacent_block <-- block info for adjacent entities
106  * stride <-- stride of adjacency array
107  * adjacency <-- entity adjacency (1 to n numbering)
108  * adjacent_ent_rank <-- destination rank for adjacent entities, or
109  * NULL if based on block size and range only.
110  * default_rank <-- default rank in case there is no adjacency, or NULL
111  *
112  * returns:
113  * initialized block to partition distributor
114  *----------------------------------------------------------------------------*/
115 
118  cs_block_dist_info_t block,
119  cs_block_dist_info_t adjacent_block,
120  int stride,
121  cs_gnum_t adjacency[],
122  int adjacent_ent_rank[],
123  int default_rank[]);
124 
125 /*----------------------------------------------------------------------------
126  * Initialize block to partition distributor for entities adjacent to
127  * already distributed entities.
128  *
129  * arguments:
130  * comm <-- communicator
131  * bi <-- block size and range info
132  * adj_bi <-- block info for adjacent entities
133  * adjacency <-- entity adjacency (1 to n numbering)
134  *
135  * returns:
136  * initialized block to partition distributor
137  *----------------------------------------------------------------------------*/
138 
140 cs_block_to_part_create_adj(MPI_Comm comm,
141  cs_block_dist_info_t adj_bi,
142  size_t adjacency_size,
143  const cs_gnum_t adjacency[]);
144 
145 /*----------------------------------------------------------------------------
146  * Initialize block to partition distributor based global element numbers
147  * for partitioned data.
148  *
149  * arguments:
150  * comm <-- communicator
151  * bi <-- block size and range info
152  * n_ents <-- number of elements in partition
153  * global_ent_num <-- global entity numbers (in partition)
154  *
155  * returns:
156  * initialized partition to block distributor
157  *----------------------------------------------------------------------------*/
158 
160 cs_block_to_part_create_by_gnum(MPI_Comm comm,
162  cs_lnum_t n_ents,
163  const cs_gnum_t global_ent_num[]);
164 
165 /*----------------------------------------------------------------------------
166  * Destroy a block to partition distributor structure.
167  *
168  * arguments:
169  * d <-> pointer to block to partition distributor structure pointer
170  *----------------------------------------------------------------------------*/
171 
172 void
174 
175 /*----------------------------------------------------------------------------
176  * Return number of entities associated with local partition
177  *
178  * arguments:
179  * d <-- distribtor helper
180  *
181  * returns:
182  * number of entities associated with distribution receive
183  *----------------------------------------------------------------------------*/
184 
185 cs_lnum_t
187 
188 /*----------------------------------------------------------------------------
189  * Transfer a block to partition distributor's associated global numbering.
190  *
191  * The pointer to the global number array is returned, and ownership
192  * of this array is given to the caller.
193  *
194  * arguments:
195  * d <-> pointer to block to partition distributor structure pointer
196  *
197  * returns:
198  * pointer to receiver global numbering, or NULL if the block to
199  * domain partition distributor was not the owner of this array.
200  *----------------------------------------------------------------------------*/
201 
202 cs_gnum_t *
204 
205 /*----------------------------------------------------------------------------
206  * Copy array data from block distribution to general domain partition.
207  *
208  * arguments:
209  * d <-- block to partition distributor
210  * datatype <-- type of data considered
211  * stride <-- number of values per entity (interlaced)
212  * block_values --> values in block distribution
213  * part_values --> values in general domain partition
214  *----------------------------------------------------------------------------*/
215 
216 void
218  cs_datatype_t datatype,
219  int stride,
220  const void *block_values,
221  void *part_values);
222 
223 /*----------------------------------------------------------------------------
224  * Copy a local index from block distribution to general domain partition.
225  *
226  * This is useful for distribution of entity connectivity information.
227  *
228  * arguments:
229  * d <-- block to partition distributor
230  * block_index <-- local index in block distribution
231  * part_index --> local index in general partition distribution
232  * (size: n_part_entities + 1)
233  *----------------------------------------------------------------------------*/
234 
235 void
237  const cs_lnum_t *block_index,
238  cs_lnum_t *part_index);
239 
240 /*----------------------------------------------------------------------------
241  * Copy indexed data from block distribution to general domain partition.
242  *
243  * arguments:
244  * d <-- block to partition distributor
245  * datatype <-- type of data considered
246  * block_index <-- local index in block distribution
247  * block_val <-- values in block distribution
248  * (size: block_index[n_block_ents])
249  * part_index --> local index in general distribution
250  * part_val --> numbers in general distribution
251  * (size: part_index[n_part_ents])
252  *----------------------------------------------------------------------------*/
253 
254 void
256  cs_datatype_t datatype,
257  const cs_lnum_t *block_index,
258  const void *block_val,
259  const cs_lnum_t *part_index,
260  void *part_val);
261 
262 #endif /* defined(HAVE_MPI) */
263 
264 /*----------------------------------------------------------------------------
265  * Determine local references from references to global numbers.
266  *
267  * This is based on finding the local id of a given global number
268  * using a binary search.
269  *
270  * Global numbers use a 1 to n numbering, while local numbers use a
271  * 0+base to n-1+base numbering. If an entity's global number does not
272  * appear in the global list, base-1 is assigned for that entity's
273  * local list.
274  *
275  * If list contains duplicate values, any local id having a multiple
276  * global number (i.e not necessarily the smallest one) may be
277  * assigned to the corresponding local_number[] entry.
278  *
279  * arguments:
280  * n_ents <-- number of entities
281  * base <-- base numbering (typically 0 or 1)
282  * global_list_size <-- size of global entity list
283  * global_list_is_sorted <-- true if global entity list is guaranteed
284  * to be sorted
285  * global_list <-- global entity list
286  * global_number <-- entity global numbers
287  * (size: n_ents)
288  * local_number --> entity local numbers
289  * (size: n_ents)
290  *----------------------------------------------------------------------------*/
291 
292 void
294  cs_lnum_t base,
295  cs_lnum_t global_list_size,
296  bool global_list_is_sorted,
297  const cs_gnum_t global_list[],
298  const cs_gnum_t global_number[],
299  cs_lnum_t local_number[]);
300 
301 /*----------------------------------------------------------------------------*/
302 
304 
305 #endif /* __CS_BLOCK_TO_PART_H__ */
cs_defs.h
cs_block_to_part_t
struct _cs_block_to_part_t cs_block_to_part_t
Definition: cs_block_to_part.h:57
cs_block_to_part_create_by_rank
cs_block_to_part_t * cs_block_to_part_create_by_rank(MPI_Comm comm, cs_block_dist_info_t block, int ent_rank[])
Definition: cs_block_to_part.c:338
cs_block_to_part_create_by_gnum
cs_block_to_part_t * cs_block_to_part_create_by_gnum(MPI_Comm comm, cs_block_dist_info_t bi, cs_lnum_t n_ents, const cs_gnum_t global_ent_num[])
Definition: cs_block_to_part.c:767
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
cs_block_to_part_get_n_part_ents
cs_lnum_t cs_block_to_part_get_n_part_ents(cs_block_to_part_t *d)
Definition: cs_block_to_part.c:895
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_block_to_part_transfer_gnum
cs_gnum_t * cs_block_to_part_transfer_gnum(cs_block_to_part_t *d)
Definition: cs_block_to_part.c:920
cs_block_to_part_copy_indexed
void cs_block_to_part_copy_indexed(cs_block_to_part_t *d, cs_datatype_t datatype, const cs_lnum_t *block_index, const void *block_val, const cs_lnum_t *part_index, void *part_val)
Definition: cs_block_to_part.c:1095
cs_block_to_part_create_by_adj_s
cs_block_to_part_t * cs_block_to_part_create_by_adj_s(MPI_Comm comm, cs_block_dist_info_t block, cs_block_dist_info_t adjacent_block, int stride, cs_gnum_t adjacency[], int adjacent_ent_rank[], int default_rank[])
Definition: cs_block_to_part.c:417
cs_block_to_part_copy_array
void cs_block_to_part_copy_array(cs_block_to_part_t *d, cs_datatype_t datatype, int stride, const void *block_values, void *part_values)
Definition: cs_block_to_part.c:941
cs_block_to_part_global_to_local
void cs_block_to_part_global_to_local(cs_lnum_t n_ents, cs_lnum_t base, cs_lnum_t global_list_size, bool global_list_is_sorted, const cs_gnum_t global_list[], const cs_gnum_t global_number[], cs_lnum_t local_number[])
Definition: cs_block_to_part.c:1264
cs_datatype_t
cs_datatype_t
Definition: cs_defs.h:260
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_block_dist_info_t
Definition: cs_block_dist.h:50
cs_gnum_t
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_block_to_part_copy_index
void cs_block_to_part_copy_index(cs_block_to_part_t *d, const cs_lnum_t *block_index, cs_lnum_t *part_index)
Definition: cs_block_to_part.c:1035
cs_block_to_part_destroy
void cs_block_to_part_destroy(cs_block_to_part_t **d)
Definition: cs_block_to_part.c:867
cs_block_to_part_create_adj
cs_block_to_part_t * cs_block_to_part_create_adj(MPI_Comm comm, cs_block_dist_info_t adj_bi, size_t adjacency_size, const cs_gnum_t adjacency[])
Definition: cs_block_to_part.c:635
cs_block_dist.h