9.2
general documentation
cs_partition.h
Go to the documentation of this file.
1#ifndef CS_PARTITION_H
2#define CS_PARTITION_H
3
4/*============================================================================
5 * Define cs_mesh_t fields from cs_mesh_builder_t fields.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 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 "base/cs_defs.h"
35
36#include "base/cs_base.h"
37#include "base/cs_log.h"
38
39#include "mesh/cs_mesh.h"
41
42/*=============================================================================
43 * Macro definitions
44 *============================================================================*/
45
46/*============================================================================
47 * Type definitions
48 *============================================================================*/
49
50/* Partitioning stage
51 *
52 * Partitioning is always done just after reading the mesh, unless a
53 * partitioning input file is available, in which case the partitioning
54 * read replaces this stage.
55 *
56 * When a mesh modification implying a change of cell connectivity graph
57 * is expected, the mesh may be re-partitioned after the pre-processing
58 * stage, prior to calculation. By default, re-partitioning is only done
59 * if the partitioning algorithm chosen for that stage is expected to
60 * produce different results due to the connectivity change. This is
61 * the case for graph-based algorithms such as those of METIS or SCOTCH,
62 * when mesh joining is defined, or additional periodic matching is defined
63 * (and the algorithm is not configured to ignore periodicity information).
64 *
65 * There are thus two possible partitioning stages:
66 *
67 * - CS_PARTITION_FOR_PREPROCESS, which is optional, and occurs
68 * just after reading the mesh.
69 * - CS_PARTITION_MAIN, which occurs just after reading the mesh if
70 * it is the only stage,, or after mesh preprocessing (and before
71 * computation), if the partitioning for preprocessing stage is
72 * activated.
73 *
74 * The number of partitioning stages is determined automatically based on
75 * information provided through cs_partition_set_preprocess_hints(),
76 * but re-partitioning may also be forced or inhibited using the
77 * cs_partition_set_preprocess() function.
78 */
79
80typedef enum {
81
82 CS_PARTITION_FOR_PREPROCESS, /* Partitioning for preprocessing stage */
83 CS_PARTITION_MAIN, /* Partitioning for computation stage */
84 CS_PARTITION_P2P, /* Part-to-part partitioning */
85
87
89
90
91/* Partitioning algorithm type
92 *
93 * If the default algorithm is selected, the choice will be based on the
94 * following priority, depending on available libraries:
95 * - Pt-Scotch (or Scotch if partitioning on one rank);
96 * - ParMETIS (or METIS if partitioning on one rank);
97 * - Morton space-filling curve (in bounding box)
98 *
99 * If both partitioning stages are active, the default for the preprocessing
100 * stage will be based on the Morton space-filling curve (in bounding box),
101 * as this should be cheaper, and the initial cell connectivity graph
102 * is usually expected to be modified during preprocessing.
103 */
104
105typedef enum {
106
107 CS_PARTITION_DEFAULT, /* Default partitioning (based on stage) */
108 CS_PARTITION_SFC_MORTON_BOX, /* Morton (Z) curve in bounding box */
109 CS_PARTITION_SFC_MORTON_CUBE, /* Morton (Z) curve in bounding cube */
110 CS_PARTITION_SFC_HILBERT_BOX, /* Peano-Hilbert curve in bounding box */
111 CS_PARTITION_SFC_HILBERT_CUBE, /* Peano-Hilbert curve in bounding cube */
112 CS_PARTITION_SCOTCH, /* PT-SCOTCH or SCOTCH */
113 CS_PARTITION_METIS, /* ParMETIS or METIS */
114 CS_PARTITION_BLOCK /* Unoptimized (naive) block partitioning */
115
117
118/*============================================================================
119 * Static global variables
120 *============================================================================*/
121
122/*=============================================================================
123 * Public function prototypes
124 *============================================================================*/
125
126/*----------------------------------------------------------------------------
127 * Print information on external libraries
128 *
129 * parameters:
130 * log_type <-- log type
131 *----------------------------------------------------------------------------*/
132
133void
135
136/*----------------------------------------------------------------------------
137 * Set algorithm for domain partitioning for a given partitioning stage.
138 *
139 * parameters:
140 * stage <-- associated partitioning stage
141 * algorithm <-- partitioning algorithm choice
142 * rank_step <-- if > 1, partitioning done on at most
143 * n_ranks / rank_step processes
144 * (for graph-based partitioning only)
145 * ignore_perio <-- if true, ignore periodicity information when present
146 * when present (for graph-based
147 * (for graph-based partitioning only)
148 *----------------------------------------------------------------------------*/
149
150void
152 cs_partition_algorithm_t algorithm,
153 int rank_step,
154 bool ignore_perio);
155
156/*----------------------------------------------------------------------------
157 * Set partitioning write to file option.
158 *
159 * Partitioning information for subsequent calculations is written to file
160 * after the last partitioning stage depending on the output level.
161 *
162 * Note that partitioning information for additional partitionings is
163 * always written to file, regardless of this option.
164 *
165 * parameters:
166 * write_flag <-- option to save partitioning information:
167 * 0: never
168 * 1: for graph-based partitioning only (default)
169 * 2: always
170 *----------------------------------------------------------------------------*/
171
172void
173cs_partition_set_write_level(int write_flag);
174
175/*----------------------------------------------------------------------------
176 * Define hints indicating if initial partitioning fo a preprocessing
177 * stage is required.
178 *
179 * parameters:
180 * join <-- true if a mesh joining operation is planned
181 * join_periodic <-- true if a mesh periodic matching operation is planned
182 *----------------------------------------------------------------------------*/
183
184void
186 bool join_periodic);
187
188/*----------------------------------------------------------------------------
189 * Activate or deactivate initial partitioning for preprocessing.
190 *
191 * parameters:
192 * active <-- true to activate pre-partitiong for the preprocessing
193 * stage, false to de-activate it
194 *----------------------------------------------------------------------------*/
195
196void
197cs_partition_set_preprocess(bool active);
198
199/*----------------------------------------------------------------------------
200 * Indicate if initial partitioning for preprocessing is required.
201 *
202 * returns:
203 * true if initial partitioning for preprocessing is active,
204 * false otherwise
205 *----------------------------------------------------------------------------*/
206
207bool
209
210/*----------------------------------------------------------------------------
211 * Define list of extra partitionings to build.
212 *
213 * Partitionings in this list will be output to file, and may be used for
214 * subsequent calculations.
215 *
216 * When partitioning for both preprocessing and calculation stages, output to
217 * file of partioning data or generation of additional partitionings
218 * (see \ref cs_partition_add_partitions) will only be done for the
219 * second stage.
220 *
221 * parameters:
222 * n_extra_partitions <-- number of extra partitionings to compute
223 * extra_partitions_list <-- list of extra partitions to compute
224 *----------------------------------------------------------------------------*/
225
226void
227cs_partition_add_partitions(int n_extra_partitions,
228 int extra_partitions_list[]);
229
230/*----------------------------------------------------------------------------*/
231/*
232 * \brief Partition mesh based on current options.
233 *
234 * If a mesh builder structure mb is provided, the computed partitioning
235 * is stored in mb->cell_rank.
236 * Else, the computed partitioning is copied to cell_dest, which must be
237 * preallocated.
238 *
239 * \param[in] mesh pointer to mesh structure
240 * \param[in, out] mb pointer to mesh builder structure
241 * \param[in] stage associated partitioning stage
242 * \param[out] cell_dest pointer to partitioning array
243 */
244/*----------------------------------------------------------------------------*/
245
246void
250 int cell_dest[]);
251
252/*----------------------------------------------------------------------------*/
253
254#endif /* CS_PARTITION_H */
cs_log_t
Definition: cs_log.h:44
void cs_partition_set_write_level(int write_flag)
Set partitioning write to file option.
Definition: cs_partition.cpp:3148
void cs_partition_set_preprocess_hints(bool join, bool join_periodic)
Define hints indicating if initial partitioning fo a preprocessing stage is required.
Definition: cs_partition.cpp:3165
bool cs_partition_get_preprocess(void)
Indicate if re-partitiong for the computation stage is required.
Definition: cs_partition.cpp:3200
cs_partition_algorithm_t
Definition: cs_partition.h:105
@ CS_PARTITION_METIS
Definition: cs_partition.h:113
@ CS_PARTITION_SFC_HILBERT_CUBE
Definition: cs_partition.h:111
@ CS_PARTITION_SFC_MORTON_CUBE
Definition: cs_partition.h:109
@ CS_PARTITION_BLOCK
Definition: cs_partition.h:114
@ CS_PARTITION_SFC_MORTON_BOX
Definition: cs_partition.h:108
@ CS_PARTITION_DEFAULT
Definition: cs_partition.h:107
@ CS_PARTITION_SCOTCH
Definition: cs_partition.h:112
@ CS_PARTITION_SFC_HILBERT_BOX
Definition: cs_partition.h:110
void cs_partition_external_library_info(cs_log_t log_type)
Print information on external libraries.
Definition: cs_partition.cpp:3002
void cs_partition_add_partitions(int n_extra_partitions, int extra_partitions_list[])
Define list of extra partitionings to build.
Definition: cs_partition.cpp:3245
void cs_partition_set_preprocess(bool active)
Activate or deactivate initial partitioning for preprocessing.
Definition: cs_partition.cpp:3182
void cs_partition_set_algorithm(cs_partition_stage_t stage, cs_partition_algorithm_t algorithm, int rank_step, bool ignore_perio)
Set algorithm for domain partitioning.
Definition: cs_partition.cpp:3065
void cs_partition(cs_mesh_t *mesh, cs_mesh_builder_t *mb, cs_partition_stage_t stage, int cell_dest[])
Partition mesh based on current options.
Definition: cs_partition.cpp:3275
cs_partition_stage_t
Definition: cs_partition.h:80
@ CS_PARTITION_FOR_PREPROCESS
Definition: cs_partition.h:82
@ CS_PARTITION_P2P
Definition: cs_partition.h:84
@ CS_PARTITION_MAIN
Definition: cs_partition.h:83
@ CS_PARTITION_STAGE_COUNT
Definition: cs_partition.h:86
Definition: mesh.f90:26
Definition: cs_mesh_builder.h:57
Definition: cs_mesh.h:85