14#include "arcane/utils/FatalErrorException.h"
15#include "arcane/utils/TraceInfo.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/ValueConvert.h"
19#include "arcane/IParallelMng.h"
20#include "arcane/Timer.h"
21#include "arcane/IItemFamilyPolicyMng.h"
22#include "arcane/IItemFamilyExchanger.h"
23#include "arcane/IParticleFamily.h"
25#include "arcane/mesh/MeshExchanger.h"
26#include "arcane/mesh/DynamicMesh.h"
27#include "arcane/mesh/MeshExchange.h"
28#include "arcane/core/internal/IMeshModifierInternal.h"
40MeshExchanger(IMesh* mesh,ITimeStats* stats)
41: TraceAccessor(mesh->traceMng())
44, m_phase(ePhase::Init)
48 String max_pending_str = platform::getEnvironmentVariable(
"ARCANE_MESH_EXCHANGE_MAX_PENDING_MESSAGE");
49 if (!max_pending_str.null()){
50 Int32 max_pending = 0;
51 if (!builtInGetValue(max_pending,max_pending_str))
52 m_exchanger_option.setMaxPendingMessage(max_pending);
55 String use_collective_str = platform::getEnvironmentVariable(
"ARCANE_MESH_EXCHANGE_USE_COLLECTIVE");
56 if (use_collective_str==
"1" || use_collective_str==
"TRUE")
57 m_exchanger_option.setExchangeMode(ParallelExchangerOptions::EM_Collective);
59 m_exchanger_option.setVerbosityLevel(1);
68 for( IItemFamilyExchanger* exchanger : m_family_exchangers )
81 if ( !m_mesh->itemFamilyNetwork() || !IItemFamilyNetwork::plug_serializer )
87 UniqueArray<IItemFamily*> sorted_families;
89 sorted_families.reserve(families.count());
90 sorted_families.add(m_mesh->cellFamily());
91 sorted_families.add(m_mesh->faceFamily());
92 sorted_families.add(m_mesh->edgeFamily());
93 sorted_families.add(m_mesh->nodeFamily());
94 for( IItemFamily* family : families )
96 IParticleFamily* particle_family = family->toParticleFamily();
98 sorted_families.add(family);
106 std::map<IItemFamily*,IItemFamilyExchanger*> family_exchanger_map;
107 for( IItemFamily* family : sorted_families ){
108 _addItemFamilyExchanger(family);
113 if(m_mesh->useMeshItemFamilyDependencies())
115 _buildWithItemFamilyNetwork();
119 std::set<String> family_set ;
120 UniqueArray<IItemFamily*> sorted_families;
122 sorted_families.reserve(families.count());
123 sorted_families.add(m_mesh->cellFamily());
124 family_set.insert(m_mesh->cellFamily()->name()) ;
125 sorted_families.add(m_mesh->faceFamily());
126 family_set.insert(m_mesh->faceFamily()->name()) ;
127 sorted_families.add(m_mesh->edgeFamily());
128 family_set.insert(m_mesh->edgeFamily()->name()) ;
129 sorted_families.add(m_mesh->nodeFamily());
130 family_set.insert(m_mesh->nodeFamily()->name()) ;
131 for( IItemFamily* family : families )
133 IParticleFamily* particle_family = family->toParticleFamily();
136 sorted_families.add(family);
137 family_set.insert(family->name()) ;
141 for(
auto family : m_mesh->itemFamilyNetwork()->getFamilies(IItemFamilyNetwork::InverseTopologicalOrder) )
143 auto value = family_set.insert(family->name()) ;
146 sorted_families.add(family) ;
155 std::map<IItemFamily*,IItemFamilyExchanger*> family_exchanger_map;
156 for( IItemFamily* family : sorted_families ){
157 _addItemFamilyExchanger(family);
161 m_phase = ePhase::ComputeInfos;
168_buildWithItemFamilyNetwork()
170 m_mesh->itemFamilyNetwork()->schedule([&](IItemFamily* family) {
171 _addItemFamilyExchanger(family);
172 }, IItemFamilyNetwork::InverseTopologicalOrder);
174 for( IItemFamily* family : m_mesh->itemFamilies() ){
175 IParticleFamily* particle_family = family->toParticleFamily();
177 _addItemFamilyExchanger(family);
185_addItemFamilyExchanger(IItemFamily* family)
187 IItemFamilyExchanger* exchanger = family->policyMng()->createExchanger();
188 m_family_exchangers.add(exchanger);
189 m_family_exchanger_map.insert(std::make_pair(family,exchanger));
190 exchanger->setParallelExchangerOption(m_exchanger_option);
197_checkPhase(ePhase wanted_phase)
199 if (m_phase!=wanted_phase)
200 ARCANE_FATAL(
"Invalid exchange phase wanted={0} current={1}",
201 (
int)wanted_phase,(
int)m_phase);
208computeExchangeInfos()
210 _checkPhase(ePhase::ComputeInfos);
217 Timer::Action ts_action1(m_time_stats,
"MeshExchangeComputeInfos",
true);
230 pwarning() <<
"No load balance is performed";
237 if (exchanger==cell_exchanger)
240 info() <<
"ComputeExchange family=" << family->
name()
250 exchanger->computeExchangeItems();
252 exchanger->setExchangeItems(mesh_exchange.
getItemsToSend(family));
253 exchanger->computeExchangeInfos();
266 Int32 rank = m_mesh->meshPartInfo().partRank();
272 Integer new_owner = owners[item];
278 m_phase = ePhase::ProcessExchange;
289 _checkPhase(ePhase::ProcessExchange);
294 Timer::Action ts_action1(m_time_stats,
"MessagesExchange",
true);
299 e->processExchange();
302 m_phase = ePhase::RemoveItems;
311 _checkPhase(ePhase::RemoveItems);
324 Timer::Action ts_action1(m_time_stats,
"RemoveSendedItems",
true);
329 exchanger->removeSentItems();
333 m_mesh->modifier()->_modifierInternalApi()->removeNeedRemoveMarkedItems();
335 m_phase = ePhase::AllocateItems;
342allocateReceivedItems()
344 _checkPhase(ePhase::AllocateItems);
347 Timer::Action ts_action1(m_time_stats,
"ReadAndAllocItems",
true);
352 e->readAndAllocItems();
356 if (m_mesh->itemFamilyNetwork() && m_mesh->itemFamilyNetwork()->isActivated())
358 auto family_set = m_mesh->itemFamilyNetwork()->getFamilies();
359 for (
auto family : family_set) {
360 m_family_exchanger_map[family]->readAndAllocItemRelations();
366 e->readAndAllocSubMeshItems();
374 e->itemFamily()->notifyItemsOwnerChanged();
377 m_phase = ePhase::UpdateItemGroups;
386 _checkPhase(ePhase::UpdateItemGroups);
393 m_phase = ePhase::UpdateVariables;
402 _checkPhase(ePhase::UpdateVariables);
411 m_phase = ePhase::Finalize;
420 _checkPhase(ePhase::Finalize);
430 e->finalizeExchange();
432 m_phase = ePhase::Ended;
441 auto x = m_family_exchanger_map.find(family);
442 if (x==m_family_exchanger_map.end())
460_setNextPhase(ePhase next_phase)
462 m_phase = next_phase;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Échange des entités et leurs caractéristiques pour une famille donnée.
virtual bool computeExchangeInfos()=0
Détermine les informations nécessaires pour les échanges.
virtual void setExchangeItems(ConstArrayView< std::set< Int32 > > items_to_send)=0
Positionne la liste des entités à échanger.
Interface d'une famille d'entités.
virtual IParticleFamily * toParticleFamily()=0
Retourne l'interface de la famille de particule de cette famille.
virtual ItemGroup allItems() const =0
Groupe de toutes les entités.
virtual String name() const =0
Nom de la famille.
virtual void notifyItemsOwnerChanged()=0
Notifie que les entités propres au sous-domaine de la famille ont été modifiées.
virtual VariableItemInt32 & itemsNewOwner()=0
Variable contenant le numéro du nouveau sous-domaine propriétaire de l'entité.
virtual IPrimaryMesh * toPrimaryMesh()=0
Retourne l'instance sous la forme d'un IPrimaryMesh.
Interface d'une famille de particules.
virtual bool getEnableGhostItems() const =0
récupère le flag pour gérer les particules ghost de la famille
virtual IItemFamily * itemFamily()=0
Interface sur la famille.
Classe de base d'un élément de maillage.
impl::MutableItemBase mutableItemBase() const
Partie interne modifiable de l'entité.
void setOwner(Integer suid, Int32 current_sub_domain)
Positionne le numéro du sous-domaine propriétaire de l'entité.
Postionne le nom de l'action en cours d'exécution.
TraceMessage info() const
Flot pour un message d'information.
TraceMessage pwarning() const
Echange des entités de maillages entre entre sous-domaines.
ConstArrayView< std::set< Int32 > > getItemsToSend(IItemFamily *family) const
Liste par sous-domaine des entités à envoyer pour la famille family.
void computeInfos()
Calcule les infos.
IItemFamilyExchanger * findExchanger(IItemFamily *family) override
Échangeur associé à la famille family. Lance une exception si non trouvé
ItemVariableScalarRefT< Int32 > VariableItemInt32
Grandeur de type entier 32 bits.
Int32 Integer
Type représentant un entier.
Collection< IItemFamily * > IItemFamilyCollection
Collection de familles d'entités.
std::int32_t Int32
Type entier signé sur 32 bits.