14#include "arcane/mesh/ItemsExchangeInfo2.h"
16#include "arcane/utils/NotSupportedException.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/ValueConvert.h"
20#include "arcane/core/IMesh.h"
21#include "arcane/core/VariableTypes.h"
24#include "arcane/core/ISubDomain.h"
25#include "arcane/core/IParticleFamily.h"
26#include "arcane/core/IParallelMng.h"
27#include "arcane/core/ItemPrinter.h"
28#include "arcane/core/IParallelExchanger.h"
29#include "arcane/core/ISerializer.h"
30#include "arcane/core/ISerializeMessage.h"
31#include "arcane/core/SerializeBuffer.h"
32#include "arcane/core/MeshToMeshTransposer.h"
33#include "arcane/core/IItemFamilyPolicyMng.h"
34#include "arcane/core/IItemFamilySerializer.h"
35#include "arcane/core/ItemFamilySerializeArgs.h"
36#include "arcane/core/ParallelMngUtils.h"
37#include "arcane/core/internal/IItemFamilyInternal.h"
39#include "arcane/mesh/ItemGroupsSerializer2.h"
40#include "arcane/mesh/TiedInterfaceExchanger.h"
41#include "arcane/mesh/ItemFamilyVariableSerializer.h"
44#include "arcane/mesh/DynamicMesh.h"
45#include "arcane/mesh/DynamicMeshIncrementalBuilder.h"
47#include "arcane/IVariableAccessor.h"
54class ItemFamilyExchange;
64 const Integer GROUPS_MAGIC_NUMBER = 0x3a9e4325;
70ItemsExchangeInfo2(IItemFamily* item_family)
71: TraceAccessor(item_family->traceMng())
72, m_item_family(item_family)
73, m_groups_serializers()
75, m_family_serializer(nullptr)
80 m_exchanger->setName(item_family->name());
83 addSerializeStep(
new ItemFamilyVariableSerializer(item_family));
92 for (IItemFamilySerializeStep* step : m_serialize_steps)
94 delete m_family_serializer;
95 for (Integer i = 0; i < m_groups_serializers.size(); ++i)
96 delete m_groups_serializers[i];
102inline void ItemsExchangeInfo2::
103_addItemToSend(Int32 sub_domain_id, Item item)
105 if (m_send_local_ids[sub_domain_id].empty())
108 m_exchanger->addSender(sub_domain_id);
109 m_send_local_ids[sub_domain_id].add(item.localId());
115bool ItemsExchangeInfo2::
116computeExchangeInfos()
131 if (current_family->hasUniqueIdMap())
140 bool r = m_exchanger->initializeCommunicationsMessages();
148void ItemsExchangeInfo2::
151 Int32 nb_part = m_item_family->mesh()->meshPartInfo().nbPart();
154 for (
Integer i = 0, is = items_to_send.size(); i < is; ++i) {
155 Int64 n = items_to_send[i].size();
157 m_exchanger->addSender(i);
159 std::set<Int32>::const_iterator iids = items_to_send[i].begin();
160 std::set<Int32>::const_iterator ids_end = items_to_send[i].end();
162 for (; iids != ids_end; ++iids) {
183void ItemsExchangeInfo2::
184computeExchangeItems()
187 ARCANE_FATAL(
"This call is only valid for ParticleFamily. family={0}",
190 Int32 nb_part = m_item_family->mesh()->meshPartInfo().nbPart();
204 Int32 new_owner = items_owner[item];
206 if (item.
isOwn() && new_owner != current_owner) {
207 _addItemToSend(new_owner, item);
215void ItemsExchangeInfo2::
218 info(4) <<
"ItemsExchangeInfo2::prepareToSend() for " <<
itemFamily()->name();
224 if (groups_serializer->itemFamily() ==
itemFamily()) {
233 Int32Array& current_subitem_lids = subitems_to_send[i_dest];
235 if (iitem.localId() != NULL_ITEM_LOCAL_ID)
236 current_subitem_lids.
add(iitem.localId());
238 groups_serializer->prepareData(subitems_to_send);
246 const Integer nb_send = m_exchanger->nbSender();
253 for (
Integer i = 0; i < nb_send; ++i) {
258 info(5) <<
"Processing message to " << dest_sub_domain
259 <<
" for family " <<
itemFamily()->fullName();
266 sbuf->
setMode(ISerializer::ModeReserve);
269 m_family_serializer->serializeItems(sbuf, dest_items_local_id);
270 m_family_serializer->serializeItemRelations(sbuf, dest_items_local_id);
276 Integer sub_dest_item_count = 0;
278 Int32 lid = iitem.localId();
279 if (lid != NULL_ITEM_LOCAL_ID)
280 ++sub_dest_item_count;
286 _applySerializeStep(IItemFamilySerializeStep::PH_Item, serialize_args);
288 sbuf->reserveInteger(1);
294 _applySerializeStep(IItemFamilySerializeStep::PH_Group, serialize_args);
299 _applySerializeStep(IItemFamilySerializeStep::PH_Variable, serialize_args);
306 m_family_serializer->serializeItems(sbuf, dest_items_local_id);
307 m_family_serializer->serializeItemRelations(sbuf, dest_items_local_id);
316 Int32 lid = iitem.localId();
317 if (lid != NULL_ITEM_LOCAL_ID)
318 sub_dest_uids.
add(iitem->uniqueId());
324 _applySerializeStep(IItemFamilySerializeStep::PH_Item, serialize_args);
326 sbuf->
put(GROUPS_MAGIC_NUMBER);
332 _applySerializeStep(IItemFamilySerializeStep::PH_Group, serialize_args);
335 _applySerializeStep(IItemFamilySerializeStep::PH_Variable, serialize_args);
345void ItemsExchangeInfo2::
348 for (
Integer i = 0, is = m_exchanger->senderRanks().size(); i < is; ++i) {
355 sbuf->releaseBuffer();
362void ItemsExchangeInfo2::
365 info(4) <<
"ItemsExchangeInfo2::readAndAllocItems() " <<
itemFamily()->name();
371 for (
Integer i = 0, is = m_exchanger->nbReceiver(); i < is; ++i) {
375 <<
" for family " <<
itemFamily()->fullName();
383void ItemsExchangeInfo2::
384readAndAllocSubMeshItems()
387 for (
Integer i = 0, is = m_exchanger->nbReceiver(); i < is; ++i) {
394 sub_dest_uids.
resize(sub_dest_item_count);
397 itemFamily()->itemsUniqueIdToLocalId(parent_sub_dest_lids, sub_dest_uids,
true);
398 ItemVectorView parent_sub_dest_items(itemFamily()->view(parent_sub_dest_lids));
402 dn->incrementalBuilder()->
addParentItems(parent_sub_dest_items, child_family->itemKind());
406 _applyDeserializePhase(IItemFamilySerializeStep::PH_Item);
412void ItemsExchangeInfo2::
413readAndAllocItemRelations()
415 info(4) <<
"ItemsExchangeInfo2::readAndAllocItemRelations() " << itemFamily()->name();
421 for (Integer i = 0, is = m_exchanger->nbReceiver(); i < is; ++i) {
422 ISerializeMessage* comm = m_exchanger->messageToReceive(i);
423 ISerializer* sbuf = comm->serializer();
424 info(5) <<
"Processing item message from " << comm->destination()
425 <<
" for family " << itemFamily()->fullName();
426 m_family_serializer->deserializeItemRelations(sbuf, &m_receive_local_ids[i]);
433void ItemsExchangeInfo2::
436 info(4) <<
"ItemsExchangeInfo2::readGroups() for "
437 << m_item_family->name();
442 for (
Integer i = 0, is = m_exchanger->nbReceiver(); i < is; ++i) {
447 <<
" for family " <<
itemFamily()->fullName();
451 if (magic_number != GROUPS_MAGIC_NUMBER)
452 ARCANE_FATAL(
"Internal error: bad magic number expected={0} found={1}",
453 GROUPS_MAGIC_NUMBER, magic_number);
460 _applyDeserializePhase(IItemFamilySerializeStep::PH_Group);
466void ItemsExchangeInfo2::
469 info(4) <<
"ItemsExchangeInfo2::readVariables() for " << m_item_family->name();
476 family->_internalApi()->resizeVariables(
true);
478 _applyDeserializePhase(IItemFamilySerializeStep::PH_Variable);
484void ItemsExchangeInfo2::
491 ARCANE_FATAL(
"This call is only valid for ParticleFamily. family={0}",
494 ARCANE_FATAL(
"This call is only valid for ParticleFamily without ghost",
497 info(4) <<
"ItemsExchangeInfo2::removeSentItems(): " << family->
name();
499 for (
Integer i = 0, is = m_exchanger->nbSender(); i < is; ++i) {
512 child_pfamily->removeParticles(sub_dest_items.
view().
localIds());
513 child_family->endUpdate();
515 pfamily->removeParticles(dest_items_local_id);
523void ItemsExchangeInfo2::
526 m_exchanger->processExchange(m_exchanger_option);
532void ItemsExchangeInfo2::
543void ItemsExchangeInfo2::
546 m_serialize_steps.add(step);
552void ItemsExchangeInfo2::
556 if (step->
phase() == phase)
564void ItemsExchangeInfo2::
565_applyDeserializePhase(IItemFamilySerializeStep::ePhase phase)
567 for (IItemFamilySerializeStep* step : m_serialize_steps) {
568 if (step->
phase() != phase)
571 Integer nb_receive = m_exchanger->nbReceiver();
573 auto action = IItemFamilySerializeStep::eAction::AC_BeginReceive;
574 step->
notifyAction(IItemFamilySerializeStep::NotifyActionArgs(action, nb_receive));
576 for (Integer i = 0; i < nb_receive; ++i) {
577 ISerializeMessage* comm = m_exchanger->messageToReceive(i);
578 ISerializer* sbuf = comm->serializer();
580 ItemFamilySerializeArgs serialize_args(sbuf, comm->destination().value(), local_ids, i);
584 auto action = IItemFamilySerializeStep::eAction::AC_EndReceive;
585 step->
notifyAction(IItemFamilySerializeStep::NotifyActionArgs(action, nb_receive));
593void ItemsExchangeInfo2::
596 m_exchanger_option = option;
#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.
Integer size() const
Number of elements in the vector.
void resize(Int64 s)
Changes the number of elements in the array to s.
void add(ConstReferenceType val)
Adds element val to the end of the array.
void reserve(Int64 new_capacity)
Reserves memory for new_capacity elements.
Constant view of an array of type T.
Interface for a step in the serialization of entity families.
virtual void notifyAction(const NotifyActionArgs &args)=0
Notifies the instance that we are entering a certain phase of the exchange.
ePhase
Serialization phase.
virtual ePhase phase() const =0
Serialization phase where this instance is involved.
@ AC_EndPrepareSend
End of send preparation.
@ AC_BeginPrepareSend
Start of send preparation.
virtual void serialize(const ItemFamilySerializeArgs &args)=0
Serializes into/from buf.
Interface of an entity family.
virtual IParticleFamily * toParticleFamily()=0
Returns the interface of the particle family for this family.
virtual String name() const =0
Family name.
virtual ItemVectorView view(Int32ConstArrayView local_ids)=0
View on the entities.
virtual void endUpdate()=0
Notifies the end of modification of the entity list.
Interface of a particle family.
virtual bool getEnableGhostItems() const =0
Retrieves the flag to manage ghost particles for the family.
void reserveInt64(Int64 n)
Reserve for n Int64.
virtual Integer getInteger()=0
Retrieve a size.
@ ModePut
The serializer expects reserve().
virtual Int64 getInt64()=0
Retrieve a size.
virtual void allocateBuffer()=0
Allocates the serializer memory.
virtual void put(Span< const Real > values)=0
Add the array values.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
virtual void setMode(eMode new_mode)=0
Sets the current mode.
virtual void putInt64(Int64 value)=0
Add the integer value.
Arguments for the serialization callbacks of entity families.
View of a list to obtain information about entities.
View on a vector of entities.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
ItemVectorView view() const
View of the vector.
Int32 size() const
Number of elements in the vector.
Base class for a mesh element.
Int32 owner() const
Owner subdomain number of the entity.
constexpr bool isOwn() const
true if the entity belongs to the subdomain
static ItemVector transpose(IMesh *meshA, IMesh *meshB, ItemVectorView itemsA, bool do_fatal=false)
Transpose itemsA from meshB to items on meshB.
Interface for a serialization message between IMessagePassingMng.
virtual MessageRank destination() const =0
Destination rank (if isSend() is true) or sender.
virtual ISerializer * serializer()=0
Serializer.
Int32 value() const
Rank value.
Options for IParallelMng::processExchange().
Int32 verbosityLevel() const
Verbosity level.
void setVerbosityLevel(Int32 v)
Sets the verbosity level.
Implementation of a buffer for serialization.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
void addParentItems(const ItemVectorView &items, const eItemKind submesh_kind)
Add to the current mesh items coming from a parent mesh.
Implementation of a mesh.
Serializes the entities of the groups.
UniqueArray< ItemGroupsSerializer2 * > m_groups_serializers
Serializer of groups.
UniqueArray< SharedArray< Int32 > > m_receive_local_ids
List of local IDs of received entities.
UniqueArray< IItemFamily * > m_families_to_exchange
List of families included in the exchange.
IItemFamily * itemFamily() override
Associated family.
UniqueArray< SharedArray< Int32 > > m_send_local_ids
List of entities to send to each processor.
ItemVariableScalarRefT< Int32 > VariableItemInt32
32-bit integer type quantity
Ref< IParallelExchanger > createExchangerRef(IParallelMng *pm)
Returns an interface to transfer messages between ranks.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
UniqueArray< Int64 > Int64UniqueArray
Dynamic 1D array of 64-bit integers.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
@ Int64
64-bit integer data type
Collection< IItemFamily * > IItemFamilyCollection
Collection of item families.
@ IK_Particle
Particle mesh entity.
ARCCORE_SERIALIZE_EXPORT Ref< ISerializer > createSerializer()
Creates an instance of ISerializer.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
UniqueArray< Integer > IntegerUniqueArray
Dynamic 1D array of integers.
std::int32_t Int32
Signed integer type of 32 bits.