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"
39class ProxyItemVariableNull
44 ProxyItemVariableNull() {}
45 ~ProxyItemVariableNull() {}
62static ProxyItemVariableNull nullProxy;
71template <
typename DataType>
class ProxyItemVariable
81 ~ProxyItemVariable() {}
85 return static_cast<Real>(m_var[i]);
128CriteriaMng(
bool use_legacy_init)
129: m_nb_cells_as_criterion(!use_legacy_init)
130, m_cell_comm(use_legacy_init)
131, m_need_compute_comm(use_legacy_init)
146 MeshHandle mesh_handle = mesh->handle();
150 m_comm_costs =
new VariableFaceReal(VariableBuildInfo(mesh_handle,
"LbMngCommCost", vflags));
151 m_mass_over_weight =
new VariableCellReal(VariableBuildInfo(mesh_handle,
"LbMngOverallMass", vflags));
152 m_mass_res_weight =
new VariableCellReal(VariableBuildInfo(mesh_handle,
"LbMngResidentMass", vflags));
153 m_event_weights =
new VariableCellArrayReal(VariableBuildInfo(mesh_handle,
"LbMngMCriteriaWgt", vflags));
155 m_comm_costs->fill(1);
156 m_mass_over_weight->fill(1);
157 m_mass_res_weight->fill(1);
170 m_event_vars.resize(1);
181 m_event_weights =
nullptr;
182 m_mass_res_weight =
nullptr;
183 m_mass_over_weight =
nullptr;
184 m_comm_costs =
nullptr;
196 count = m_event_vars.size();
197 count -= ((m_use_mass_as_criterion) ? 0 : 1);
198 count += ((m_nb_cells_as_criterion) ? 1 : 0);
208 if (m_use_mass_as_criterion) {
209 StoreIProxyItemVariable cvar(m_mass_over_weight->variable());
210 m_event_vars[0] = cvar;
213 return m_event_vars.
subView(1, m_event_vars.size());
222 if (needComputeComm() || useMassAsCriterion()) {
223 m_criteria->computeMemory(m_mesh->variableMng());
224 _computeResidentMass();
226 if (needComputeComm()) {
229 if (useMassAsCriterion()) {
230 _computeOverallMass();
243 mass_over_weigth[icell] = m_criteria->getOverallMemory(*icell);
257 if (!m_comm_vars.empty())
260 for (
auto& commvar : m_comm_vars) {
262 comm_costs[iface] += commvar[iface] * m_criteria->getResidentMemory(commvar.getPos());
268 Real mem = mass_res_weight[icell];
269 for (Face face : icell->faces()) {
270 comm_costs[face] += mem * penalty;
276 IVariable* ivar = m_comm_costs->variable();
278 m_comm_costs->synchronize();
285_computeResidentMass()
289 mass_res_weight[icell] = m_criteria->getResidentMemory(*icell);
301 ITraceMng* tm = m_mesh->traceMng();
302 m_event_weights->resize(nbCriteria());
304 ArrayView<StoreIProxyItemVariable> event_vars = criteria();
306 const Int32 nb_event_var = event_vars.size();
307 const Int32 nb_criteria = nbCriteria();
309 tm->info() <<
"CriteriaMng: Compute Events nb_criteria=" << nb_criteria <<
" nb_event_var=" << nb_event_var;
314 if (nb_event_var == 0 && m_nb_cells_as_criterion) {
316 event_weights(icell, 0) = 1.0;
320 for (
Integer i = 0; i < event_vars.size(); ++i) {
323 if (m_nb_cells_as_criterion) {
325 event_weights(icell, 0) = 1;
327 event_weights(icell, count) = event_vars[i][icell];
339LoadBalanceMngInternal::
340LoadBalanceMngInternal(
bool mass_as_criterion,
bool is_legacy_init)
341: m_default_mass_criterion(mass_as_criterion)
342, m_is_legacy_init(is_legacy_init)
351 auto x = m_mesh_criterion.find(mesh);
352 if (x != m_mesh_criterion.end())
353 return *(x->second.get());
355 auto v = m_mesh_criterion.emplace(mesh, c);
357 return *(x->second.get());
363void LoadBalanceMngInternal::
366 _getCriteria(mesh).resetCriteria();
368 mesh->traceMng()->debug() <<
"LoadBalanceInternal -- Mesh : " << mesh->name() <<
" -- reset()";
375void LoadBalanceMngInternal::
381 m_mesh_handle = mesh->handle();
383 CriteriaMng& mesh_criterion = _getCriteria(mesh);
384 mesh_criterion.init(mesh);
385 mesh_criterion.defaultMassCriterion(m_default_mass_criterion);
387 mesh->traceMng()->info() <<
"LoadBalanceMngInternal::initAccess():"
388 <<
" use_memory=" << mesh_criterion.useMassAsCriterion()
389 <<
" use_nb_cell=" << mesh_criterion.useNbCellsAsCriterion()
390 <<
" nb_criteria=" << mesh_criterion.nbCriteria();
394 if (mesh_criterion.nbCriteria() == 0)
395 mesh_criterion.setNbCellsAsCriterion(
true);
397 mesh_criterion.computeCriteria();
399 mesh->traceMng()->debug() <<
"LoadBalanceInternal -- Mesh : " << mesh->name() <<
" -- initAccess()";
405void LoadBalanceMngInternal::
408 IMesh* mesh = m_mesh_handle.mesh();
412 _getCriteria(mesh).clearVariables();
414 mesh->traceMng()->debug() <<
"LoadBalanceInternal -- Mesh : " << mesh->name() <<
" -- clearVariables()";
420void LoadBalanceMngInternal::
423 CriteriaMng& criterion = _getCriteria(mesh);
424 StoreIProxyItemVariable cvar(count.variable(), criterion.addEntity(entity));
425 criterion.addMass(cvar);
426 mesh->traceMng()->debug() <<
"Set mass (name=" << count.name() <<
") criterion to mesh (name=" << mesh->name() <<
")";
432void LoadBalanceMngInternal::
435 StoreIProxyItemVariable cvar(count.variable());
436 _getCriteria(mesh).addCriterion(cvar);
437 mesh->traceMng()->debug() <<
"Set criterion (name=" << count.name() <<
") criterion to mesh (name=" << mesh->name() <<
")";
443void LoadBalanceMngInternal::
447 StoreIProxyItemVariable cvar(count.variable());
449 _getCriteria(mesh).addCriterion(cvar);
450 mesh->traceMng()->debug() <<
"Set criterion (name=" << count.name() <<
") criterion to mesh (name=" << mesh->name() <<
")";
456void LoadBalanceMngInternal::
459 CriteriaMng& criterion = _getCriteria(mesh);
460 StoreIProxyItemVariable cvar(count.variable(), criterion.addEntity(entity));
461 criterion.addCommCost(cvar);
462 mesh->traceMng()->debug() <<
"Set CommCost (name=" << count.name() <<
") criterion to mesh (name=" << mesh->name() <<
")";
468Integer LoadBalanceMngInternal::
471 return _getCriteria(mesh).nbCriteria();
477void LoadBalanceMngInternal::
478setMassAsCriterion(
IMesh*
mesh,
bool active)
480 _getCriteria(mesh).setMassCriterion(active);
486void LoadBalanceMngInternal::
487setNbCellsAsCriterion(
IMesh*
mesh,
bool active)
489 _getCriteria(mesh).setNbCellsAsCriterion(active);
495void LoadBalanceMngInternal::
496setCellCommContrib(
IMesh*
mesh,
bool active)
498 _getCriteria(mesh).setCellCommContrib(active);
504bool LoadBalanceMngInternal::
507 if (m_mesh_criterion.find(mesh) == m_mesh_criterion.end()) {
510 return _getCriteria(mesh).cellCommContrib();
516void LoadBalanceMngInternal::
519 _getCriteria(mesh).setComputeComm(active);
528 return _getCriteria(mesh).commCost();
537 return _getCriteria(mesh).massWeight();
546 return _getCriteria(mesh).massResWeight();
555 return _getCriteria(mesh).criteriaWeight();
561void LoadBalanceMngInternal::
564 IMesh* mesh = m_mesh_handle.mesh();
565 _getCriteria(mesh).fillCellNewOwner();
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Modifiable view of an array of type T.
constexpr ArrayView< T > subView(Integer abegin, Integer asize) noexcept
Sub-view starting from element abegin and containing asize elements.
Interface proxy to access variables defining weights.
virtual eDataType dataType() const =0
Data type managed by the variable (Real, Integer, ...).
@ PTemporary
Indicates that the variable is temporary.
@ PExecutionDepend
Indicates that the variable value is dependent on the execution.
@ PNoDump
Indicates that the variable should not be saved.
Scalar variable on a mesh entity type.
Class for managing partitioning criteria.
Integer getPos() const
Access to the associated family number.
void deleteMe()
Destroys this object.
Real operator[](ItemEnumerator) const
Access to the value associated with a mesh entity, in the form of a Real.
Implementation of the IProxyItemVariable interface.
Integer getPos() const
Access to the associated family number.
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.
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.
@ ReduceSum
Sum of values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Ref< TrueType > createRef(Args &&... args)
Creates an instance of type TrueType with arguments Args and returns a reference to it.
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
@ DT_Int32
32-bit integer data type
std::int32_t Int32
Signed integer type of 32 bits.