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/core/IParallelMng.h"
20#include "arcane/core/Timer.h"
21#include "arcane/core/IItemFamilyPolicyMng.h"
22#include "arcane/core/IItemFamilyExchanger.h"
23#include "arcane/core/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"
29#include "arcane/core/internal/IItemFamilySerializerMngInternal.h"
30#include "arcane/core/internal/IMeshInternal.h"
42MeshExchanger(IMesh* mesh, ITimeStats* stats)
43: TraceAccessor(mesh->traceMng())
46, m_phase(ePhase::Init)
50 String max_pending_str = platform::getEnvironmentVariable(
"ARCANE_MESH_EXCHANGE_MAX_PENDING_MESSAGE");
51 if (!max_pending_str.null()) {
52 Int32 max_pending = 0;
53 if (!builtInGetValue(max_pending, max_pending_str))
54 m_exchanger_option.setMaxPendingMessage(max_pending);
57 String use_collective_str = platform::getEnvironmentVariable(
"ARCANE_MESH_EXCHANGE_USE_COLLECTIVE");
58 if (use_collective_str ==
"1" || use_collective_str ==
"TRUE")
59 m_exchanger_option.setExchangeMode(ParallelExchangerOptions::EM_Collective);
61 m_exchanger_option.setVerbosityLevel(1);
70 for (IItemFamilyExchanger* exchanger : m_family_exchangers)
83 if (!m_mesh->itemFamilyNetwork() || !IItemFamilyNetwork::plug_serializer) {
88 UniqueArray<IItemFamily*> sorted_families;
90 sorted_families.reserve(families.count());
91 sorted_families.add(m_mesh->cellFamily());
92 sorted_families.add(m_mesh->faceFamily());
93 sorted_families.add(m_mesh->edgeFamily());
94 sorted_families.add(m_mesh->nodeFamily());
95 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);
112 if (m_mesh->useMeshItemFamilyDependencies()) {
113 _buildWithItemFamilyNetwork();
116 std::set<String> family_set;
117 UniqueArray<IItemFamily*> sorted_families;
119 sorted_families.reserve(families.count());
120 sorted_families.add(m_mesh->cellFamily());
121 family_set.insert(m_mesh->cellFamily()->name());
122 sorted_families.add(m_mesh->faceFamily());
123 family_set.insert(m_mesh->faceFamily()->name());
124 sorted_families.add(m_mesh->edgeFamily());
125 family_set.insert(m_mesh->edgeFamily()->name());
126 sorted_families.add(m_mesh->nodeFamily());
127 family_set.insert(m_mesh->nodeFamily()->name());
128 for (IItemFamily* family : families) {
129 IParticleFamily* particle_family = family->toParticleFamily();
130 if (particle_family) {
131 sorted_families.add(family);
132 family_set.insert(family->name());
136 for (
auto family : m_mesh->itemFamilyNetwork()->getFamilies(IItemFamilyNetwork::InverseTopologicalOrder)) {
137 auto value = family_set.insert(family->name());
139 sorted_families.add(family);
148 std::map<IItemFamily*, IItemFamilyExchanger*> family_exchanger_map;
149 for (IItemFamily* family : sorted_families) {
150 _addItemFamilyExchanger(family);
154 m_phase = ePhase::ComputeInfos;
161_buildWithItemFamilyNetwork()
163 m_mesh->itemFamilyNetwork()->schedule([&](IItemFamily* family) {
164 _addItemFamilyExchanger(family);
166 IItemFamilyNetwork::InverseTopologicalOrder);
168 for (IItemFamily* family : m_mesh->itemFamilies()) {
169 IParticleFamily* particle_family = family->toParticleFamily();
171 _addItemFamilyExchanger(family);
179_addItemFamilyExchanger(IItemFamily* family)
181 IItemFamilyExchanger* exchanger = family->policyMng()->createExchanger();
182 m_family_exchangers.add(exchanger);
183 m_family_exchanger_map.insert(std::make_pair(family, exchanger));
184 exchanger->setParallelExchangerOption(m_exchanger_option);
191_checkPhase(ePhase wanted_phase)
193 if (m_phase != wanted_phase)
194 ARCANE_FATAL(
"Invalid exchange phase wanted={0} current={1}",
195 (
int)wanted_phase, (
int)m_phase);
202computeExchangeInfos()
204 _checkPhase(ePhase::ComputeInfos);
211 Timer::Action ts_action1(m_time_stats,
"MeshExchangeComputeInfos",
true);
224 pwarning() <<
"No load balance is performed";
231 if (exchanger == cell_exchanger)
234 info() <<
"ComputeExchange family=" << family->
name()
244 exchanger->computeExchangeItems();
246 exchanger->setExchangeItems(mesh_exchange.
getItemsToSend(family));
247 exchanger->computeExchangeInfos();
260 Int32 rank = m_mesh->meshPartInfo().partRank();
266 Integer new_owner = owners[item];
272 m_phase = ePhase::ProcessExchange;
283 _checkPhase(ePhase::ProcessExchange);
288 Timer::Action ts_action1(m_time_stats,
"MessagesExchange",
true);
293 e->processExchange();
296 m_phase = ePhase::RemoveItems;
305 _checkPhase(ePhase::RemoveItems);
318 Timer::Action ts_action1(m_time_stats,
"RemoveSendedItems",
true);
323 exchanger->removeSentItems();
327 m_mesh->modifier()->_modifierInternalApi()->removeNeedRemoveMarkedItems();
329 m_phase = ePhase::AllocateItems;
336allocateReceivedItems()
338 _checkPhase(ePhase::AllocateItems);
341 Timer::Action ts_action1(m_time_stats,
"ReadAndAllocItems",
true);
346 e->readAndAllocItems();
349 auto* family_serializer_mng = m_mesh->_internalApi()->familySerializerMng();
350 if (family_serializer_mng)
351 family_serializer_mng->finalizeItemAllocation();
355 if (m_mesh->itemFamilyNetwork() && m_mesh->itemFamilyNetwork()->isActivated()) {
356 auto family_set = m_mesh->itemFamilyNetwork()->getFamilies();
357 for (
auto family : family_set) {
358 m_family_exchanger_map[family]->readAndAllocItemRelations();
364 e->readAndAllocSubMeshItems();
372 e->itemFamily()->notifyItemsOwnerChanged();
375 m_phase = ePhase::UpdateItemGroups;
384 _checkPhase(ePhase::UpdateItemGroups);
391 m_phase = ePhase::UpdateVariables;
400 _checkPhase(ePhase::UpdateVariables);
409 m_phase = ePhase::Finalize;
418 _checkPhase(ePhase::Finalize);
428 e->finalizeExchange();
430 m_phase = ePhase::Ended;
439 auto x = m_family_exchanger_map.find(family);
440 if (x == m_family_exchanger_map.end())
458_setNextPhase(ePhase next_phase)
460 m_phase = next_phase;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Exchange of entities and their characteristics for a given family.
virtual bool computeExchangeInfos()=0
Determines the information necessary for the exchanges.
virtual void setExchangeItems(ConstArrayView< std::set< Int32 > > items_to_send)=0
Positions the list of entities to exchange.
Interface of an entity family.
virtual IParticleFamily * toParticleFamily()=0
Returns the interface of the particle family for this family.
virtual ItemGroup allItems() const =0
Group of all entities.
virtual String name() const =0
Family name.
virtual void notifyItemsOwnerChanged()=0
Notifies that the entities specific to the family's subdomain have been modified.
virtual VariableItemInt32 & itemsNewOwner()=0
Variable containing the number of the new subdomain owning the entity.
virtual IPrimaryMesh * toPrimaryMesh()=0
Returns the instance in the form of an IPrimaryMesh.
Interface of a particle family.
virtual bool getEnableGhostItems() const =0
Retrieves the flag to manage ghost particles for the family.
virtual IItemFamily * itemFamily()=0
Interface on the family.
Base class for a mesh element.
impl::MutableItemBase mutableItemBase() const
Mutable internal part of the entity.
void setOwner(Integer suid, Int32 current_sub_domain)
Sets the sub-domain number of the entity owner.
Positions the name of the currently executing action.
TraceMessage info() const
Flow for an information message.
TraceMessage pwarning() const
Exchange of mesh entities between subdomains.
ConstArrayView< std::set< Int32 > > getItemsToSend(IItemFamily *family) const
List of entities to send by subdomain for the family family.
void computeInfos()
Compute the info.
IItemFamilyExchanger * findExchanger(IItemFamily *family) override
Exchanger associated with the family. Throws an exception if not found.
ItemVariableScalarRefT< Int32 > VariableItemInt32
32-bit integer type quantity
Int32 Integer
Type representing an integer.
Collection< IItemFamily * > IItemFamilyCollection
Collection of item families.
std::int32_t Int32
Signed integer type of 32 bits.