14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/TraceInfo.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/MultiArray2.h"
20#include "arcane/utils/HashTableMap.h"
21#include "arcane/utils/Deleter.h"
23#include "arcane/IMesh.h"
24#include "arcane/IParallelMng.h"
25#include "arcane/IItemFamily.h"
26#include "arcane/Item.h"
27#include "arcane/VariableTypes.h"
28#include "arcane/IMeshPartitionConstraint.h"
30#include "arcane/mesh/MeshPartitionConstraintMng.h"
55 m_mesh(mesh), m_is_debug(
is_debug), m_true_first_uid(5000,
true),
56 m_uids_owner(5000,
true)
73MeshPartitionConstraintMng::
74MeshPartitionConstraintMng(
IMesh* mesh)
84MeshPartitionConstraintMng::
85~MeshPartitionConstraintMng()
88 m_weak_constraints.each(
Deleter());
109 m_constraints.remove(constraint);
118 Helper h(m_mesh,m_is_debug);
119 _computeAndApplyConstraints(h);
129 Helper h(m_mesh,m_is_debug);
130 _computeAndApplyConstraints(h);
131 h.computeList(tied_uids);
137void MeshPartitionConstraintMng::
138_computeAndApplyConstraints(Helper& h)
143 IMeshPartitionConstraint* c = *i;
144 c->addLinkedCells(linked_cells,linked_owners);
146 h.merge(linked_cells,linked_owners);
149void MeshPartitionConstraintMng::
150_computeAndApplyWeakConstraints(Helper& h)
155 IMeshPartitionConstraint* c = *i;
156 c->addLinkedCells(linked_cells,linked_owners);
158 h.merge(linked_cells,linked_owners);
167 m_weak_constraints.add(constraint);
173 m_weak_constraints.remove(constraint);
179 Helper h(m_mesh,m_is_debug);
180 _computeAndApplyWeakConstraints(h);
187 Helper h(m_mesh,m_is_debug);
188 _computeAndApplyWeakConstraints(h);
189 h.computeList(tied_uids);
195void MeshPartitionConstraintMng::Helper::
202 IParallelMng* pm = m_mesh->parallelMng();
207 Integer nb_global = global_linked_items.size() / 2;
208 info() <<
"NB_GLOBAL_LINKED_CELL=" << nb_global;
210 m_true_first_uid.clear();
211 m_uids_owner.clear();
215 for( Integer i=0; i<nb_global; ++i ){
216 Int64 first_uid = global_linked_items[(i*2)];
217 Int64 second_uid = global_linked_items[(i*2)+1];
218 Int32 first_owner = global_linked_owners[i];
219 info() <<
"LinkedItem: first_uid=" << first_uid
220 <<
" second_uid=" << second_uid
221 <<
" first_owner=" << first_owner;
227 for( Integer i=0; i<nb_global; ++i ){
228 Int64 first_uid = global_linked_items[(i*2)];
229 Int64 second_uid = global_linked_items[(i*2)+1];
231 Int32 first_owner = global_linked_owners[i];
232 m_uids_owner.add(first_uid,first_owner);
235 ItemFirstUidData* first_data = m_true_first_uid.lookup(first_uid);
236 ItemFirstUidData* second_data = m_true_first_uid.lookup(second_uid);
237 Int64 first_data_uid = first_uid;
238 Int64 second_data_uid = second_uid;
240 first_data_uid = first_data->value();
242 second_data_uid = second_data->value();
245 if (second_data_uid>smallest_uid){
247 info() <<
"Changed second current=" << second_data->value() <<
" to " << smallest_uid
248 <<
" (first=" << first_uid <<
",second=" << second_uid <<
")";
249 second_data->setValue(smallest_uid);
255 info() <<
"Changed second add current=" << second_uid <<
" to " << smallest_uid
256 <<
" (first=" << first_uid <<
",second=" << second_uid <<
")";
258 m_true_first_uid.add(second_uid,smallest_uid);
263 if (first_data_uid>smallest_uid){
265 info() <<
"Changed first current=" << first_data->value() <<
" to " << smallest_uid
266 <<
" (first=" << first_uid <<
",second=" << second_uid <<
")";
267 first_data->setValue(smallest_uid);
273 info() <<
"Changed first add current=" << first_uid <<
" to " << smallest_uid
274 <<
" (first=" << first_uid <<
",second=" << second_uid <<
")";
276 m_true_first_uid.add(first_uid,smallest_uid);
281 debug(
Trace::High) <<
"NB_CHANGED=" << nb_changed <<
" iter=" << nb_iter;
282 }
while (nb_changed!=0 && nb_iter<100);
284 fatal() <<
"Too many iterations";
287 for( Integer i=0; i<nb_global; ++i ){
288 Int64 first_uid = global_linked_items[(i*2)];
289 Int64 second_uid = global_linked_items[(i*2)+1];
290 ItemFirstUidData* first_data = m_true_first_uid.lookup(first_uid);
292 m_true_first_uid.add(first_uid,first_uid);
293 ItemFirstUidData* second_data = m_true_first_uid.lookup(second_uid);
295 m_true_first_uid.add(second_uid,first_uid);
302void MeshPartitionConstraintMng::Helper::
310 for(
auto i : m_true_first_uid.buckets() )
311 for( ItemFirstUidData* nbid = i; nbid; nbid = nbid->next() ){
312 cells_uid.
add(nbid->key());
313 cells_owner.add(m_uids_owner[nbid->value()]);
315 Integer nb_cell = cells_uid.size();
317 IItemFamily* cell_family = m_mesh->cellFamily();
318 cell_family->itemsUniqueIdToLocalId(cells_local_id,cells_uid,
false);
320 CellInfoListView cells_internal(cell_family);
321 for( Integer i=0; i<nb_cell; ++i ){
322 Int32 lid = cells_local_id[i];
323 if (lid!=NULL_ITEM_LOCAL_ID){
324 Cell cell = cells_internal[lid];
326 info() <<
"Change cell owner uid=" << cell.uniqueId() <<
" old=" << cell.owner()
327 <<
" new=" << cells_owner[i];
328 cells_new_owner[cell] = cells_owner[i];
333 cells_new_owner.synchronize();
339void MeshPartitionConstraintMng::Helper::
340computeList(MultiArray2<Int64> & tied_uids)
344 HashTableMapT<Int64,Integer> uids_tied_index(5000,
true);
346 for(
auto i : m_true_first_uid.buckets() )
347 for( ItemFirstUidData* nbid = i; nbid; nbid = nbid->next() ){
348 Int64 tied_uid = nbid->value();
349 HashTableMapT<Int64,Integer>::Data* d = uids_tied_index.lookup(tied_uid);
351 ++nb_tieds[d->value()];
353 Integer index = nb_tieds.size();
354 uids_tied_index.add(tied_uid,index);
359 info() <<
"NB_TIED=" << nb_tieds.size();
360 tied_uids.resize(nb_tieds);
363 for(
auto i : m_true_first_uid.buckets() )
364 for( ItemFirstUidData* nbid = i; nbid; nbid = nbid->next() ){
365 Int64 tied_uid = nbid->value();
366 Integer index = uids_tied_index[tied_uid];
367 Integer index2 = nb_tieds[index];
369 tied_uids.setAt(index,index2,nbid->key());
372 for( Integer i=0, n=tied_uids.dim1Size(); i<n; ++i ){
375 for( Integer j=0, js=uids.size(); j<js; ++j ){
Tableau d'items de types quelconques.
Classe utilitaire pour la destruction des objets alloués par new.
virtual ITraceMng * traceMng()=0
Gestionnaire de message associé
Interface d'une contrainte de partitionnement d'un maillage.
virtual void allGatherVariable(ConstArrayView< char > send_buf, Array< char > &recv_buf)=0
Effectue un regroupement sur tous les processeurs.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
ListEnumeratorT< T > Enumerator
Type d'un itérateur constant sur tout le tableau.
virtual void computeConstraintList(Int64MultiArray2 &tied_uids)
Calcule les contraintes et retourne une liste d'entités liées.
virtual void computeAndApplyWeakConstraints()
Calcule et applique des contraintes.
virtual void removeWeakConstraint(IMeshPartitionConstraint *constraint)
Supprime une contrainte.
virtual void computeWeakConstraintList(Int64MultiArray2 &tied_uids)
Calcule les contraintes et retourne une liste d'entités liées.
virtual void addWeakConstraint(IMeshPartitionConstraint *constraint)
Ajoute une contrainte.
virtual void addConstraint(IMeshPartitionConstraint *constraint)
Ajoute une contrainte.
virtual void removeConstraint(IMeshPartitionConstraint *constraint)
Supprime une contrainte.
virtual void computeAndApplyConstraints()
Calcule et applique des contraintes.
Helper pour la gestion des contrainte.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Classe d'accès aux traces.
ARCCORE_HOST_DEVICE Real2 min(Real2 a, Real2 b)
Retourne le minimum de deux Real2.
ItemVariableScalarRefT< Int32 > VariableItemInt32
Grandeur de type entier 32 bits.
Array< Int64 > Int64Array
Tableau dynamique à une dimension d'entiers 64 bits.
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
MultiArray2< Int64 > Int64MultiArray2
Tableau 2D a taille variable d'entiers 64 bits.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Array< Int32 > Int32Array
Tableau dynamique à une dimension d'entiers 32 bits.
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
UniqueArray< Integer > IntegerUniqueArray
Tableau dynamique à une dimension d'entiers.
@ Highest
Niveau le plus élevé
Int32 Integer
Type représentant un entier.