Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MeshPartitionerBase.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MeshPartitionerBase.h (C) 2000-2025 */
9/* */
10/* Base class for a mesh partitioner. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_STD_MESHPARTITIONERBASE_H
13#define ARCANE_STD_MESHPARTITIONERBASE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18#include "arcane/utils/HashTableMap.h"
19#include "arcane/utils/ScopedPtr.h"
20
21#include "arcane/core/IMeshPartitioner.h"
22#include "arcane/core/AbstractService.h"
23#include "arcane/core/ILoadBalanceMng.h"
24
25#include <set>
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
40class ARCANE_STD_EXPORT MeshPartitionerBase
41: public AbstractService
42, public IMeshPartitioner
43{
44 public:
45
46 explicit MeshPartitionerBase(const ServiceBuildInfo& sbi);
47 ~MeshPartitionerBase() override;
48
49 public:
50
51 ISubDomain* subDomain() const { return m_sub_domain; }
52 IMesh* mesh() const override { return m_mesh; }
53
54 // DEPRECATED
55 void setMaximumComputationTime(Real v) override { m_maximum_computation_time = v; }
56 Real maximumComputationTime() const override { return m_maximum_computation_time; }
57
58 void setImbalance(Real v) override { m_imbalance = v; }
59 Real imbalance() const override { return m_imbalance; }
60
61 void setMaxImbalance(Real v) override { m_max_imbalance = v; }
62 Real maxImbalance() const override { return m_max_imbalance; }
63
64 void setComputationTimes(RealConstArrayView v) override { m_computation_times.copy(v); }
65 RealConstArrayView computationTimes() const override { return m_computation_times; }
66
67 void setCellsWeight(ArrayView<float> weights, Integer nb_weight) override;
68 ArrayView<float> cellsWeight() const override;
69
70 // CORRECT
71 Integer nbCellWeight() const;
72 void setILoadBalanceMng(ILoadBalanceMng* mng) override { m_lbMng = mng; }
73 ILoadBalanceMng* loadBalanceMng() const override { return m_lbMng; }
74
75 public:
76
77 void notifyEndPartition() override { loadBalanceMng()->notifyEndPartition(); }
78
79 public:
80
88 virtual void changeOwnersFromCells();
89
90 enum eMarkCellWithConstraint
91 {
92 eCellClassical,
93 eCellReference,
94 eCellGrouped,
95 eCellGhost,
96 eCellInAConstraint
97 };
98
99 /* \brief Initializes structures for the case with partitioning constraints */
100 virtual void initConstraints(bool uidref = true);
101
102 /* \brief Frees temporary arrays */
103 virtual void freeConstraints();
104
105 /* \brief Returns the number of Cells after grouping according to constraints, internal */
106 virtual Int32 nbOwnCellsWithConstraints() const;
107
108 /* \brief Provides the list of unique IDs of neighboring Cells of a cell, taking constraints into account */
109 virtual Real getNeighbourCellsUidWithConstraints(Cell cell, Int64Array& neighbourcells, Array<float>* commWeights = NULL,
110 bool noCellContrib = false);
111
112 virtual Integer nbNeighbourCellsWithConstraints(Cell cell);
113
114 /* \brief Provides the list of unique IDs of neighboring Nodes, useful for the HG model */
115 virtual void getNeighbourNodesUidWithConstraints(Cell cell, Int64UniqueArray neighbournodes);
116
117 /* \brief Returns the local ID for a Cell, taking constraints into account and compacting
118 * the numbering. Returns -1 for cells not to be used */
119 virtual Int32 localIdWithConstraints(Cell cell);
120 virtual Int32 localIdWithConstraints(Int32 cell_lid);
121
122 /* \brief Inverts the functionality of localIdWithConstraints */
123 virtual void invertArrayLid2LidCompacted();
124
125 /* \brief Returns the weight(s) associated with the Cells, taking constraints into
126 * account. max_nb_weight is 0 if there are no limits */
127 virtual SharedArray<float> cellsWeightsWithConstraints(Int32 max_nb_weight = 0, bool ask_lb_cells = false);
128
129 virtual SharedArray<float> cellsSizeWithConstraints();
130
131 /* \brief Returns true if the cell is used despite the constraints. If false, it is
132 * necessary to pass it during an ENUMERATE_CELL */
133 virtual bool cellUsedWithConstraints(Cell cell);
134
135 virtual bool cellUsedWithWeakConstraints(std::pair<Int64, Int64>& paired_item);
136
137 /* \brief Assigns the new process number to the cell and others in the same
138 * group/constraint if applicable */
139 virtual void changeCellOwner(Item cell, VariableItemInt32& cells_new_owner, Int32 new_owner);
140
141 /* \brief Returns true if there are constraints in the mesh. Requires calling
142 * initArrayCellsWithConstraints */
143 virtual bool haveConstraints() { return m_cells_with_constraints.size() > 0; }
144
145 virtual bool haveWeakConstraints() { return m_cells_with_weak_constraints.size() > 0; }
146
147 protected:
148
150 virtual void dumpObject(String filename = "toto");
151
152 virtual void* getCommunicator() const;
153 virtual Parallel::Communicator communicator() const;
154 virtual bool cellComm() { return true; }
155
156 protected:
157
158 virtual void _initArrayCellsWithConstraints();
159 virtual void _initFilterLidCells();
160 virtual void _initUidRef();
161 virtual void _initUidRef(VariableCellInteger& cell_renum_uid);
162 virtual void _initLid2LidCompacted();
163 virtual void _initNbCellsWithConstraints();
164 virtual void _clearCellWgt();
165
166 protected:
167
168 bool _isNonManifoldMesh() const { return m_is_non_manifold_mesh; }
169 Int32 _meshDimension() const { return m_mesh_dimension; }
170
171 private:
172
173 Real _addNgb(const Cell& cell, const Face& face, Int64Array& neighbourcells, Array<bool>& contrib,
174 HashTableMapT<Int64, Int32>& map, Array<float>* ptrcommWeights, Int32 offset,
175 HashTableMapT<Int32, Int32>& lids, bool special = false);
176 bool _createConstraintsLists(Int64MultiArray2& tied_uid);
177
178 SharedArray<float> _cellsProjectWeights(VariableCellArrayReal& cellWgtIn, Int32 nbWgt) const;
179 SharedArray<float> _cellsProjectWeights(VariableCellReal& cellWgtIn) const;
180
181 private:
182
183 ISubDomain* m_sub_domain = nullptr;
184 IMesh* m_mesh = nullptr;
185 IParallelMng* m_pm_sub = nullptr; // sub communicator for partitioning libraries.
186
187 protected:
188
189 IItemFamily* m_cell_family = nullptr;
190
191 private:
192
193 ILoadBalanceMng* m_lbMng = nullptr;
194 ILoadBalanceMngInternal* m_lb_mng_internal = nullptr;
195
196 Real m_maximum_computation_time = 0.0;
197 Real m_imbalance = 0.0;
198 Real m_max_imbalance = 0.0;
199 UniqueArray<Real> m_computation_times;
200
201 // Used internally to build the graph/hypergraph
202 UniqueArray<SharedArray<Cell>> m_cells_with_constraints;
203 std::set<std::pair<Int64, Int64>> m_cells_with_weak_constraints;
204 Integer m_nb_cells_with_constraints = 0;
205 UniqueArray<eMarkCellWithConstraint> m_filter_lid_cells;
206 UniqueArray<Int32> m_local_id_2_local_id_compacted;
207 VariableCellInt64* m_unique_id_reference = nullptr;
208
209 void _checkCreateVar();
210 UniqueArray<Int32> m_check;
211 bool m_is_non_manifold_mesh = false;
212 Int32 m_mesh_dimension = -1;
213};
214
215/*---------------------------------------------------------------------------*/
216/*---------------------------------------------------------------------------*/
217
218} // namespace Arcane
219
220/*---------------------------------------------------------------------------*/
221/*---------------------------------------------------------------------------*/
222
223#endif
AbstractService(const ServiceBuildInfo &)
Constructor from a ServiceBuildInfo.
Interface for registering variables for load balancing.
Interface of a mesh partitioner.
Interface of the subdomain manager.
Definition ISubDomain.h:75
void setMaxImbalance(Real v) override
Sets the maximum allowed imbalance.
void setComputationTimes(RealConstArrayView v) override
Computation time of this subdomain. The first element indicates the computation time of the subdomain...
IMesh * mesh() const override
Mesh associated with the partitioner.
void setILoadBalanceMng(ILoadBalanceMng *mng) override
Changes the ILoadBalanceMng to use.
Real imbalance() const override
Computation time imbalance.
Real maxImbalance() const override
Maximum allowed imbalance.
void setMaximumComputationTime(Real v) override
Sets the proportion of computation time.
void setImbalance(Real v) override
Sets the computation time imbalance.
void notifyEndPartition() override
Notification when a re-partitioning finishes (after entity exchange).
Structure containing the information to create a service.
MeshVariableScalarRefT< Cell, Int64 > VariableCellInt64
Quantity at the cell center of 64-bit integer type.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.
Definition UtilsTypes.h:488