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]);
 
 
 
  127CriteriaMng(
bool use_legacy_init)
 
  128: m_nb_cells_as_criterion(!use_legacy_init)
 
  129, m_cell_comm(use_legacy_init)
 
  130, m_need_compute_comm(use_legacy_init)
 
  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);
 
  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()) { 
 
  222    m_criteria->computeMemory(m_mesh->variableMng());
 
  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();
 
  277  m_comm_costs->synchronize();
 
  284_computeResidentMass()
 
  288    mass_res_weight[icell] = m_criteria->getResidentMemory(*icell);
 
  300  ITraceMng* tm = m_mesh->traceMng();
 
  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)
 
  350  auto x = m_mesh_criterion.find(mesh);
 
  351  if (x != m_mesh_criterion.end())
 
  352    return *(x->second.get());
 
  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::
 
  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::
 
  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::
 
  506  if(m_mesh_criterion.find(mesh) == m_mesh_criterion.end()){
 
  509  return _getCriteria(mesh).cellCommContrib();
 
  515void LoadBalanceMngInternal::
 
  518  _getCriteria(mesh).setComputeComm(active);
 
  527  return _getCriteria(mesh).commCost();
 
  536  return _getCriteria(mesh).massWeight();
 
  545  return _getCriteria(mesh).massResWeight();
 
  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.
 
Vue modifiable d'un tableau d'un type T.
 
constexpr ArrayView< T > subView(Integer abegin, Integer asize) noexcept
Sous-vue à partir de l'élément abegin et contenant asize éléments.
 
Interface proxy pour accéder aux variables définissant les poids.
 
Interface d'une variable.
 
virtual eDataType dataType() const =0
Type de la donnée gérée par la variable (Real, Integer, ...)
 
@ 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.
 
Variable scalaire sur un type d'entité du maillage.
 
Classe de gestion des critèes de partitionnement.
 
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.
 
Chaîne de caractères unicode.
 
MeshVariableScalarRefT< Face, Real > VariableFaceReal
Grandeur aux faces de type réel.
 
MeshVariableScalarRefT< Cell, Real > VariableCellReal
Grandeur au centre des mailles de type réel.
 
MeshVariableArrayRefT< Cell, Real > VariableCellArrayReal
Grandeur au centre des mailles de type tableau de réel.
 
MeshVariableScalarRefT< Cell, Int32 > VariableCellInt32
Grandeur au centre des mailles de type entier 32 bits.
 
MeshVariableScalarRefT< Face, Int32 > VariableFaceInt32
Grandeur aux faces de type entier 32 bits.
 
@ ReduceSum
Somme des valeurs.
 
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
 
Ref< TrueType > createRef(Args &&... args)
Créé une instance de type TrueType avec les arguments Args et retourne une référence dessus.
 
Int32 Integer
Type représentant un entier.
 
double Real
Type représentant un réel.
 
@ DT_Int32
Donnée de type entier 32 bits.
 
@ DT_Real
Donnée de type réel.
 
std::int32_t Int32
Type entier signé sur 32 bits.