12#ifndef ARCANE_IMPL_INTERNAL_LOADBALANCEMNGINTERNAL_H
13#define ARCANE_IMPL_INTERNAL_LOADBALANCEMNGINTERNAL_H
17#include "arcane/core/internal/ILoadBalanceMngInternal.h"
19#include "arcane/core/IMesh.h"
20#include "arcane/core/IVariable.h"
21#include "arcane/core/VariableBuildInfo.h"
23#include "arcane/core/IVariableMng.h"
24#include "arcane/core/VariableTypes.h"
25#include "arcane/core/CommonVariables.h"
26#include "arcane/core/VariableCollection.h"
27#include "arcane/core/IItemFamily.h"
28#include "arcane/core/IParallelMng.h"
30#include "arcane/utils/ObjectImpl.h"
31#include "arcane/utils/AutoRef.h"
32#include "arcane/utils/ScopedPtr.h"
33#include "arcane/utils/FatalErrorException.h"
34#include "arcane/utils/ArgumentException.h"
36#include <unordered_map>
79class ARCANE_IMPL_EXPORT StoreIProxyItemVariable
88 StoreIProxyItemVariable(
const StoreIProxyItemVariable& src)
107 Integer getPos()
const
109 return m_var->getPos();
115 static IProxyItemVariable* proxyItemVariableFactory(IVariable* var, Integer pos = 0);
140 : m_family_names(
IK_Unknown + 1,
"__special__")
142 m_family_names[
IK_Cell] =
"Cell";
143 m_family_names[
IK_Face] =
"Face";
144 m_family_names[
IK_Edge] =
"Edge";
145 m_family_names[
IK_Node] =
"Node";
153 pos = _findEntity(entity);
155 pos = m_family_names.size();
156 m_family_names.add(entity);
166 m_overall_memory.
resize(length);
167 m_resident_memory.
resize(length);
169 m_overall_memory.
fill(0);
170 m_resident_memory.
fill(0);
180 catch (
const ArgumentException&) {
184 Int32 family_index = -1;
188 if (family_index >= 0) {
189 m_overall_memory[family_index] += memory;
192 m_overall_memory[kind] += memory;
201 m_resident_memory[kind] += memory;
202 if (family_index >= 0) {
203 m_resident_memory[family_index] += memory;
211 Integer pos = _findEntity(entity);
219 return m_overall_memory[offset];
223 _computeMemCell(cell);
224 return m_buffer.overall_memory;
230 Integer pos = _findEntity(entity);
238 return m_resident_memory[offset];
242 _computeMemCell(cell);
243 return m_buffer.resident_memory;
249 return _findEntity(entity);
253 return m_family_names[i];
258 Integer _findEntity(
const String& entity)
const
260 for (
int i = 0; i < m_family_names.
size(); ++i) {
261 if (m_family_names[i] == entity)
268 void _computeMemCell(
Cell cell)
271 if (cell.localId() == m_buffer.id)
273 m_buffer.id = cell.localId();
274 m_buffer.overall_memory = m_overall_memory[
IK_Cell];
275 m_buffer.resident_memory = m_resident_memory[
IK_Cell];
278 m_buffer.overall_memory += contrib * m_overall_memory[
IK_Node];
279 m_buffer.resident_memory += contrib * m_resident_memory[
IK_Node];
282 m_buffer.overall_memory += contrib * m_overall_memory[
IK_Face];
283 m_buffer.resident_memory += contrib * m_resident_memory[
IK_Face];
286 m_buffer.overall_memory += contrib * m_overall_memory[
IK_Edge];
287 m_buffer.resident_memory += contrib * m_resident_memory[
IK_Edge];
291 template <
typename ItemKind>
296 for (
const auto& item : list) {
297 contrib += 1.0 / (
Real)(item.nbCell());
310 Real overall_memory = 0;
311 Real resident_memory = 0;
323 CriteriaMng(
bool use_legacy_init);
329 void defaultMassCriterion(
bool mass_criterion)
331 if (!m_is_edited_mass_criterion)
332 m_use_mass_as_criterion = mass_criterion;
335 void setMassCriterion(
bool mass_criterion)
337 m_is_edited_mass_criterion =
true;
338 m_use_mass_as_criterion = mass_criterion;
341 bool useMassAsCriterion()
const {
return m_use_mass_as_criterion; }
342 bool useNbCellsAsCriterion()
const {
return m_nb_cells_as_criterion; }
344 void resetCriteria();
345 void clearVariables();
349 m_event_vars.add(criterion);
357 return *m_event_weights;
361 const VariableCellReal& massResWeight()
const {
return *m_mass_res_weight; }
364 void fillCellNewOwner()
366 if (!m_cell_new_owner.isNull())
367 m_cell_new_owner->fill(m_mesh->parallelMng()->commRank(), m_mesh->ownCells());
372 void setComputeComm(
bool active) { m_need_compute_comm = active; }
373 bool cellCommContrib()
const {
return m_cell_comm; }
374 void setCellCommContrib(
bool active) { m_cell_comm = active; }
375 void setNbCellsAsCriterion(
bool active) { m_nb_cells_as_criterion = active; }
377 bool needComputeComm()
const {
return m_need_compute_comm; }
378 bool isInit()
const {
return m_is_init; }
379 Integer addEntity(
const String& entity) {
return m_criteria->addEntity(entity); }
380 void computeCriteria();
384 void _computeOverallMass();
386 void _computeResidentMass();
387 void _computeEvents();
395 bool m_use_mass_as_criterion =
false;
396 bool m_nb_cells_as_criterion =
true;
397 bool m_cell_comm =
false;
398 bool m_need_compute_comm =
false;
399 bool m_is_edited_mass_criterion =
false;
400 bool m_is_init =
false;
408 IMesh* m_mesh =
nullptr;
415class ARCANE_IMPL_EXPORT LoadBalanceMngInternal
420 explicit LoadBalanceMngInternal(
bool mass_as_criterion,
bool is_legacy_init);
429 void setMassAsCriterion(
IMesh*
mesh,
bool active)
override;
430 void setNbCellsAsCriterion(
IMesh*
mesh,
bool active)
override;
431 void setCellCommContrib(
IMesh*
mesh,
bool active)
override;
432 void setComputeComm(
IMesh*
mesh,
bool active)
override;
438 bool cellCommContrib(
IMesh*
mesh)
override;
443 void endAccess()
override;
444 void notifyEndPartition()
override;
449 bool m_default_mass_criterion =
false;
450 bool m_is_legacy_init =
false;
451 std::unordered_map<IMesh*, Ref<CriteriaMng>> m_mesh_criterion;
Integer size() const
Number of elements in the vector.
Modifiable view of an array of type T.
void fill(ConstReferenceType value)
Fills the array with the value value.
void resize(Int64 s)
Changes the number of elements in the array to s.
Encapsulation of a pointer with a reference counter.
Internal API of ILoadBalanceMng to Arcane.
Interface proxy to access variables defining weights.
virtual Real operator[](ItemEnumerator i) const =0
Access to the value associated with a mesh entity, in the form of a Real.
virtual Integer getPos() const =0
Access to the associated family number.
Variable manager interface.
virtual VariableCollection usedVariables()=0
List of used variables.
virtual eDataType dataType() const =0
Data type managed by the variable (Real, Integer, ...).
virtual String itemFamilyName() const =0
Name of the associated family (null if none).
@ PNoExchange
Indicates that the variable should not be exchanged.
@ PTemporary
Indicates that the variable is temporary.
@ PSubDomainPrivate
Indicates that the variable is private to the subdomain.
@ PNoNeedSync
Indicates that the variable is not necessarily synchronized.
virtual int property() const =0
Returns the properties of the variable.
virtual eItemKind itemKind() const =0
Kind of mesh entities on which the variable is based.
Class for managing partitioning criteria.
Integer operator[](const String &entity) const
Management of entities and their names.
PartitionerMemoryInfo()
Construction based on the IVariableMng.
Real _computeMemContrib(ItemConnectedListViewTypeT< ItemKind > list)
Calculates the contribution of an entity to adjacent cells.
Integer addEntity(const String &entity)
Adds an entity and assigns it a number. The same name is not duplicated.
Real getResidentMemory(const String &entity) const
Returns the "resident" (to be transferred) memory associated with an entity.
Real getOverallMemory(const String &entity) const
Returns the total memory associated with an entity.
Encapsulation of an automatically destructing pointer.
Class for accessing the proxy without dereferencing in the code.
AutoRefT< IProxyItemVariable > m_var
Pointer to the variable.
Real operator[](ItemEnumerator i) const
Access to the value associated with a mesh entity, in the form of a Real.
static IProxyItemVariable * proxyItemVariableFactory(IVariable *var, Integer pos=0)
Factory for construction based on the initial variable type.
Unicode character string.
1D data vector with value semantics (STL style).
MeshVariableScalarRefT< Face, Real > VariableFaceReal
Real type quantity at face.
MeshVariableScalarRefT< Cell, Real > VariableCellReal
Real type quantity at cell center.
MeshVariableArrayRefT< Cell, Real > VariableCellArrayReal
Quantity at the cell center of real array type.
MeshVariableScalarRefT< Cell, Int32 > VariableCellInt32
Quantity at the cell center of 32-bit integer type.
MeshVariableScalarRefT< Face, Int32 > VariableFaceInt32
Quantity at the face of 32-bit integer type.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ARCANE_DATATYPE_EXPORT Integer dataTypeSize(eDataType type)
Size of data type type (which must be different from DT_String).
Int32 Integer
Type representing an integer.
@ IK_Particle
Particle mesh entity.
@ IK_Node
Node mesh entity.
@ IK_Cell
Cell mesh entity.
@ IK_Unknown
Unknown or uninitialized mesh entity.
@ IK_Face
Face mesh entity.
@ IK_Edge
Edge mesh entity.
double Real
Type representing a real number.
ItemConnectedListViewT< ItemType > ItemConnectedListViewTypeT
Generic list of connected entities.
@ DT_String
UTF-8 character string data type.
@ Cell
The mesh is AMR by cell.
std::int32_t Int32
Signed integer type of 32 bits.
Cache system for accessing memory related to a cell.