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;
64const 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)
77 m_family_serializer = item_family->policyMng()->createSerializer();
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()
121 m_families_to_exchange.add(itemFamily());
140 bool r = m_exchanger->initializeCommunicationsMessages();
141 m_receive_local_ids.resize(m_exchanger->nbReceiver());
148void ItemsExchangeInfo2::
151 Int32
nb_part = m_item_family->mesh()->meshPartInfo().nbPart();
152 m_send_local_ids.resize(
nb_part);
157 m_exchanger->addSender(i);
163 m_send_local_ids[i].add(*
iids);
184void ItemsExchangeInfo2::
185computeExchangeItems()
188 ARCANE_FATAL(
"This call is only valid for ParticleFamily. family={0}",
189 itemFamily()->name());
191 Int32
nb_part = m_item_family->mesh()->meshPartInfo().nbPart();
193 m_send_local_ids.resize(
nb_part);
216void ItemsExchangeInfo2::
219 info(4) <<
"ItemsExchangeInfo2::prepareToSend() for " << itemFamily()->name();
220 info(4) <<
"Number of groups to serialize: " << m_groups_serializers.size();
236 if (
iitem.localId() != NULL_ITEM_LOCAL_ID)
247 const Integer
nb_send = m_exchanger->nbSender();
249 auto action = IItemFamilySerializeStep::eAction::AC_BeginPrepareSend;
254 for( Integer i=0; i<
nb_send; ++i ){
260 <<
" for family " << itemFamily()->fullName();
267 sbuf->setMode(ISerializer::ModeReserve);
280 if (
lid != NULL_ITEM_LOCAL_ID)
287 _applySerializeStep(IItemFamilySerializeStep::PH_Item,
serialize_args);
289 sbuf->reserveInteger(1);
295 _applySerializeStep(IItemFamilySerializeStep::PH_Group,
serialize_args);
300 _applySerializeStep(IItemFamilySerializeStep::PH_Variable,
serialize_args);
302 sbuf->allocateBuffer();
305 sbuf->setMode(ISerializer::ModePut);
318 if (
lid != NULL_ITEM_LOCAL_ID)
325 _applySerializeStep(IItemFamilySerializeStep::PH_Item,
serialize_args);
333 _applySerializeStep(IItemFamilySerializeStep::PH_Group,
serialize_args);
336 _applySerializeStep(IItemFamilySerializeStep::PH_Variable,
serialize_args);
340 auto action = IItemFamilySerializeStep::eAction::AC_EndPrepareSend;
346void ItemsExchangeInfo2::
349 for( Integer i=0, is=m_exchanger->senderRanks().size(); i<is; ++i ) {
356 sbuf->releaseBuffer();
363void ItemsExchangeInfo2::
366 info(4) <<
"ItemsExchangeInfo2::readAndAllocItems() " << itemFamily()->name();
372 for( Integer i=0, is=m_exchanger->nbReceiver(); i<is; ++i ){
375 info(5) <<
"Processing item message from " <<
comm->destination()
376 <<
" for family " << itemFamily()->fullName();
377 m_family_serializer->deserializeItems(
sbuf,&m_receive_local_ids[i]);
384void ItemsExchangeInfo2::
385readAndAllocSubMeshItems()
388 for( Integer i=0, is=m_exchanger->nbReceiver(); i<is; ++i ){
407 _applyDeserializePhase(IItemFamilySerializeStep::PH_Item);
414void ItemsExchangeInfo2::
415readAndAllocItemRelations()
417 info(4) <<
"ItemsExchangeInfo2::readAndAllocItemRelations() " << itemFamily()->name();
423 for( Integer i=0, is=m_exchanger->nbReceiver(); i<is; ++i ){
424 ISerializeMessage* comm = m_exchanger->messageToReceive(i);
425 ISerializer* sbuf = comm->serializer();
426 info(5) <<
"Processing item message from " << comm->destination()
427 <<
" for family " << itemFamily()->fullName();
428 m_family_serializer->deserializeItemRelations(sbuf,&m_receive_local_ids[i]);
435void ItemsExchangeInfo2::
438 info(4) <<
"ItemsExchangeInfo2::readGroups() for "
439 << m_item_family->name();
444 for( Integer i=0, is=m_exchanger->nbReceiver(); i<is; ++i ){
448 info(4) <<
"Processing group message from " <<
comm->destination()
449 <<
" for family " << itemFamily()->fullName();
454 ARCANE_FATAL(
"Internal error: bad magic number expected={0} found={1}",
462 _applyDeserializePhase(IItemFamilySerializeStep::PH_Group);
468void ItemsExchangeInfo2::
471 info(4) <<
"ItemsExchangeInfo2::readVariables() for " << m_item_family->name();
477 for(
IItemFamily* family : m_families_to_exchange )
478 family->_internalApi()->resizeVariables(
true);
480 _applyDeserializePhase(IItemFamilySerializeStep::PH_Variable);
486void ItemsExchangeInfo2::
494 ARCANE_FATAL(
"This call is only valid for ParticleFamily. family={0}",
495 itemFamily()->name());
496 if (
pfamily->getEnableGhostItems())
497 ARCANE_FATAL(
"This call is only valid for ParticleFamily without ghost",
498 itemFamily()->name());
500 info(4) <<
"ItemsExchangeInfo2::removeSentItems(): " << family->
name();
502 for( Integer i=0, is=m_exchanger->nbSender(); i<is; ++i ){
526void ItemsExchangeInfo2::
529 m_exchanger->processExchange(m_exchanger_option);
535void ItemsExchangeInfo2::
546void ItemsExchangeInfo2::
549 m_serialize_steps.add(
step);
555void ItemsExchangeInfo2::
559 if (
step->phase()==phase)
560 step->serialize(args);
567void ItemsExchangeInfo2::
568_applyDeserializePhase(IItemFamilySerializeStep::ePhase phase)
570 for( IItemFamilySerializeStep* step : m_serialize_steps ){
571 if (step->
phase()!=phase)
574 Integer nb_receive = m_exchanger->nbReceiver();
576 auto action = IItemFamilySerializeStep::eAction::AC_BeginReceive;
577 step->
notifyAction(IItemFamilySerializeStep::NotifyActionArgs(action,nb_receive));
579 for( Integer i=0; i<nb_receive; ++i ){
580 ISerializeMessage* comm = m_exchanger->messageToReceive(i);
581 ISerializer* sbuf = comm->serializer();
583 ItemFamilySerializeArgs serialize_args(sbuf,comm->destination().value(),local_ids,i);
587 auto action = IItemFamilySerializeStep::eAction::AC_EndReceive;
588 step->
notifyAction(IItemFamilySerializeStep::NotifyActionArgs(action,nb_receive));
596void ItemsExchangeInfo2::
599 m_exchanger_option =
option;
600 m_exchanger->setVerbosityLevel(
option.verbosityLevel());
#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.
Tableau d'items de types quelconques.
Interface d'une étape de la sérialisation des familles d'entités.
virtual void notifyAction(const NotifyActionArgs &args)=0
Notifie l'instance qu'on entre dans une certaine phase de l'échange.
ePhase
Phase de la sérialisation.
virtual ePhase phase() const =0
Phase de la sérialisation où cette instance intervient.
virtual void serialize(const ItemFamilySerializeArgs &args)=0
Sérialise dans/depuis buf.
Interface d'une famille d'entités.
virtual IParticleFamily * toParticleFamily()=0
Retourne l'interface de la famille de particule de cette famille.
virtual String name() const =0
Nom de la famille.
virtual ItemVectorView view(Int32ConstArrayView local_ids)=0
Vue sur les entités.
virtual void endUpdate()=0
Notifie la fin de modification de la liste des entités.
Interface d'une famille de particules.
Arguments des callbacks de sérialisation des familles d'entités.
Sérialise les entités des groupes.
Vue sur une liste pour obtenir des informations sur les entités.
Vue sur un vecteur d'entités.
Classe de base d'un élément de maillage.
bool isOwn() const
true si l'entité est appartient au sous-domaine
Int32 owner() const
Numéro du sous-domaine propriétaire de l'entité
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Options pour IParallelMng::processExchange().
Implémentation d'un tampon pour la sérialisation.
Implémentation d'un maillage.
Vue constante d'un tableau de type T.
Interface d'un sérialiseur.
Interface d'un message de sérialisation entre IMessagePassingMng.
Vecteur 1D de données avec sémantique par valeur (style STL).
Ref< IParallelExchanger > createExchangerRef(IParallelMng *pm)
Retourne une interface pour transférer des messages entre rangs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
@ IK_Particle
Entité de maillage de genre particule.
@ DT_Int64
Donnée de type entier 64 bits.
Int32 Integer
Type représentant un entier.