14#include "arcane/utils/String.h"
15#include "arcane/utils/ITraceMng.h"
16#include "arcane/utils/CheckedConvert.h"
17#include "arcane/utils/FatalErrorException.h"
19#include "arcane/core/IMesh.h"
20#include "arcane/core/IParallelMng.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/Item.h"
24#include "arcane/core/IParallelExchanger.h"
25#include "arcane/core/ISerializer.h"
26#include "arcane/core/ItemFamilySerializeArgs.h"
28#include "arcane/mesh/ItemGroupsSerializer2.h"
42ItemGroupsSerializer2::
43ItemGroupsSerializer2(IItemFamily* item_family,IParallelExchanger* exchanger)
44: TraceAccessor(item_family->traceMng())
45, m_exchanger(exchanger)
46, m_mesh(item_family->mesh())
47, m_item_family(item_family)
53 std::map<String,ItemGroup> group_set;
55 for( ItemGroupCollection::Enumerator i_group(itemFamily()->groups()); ++i_group; ){
56 ItemGroup group = *i_group;
57 if (group.internal()->needSynchronization()){
58 group_set.insert(std::make_pair(group.name(),group));
62 for(
const auto& iter : group_set ){
63 const ItemGroup& group = iter.second;
64 m_groups_to_exchange.add(group);
71ItemGroupsSerializer2::
72~ItemGroupsSerializer2()
79void ItemGroupsSerializer2::
80serialize(
const ItemFamilySerializeArgs& args)
82 ISerializer* sbuf = args.serializer();
83 Int32 rank = args.rank();
86 case ISerializer::ModeReserve:
87 sbuf->reserveInt64(1);
88 sbuf->reserveSpan(eBasicDataType::Int64,m_items_to_send[rank].size());
90 case ISerializer::ModePut:
91 sbuf->putInt64(m_items_to_send[rank].size());
92 sbuf->putSpan(m_items_to_send[rank]);
94 case ISerializer::ModeGet:
95 ARCANE_FATAL(
"Do no call this method for deserialization. Use method get()");
102void ItemGroupsSerializer2::
103get(ISerializer* sbuf,Int64Array& items_in_groups_uid)
106 Int64 nb_item_in_groups = sbuf->getInt64();
107 items_in_groups_uid.resize(nb_item_in_groups);
108 sbuf->getSpan(items_in_groups_uid);
110 info(4) <<
"Receiving groups family=" << itemFamily()->fullName()
111 <<
" n=" << nb_item_in_groups <<
" entities";
114 UniqueArray<Int32> items_in_group_local_id;
115 [[maybe_unused]]
Int32 group_index = 0;
116 for( ItemGroupList::Enumerator i_group(m_groups_to_exchange); ++i_group; ++group_index ){
117 ItemGroup group = *i_group;
119 Integer nb_item_in_group = CheckedConvert::toInteger(items_in_groups_uid[local_index]);
121 if (nb_item_in_group!=0){
122 Int64ArrayView items_in_group(nb_item_in_group,&items_in_groups_uid[local_index]);
124 info() <<
"Unserialize group " << group.name() <<
" index=" << group_index <<
" nb item " << nb_item_in_group;
125 for( Integer z=0; z<nb_item_in_group; ++z ){
126 info() <<
"UID = " << items_in_group[z];
129 items_in_group_local_id.resize(nb_item_in_group);
130 itemFamily()->itemsUniqueIdToLocalId(items_in_group_local_id,items_in_group);
131 group.addItems(items_in_group_local_id);
133 local_index += nb_item_in_group;
140void ItemGroupsSerializer2::
141prepareData(ConstArrayView< SharedArray<Int32> > items_exchange)
143 IParallelMng* pm = m_mesh->parallelMng();
149 Integer nb_group = m_groups_to_exchange.count();
150 Integer total_nb_group = pm->
reduce(Parallel::ReduceMax,nb_group);
151 if (nb_group!=total_nb_group){
152 for( ItemGroupList::Enumerator i_group(m_groups_to_exchange); ++i_group; ){
153 ItemGroup group = *i_group;
154 info() <<
"Group: " << group.name();
156 fatal() <<
"Number of groups different between subdomains"
157 <<
" family=" << itemFamily()->fullName()
158 <<
" current=" << nb_group
159 <<
" max=" << total_nb_group;
166 m_items_to_send.resize(nb_sub_domain);
167 UniqueArray<Integer> first_items_to_send(m_items_to_send.size());
168 first_items_to_send.fill(0);
170 UniqueArray<bool> items_in_exchange(itemFamily()->maxLocalId());
173 for( Integer i=0, is=send_sub_domains.size(); i<is; ++i ){
174 Integer dest_sub_domain = send_sub_domains[i];
175 items_in_exchange.fill(
false);
177 for( Integer z=0, zs=items_exchange_lid.size(); z<zs; ++ z)
178 items_in_exchange[items_exchange_lid[z]] =
true;
180 for( ItemGroupList::Enumerator i_group(m_groups_to_exchange); ++i_group; ){
181 ItemGroup group = *i_group;
182 info(4) <<
"Serialize group " << group.name();
183 first_items_to_send[dest_sub_domain] = m_items_to_send[dest_sub_domain].size();
184 m_items_to_send[dest_sub_domain].add(NULL_ITEM_ID);
189 if (items_in_exchange[iitem.itemLocalId()])
190 m_items_to_send[dest_sub_domain].add((*iitem).uniqueId().asInt64());
193 Integer first_item = first_items_to_send[dest_sub_domain];
194 Integer last_item = m_items_to_send[dest_sub_domain].size()-1;
195 info(5) <<
"Serialize for subdomain " << dest_sub_domain
196 <<
" first " << first_item <<
" last " << last_item;
197 m_items_to_send[dest_sub_domain][first_item] = last_item-first_item;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
virtual Int32 commSize() const =0
Nombre d'instance dans le communicateur.
virtual char reduce(eReduceType rt, char v)=0
Effectue la réduction de type rt sur le réel v et retourne la valeur.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
ArrayView< Int64 > Int64ArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Int32 Integer
Type représentant un entier.