14#include "arcane/impl/internal/LoadBalanceMngInternal.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/StringBuilder.h"
18#include "arcane/utils/MultiArray2.h"
19#include "arcane/utils/ITraceMng.h"
21#include "arcane/core/IMesh.h"
22#include "arcane/core/IModule.h"
23#include "arcane/core/ItemPrinter.h"
62static ProxyItemVariableNull nullProxy;
85 return static_cast<Real
>(m_var[i]);
110 switch (
var->dataType()) {
145 MeshHandle mesh_handle = mesh->handle();
149 m_comm_costs =
new VariableFaceReal(VariableBuildInfo(mesh_handle,
"LbMngCommCost", vflags));
150 m_mass_over_weight =
new VariableCellReal(VariableBuildInfo(mesh_handle,
"LbMngOverallMass", vflags));
151 m_mass_res_weight =
new VariableCellReal(VariableBuildInfo(mesh_handle,
"LbMngResidentMass", vflags));
152 m_event_weights =
new VariableCellArrayReal(VariableBuildInfo(mesh_handle,
"LbMngMCriteriaWgt", vflags));
154 m_comm_costs->fill(1);
155 m_mass_over_weight->fill(1);
156 m_mass_res_weight->fill(1);
169 m_event_vars.resize(1);
180 m_event_weights =
nullptr;
181 m_mass_res_weight =
nullptr;
182 m_mass_over_weight =
nullptr;
183 m_comm_costs =
nullptr;
195 count = m_event_vars.size();
196 count -= ((m_use_mass_as_criterion) ? 0 : 1);
197 count += ((m_nb_cells_as_criterion) ? 1 : 0);
204ArrayView<StoreIProxyItemVariable> CriteriaMng::
207 if (m_use_mass_as_criterion) {
208 StoreIProxyItemVariable cvar(m_mass_over_weight->variable());
209 m_event_vars[0] = cvar;
212 return m_event_vars.subView(1, m_event_vars.size());
221 if (needComputeComm() || useMassAsCriterion()) {
223 _computeResidentMass();
225 if (needComputeComm()) {
228 if (useMassAsCriterion()) {
229 _computeOverallMass();
242 mass_over_weigth[icell] = m_criteria->getOverallMemory(*icell);
256 if (!m_comm_vars.empty())
259 for (
auto& commvar : m_comm_vars) {
261 comm_costs[iface] += commvar[iface] * m_criteria->getResidentMemory(commvar.getPos());
267 Real mem = mass_res_weight[icell];
268 for (Face face : icell->faces()) {
269 comm_costs[face] += mem * penalty;
275 IVariable* ivar = m_comm_costs->variable();
276 ivar->itemFamily()->reduceFromGhostItems(ivar, Parallel::ReduceSum);
277 m_comm_costs->synchronize();
284_computeResidentMass()
288 mass_res_weight[icell] = m_criteria->getResidentMemory(*icell);
301 m_event_weights->resize(nbCriteria());
303 ArrayView<StoreIProxyItemVariable> event_vars = criteria();
305 const Int32 nb_event_var = event_vars.size();
306 const Int32 nb_criteria = nbCriteria();
308 tm->info() <<
"CriteriaMng: Compute Events nb_criteria=" << nb_criteria <<
" nb_event_var=" << nb_event_var;
313 if (nb_event_var == 0 && m_nb_cells_as_criterion) {
315 event_weights(icell, 0) = 1.0;
319 for (Integer i = 0; i < event_vars.size(); ++i) {
322 if (m_nb_cells_as_criterion) {
324 event_weights(icell, 0) = 1;
326 event_weights(icell, count) = event_vars[i][icell];
338LoadBalanceMngInternal::
339LoadBalanceMngInternal(
bool mass_as_criterion,
bool is_legacy_init)
340: m_default_mass_criterion(mass_as_criterion)
341, m_is_legacy_init(is_legacy_init)
347CriteriaMng& LoadBalanceMngInternal::
348_getCriteria(IMesh* mesh)
350 auto x = m_mesh_criterion.find(mesh);
351 if (x != m_mesh_criterion.end())
352 return *(x->second.get());
353 auto c = createRef<CriteriaMng>(m_is_legacy_init);
354 auto v = m_mesh_criterion.emplace(mesh, c);
356 return *(x->second.get());
362void LoadBalanceMngInternal::
365 _getCriteria(mesh).resetCriteria();
367 mesh->
traceMng()->
debug() <<
"LoadBalanceInternal -- Mesh : " << mesh->name() <<
" -- reset()";
374void LoadBalanceMngInternal::
375initAccess(IMesh* mesh)
380 m_mesh_handle = mesh->handle();
382 CriteriaMng& mesh_criterion = _getCriteria(mesh);
383 mesh_criterion.init(mesh);
384 mesh_criterion.defaultMassCriterion(m_default_mass_criterion);
386 mesh->traceMng()->info() <<
"LoadBalanceMngInternal::initAccess():"
387 <<
" use_memory=" << mesh_criterion.useMassAsCriterion()
388 <<
" use_nb_cell=" << mesh_criterion.useNbCellsAsCriterion()
389 <<
" nb_criteria=" << mesh_criterion.nbCriteria();
393 if (mesh_criterion.nbCriteria() == 0)
394 mesh_criterion.setNbCellsAsCriterion(
true);
396 mesh_criterion.computeCriteria();
398 mesh->traceMng()->debug() <<
"LoadBalanceInternal -- Mesh : " << mesh->name() <<
" -- initAccess()";
404void LoadBalanceMngInternal::
407 IMesh* mesh = m_mesh_handle.
mesh();
411 _getCriteria(mesh).clearVariables();
413 mesh->
traceMng()->
debug() <<
"LoadBalanceInternal -- Mesh : " << mesh->name() <<
" -- clearVariables()";
419void LoadBalanceMngInternal::
422 CriteriaMng& criterion = _getCriteria(mesh);
423 StoreIProxyItemVariable cvar(count.variable(), criterion.addEntity(entity));
424 criterion.addMass(cvar);
425 mesh->traceMng()->debug() <<
"Set mass (name=" << count.name() <<
") criterion to mesh (name=" << mesh->name() <<
")";
431void LoadBalanceMngInternal::
434 StoreIProxyItemVariable cvar(count.variable());
435 _getCriteria(mesh).addCriterion(cvar);
436 mesh->
traceMng()->
debug() <<
"Set criterion (name=" << count.name() <<
") criterion to mesh (name=" << mesh->name() <<
")";
442void LoadBalanceMngInternal::
446 StoreIProxyItemVariable cvar(count.variable());
448 _getCriteria(mesh).addCriterion(cvar);
449 mesh->
traceMng()->
debug() <<
"Set criterion (name=" << count.name() <<
") criterion to mesh (name=" << mesh->name() <<
")";
455void LoadBalanceMngInternal::
458 CriteriaMng& criterion = _getCriteria(mesh);
459 StoreIProxyItemVariable cvar(count.variable(), criterion.addEntity(entity));
460 criterion.addCommCost(cvar);
461 mesh->traceMng()->debug() <<
"Set CommCost (name=" << count.name() <<
") criterion to mesh (name=" << mesh->name() <<
")";
467Integer LoadBalanceMngInternal::
468nbCriteria(IMesh* mesh)
470 return _getCriteria(mesh).nbCriteria();
476void LoadBalanceMngInternal::
477setMassAsCriterion(IMesh* mesh,
bool active)
479 _getCriteria(mesh).setMassCriterion(active);
485void LoadBalanceMngInternal::
486setNbCellsAsCriterion(IMesh* mesh,
bool active)
488 _getCriteria(mesh).setNbCellsAsCriterion(active);
494void LoadBalanceMngInternal::
495setCellCommContrib(IMesh* mesh,
bool active)
497 _getCriteria(mesh).setCellCommContrib(active);
503bool LoadBalanceMngInternal::
504cellCommContrib(IMesh* mesh)
506 if(m_mesh_criterion.find(mesh) == m_mesh_criterion.end()){
509 return _getCriteria(mesh).cellCommContrib();
515void LoadBalanceMngInternal::
516setComputeComm(IMesh* mesh,
bool active)
518 _getCriteria(mesh).setComputeComm(active);
527 return _getCriteria(mesh).commCost();
534massWeight(IMesh* mesh)
536 return _getCriteria(mesh).massWeight();
543massResWeight(IMesh* mesh)
545 return _getCriteria(mesh).massResWeight();
552mCriteriaWeight(IMesh* mesh)
554 return _getCriteria(mesh).criteriaWeight();
560void LoadBalanceMngInternal::
563 IMesh* mesh = m_mesh_handle.
mesh();
564 _getCriteria(mesh).fillCellNewOwner();
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
virtual ITraceMng * traceMng()=0
Gestionnaire de message associé
virtual CellGroup ownCells()=0
Groupe de toutes les mailles propres au domaine.
virtual FaceGroup ownFaces()=0
Groupe de toutes les faces propres au domaine.
virtual IVariableMng * variableMng() const =0
Gestionnaire de variable associé
Interface proxy pour accéder aux variables définissant les poids.
Interface d'une variable.
@ PTemporary
Indique que la variable est temporaire.
@ PExecutionDepend
Indique que la valeur de la variable est dépendante de l'exécution.
@ PNoDump
Indique que la variable ne doit pas être sauvegardée.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
IMesh * mesh() const
Maillage associé.
Classe de gestion des critèes de partitionnement.
Implementation "nulle" de l'interface IProxyItemVariable. Permet d'avoir une variable référence unita...
Integer getPos() const
Accès au numéro de la famille associée.
void deleteMe()
Détruit cet objet.
Real operator[](ItemEnumerator) const
Accès à la valeur associée à une entité du maillage, sous forme d'un Real.
Implementation de l'interface IProxyItemVariable.
Integer getPos() const
Accès au numéro de la famille associée.
Real operator[](ItemEnumerator i) const
Accès à la valeur associée à une entité du maillage, sous forme d'un Real.
static IProxyItemVariable * proxyItemVariableFactory(IVariable *var, Integer pos=0)
Factory pour la constructions selon le type de variable initiale.
virtual TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium)=0
Flot pour un message de debug.
ITraceMng * traceMng() const
Gestionnaire de trace.
MeshVariableScalarRefT< Cell, Real > VariableCellReal
Grandeur au centre des mailles de type réel.
MeshVariableScalarRefT< Face, Int32 > VariableFaceInt32
Grandeur aux faces de type entier 32 bits.
MeshVariableScalarRefT< Face, Real > VariableFaceReal
Grandeur aux faces de type réel.
MeshVariableScalarRefT< Cell, Int32 > VariableCellInt32
Grandeur au centre des mailles de type entier 32 bits.
MeshVariableArrayRefT< Cell, Real > VariableCellArrayReal
Grandeur au centre des mailles de type tableau de réel.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
@ DT_Int32
Donnée de type entier 32 bits.
@ DT_Real
Donnée de type réel.
Int32 Integer
Type représentant un entier.