14#include "arcane/utils/ArcanePrecomp.h"
15#include "arcane/utils/String.h"
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/CheckedConvert.h"
18#include "arcane/utils/FatalErrorException.h"
20#include "arcane/IMesh.h"
21#include "arcane/IParallelMng.h"
22#include "arcane/ItemEnumerator.h"
23#include "arcane/IItemFamily.h"
24#include "arcane/Item.h"
25#include "arcane/IParallelExchanger.h"
26#include "arcane/ISerializer.h"
27#include "arcane/ItemFamilySerializeArgs.h"
29#include "arcane/mesh/ItemGroupsSerializer2.h"
43ItemGroupsSerializer2::
44ItemGroupsSerializer2(IItemFamily* item_family,IParallelExchanger* exchanger)
45: TraceAccessor(item_family->traceMng())
46, m_exchanger(exchanger)
47, m_mesh(item_family->mesh())
48, m_item_family(item_family)
54 std::map<String,ItemGroup> group_set;
56 for( ItemGroupCollection::Enumerator i_group(itemFamily()->groups()); ++i_group; ){
57 ItemGroup group = *i_group;
58 if (group.internal()->needSynchronization()){
59 group_set.insert(std::make_pair(group.name(),group));
63 for(
const auto& iter : group_set ){
64 const ItemGroup& group = iter.second;
65 m_groups_to_exchange.add(group);
72ItemGroupsSerializer2::
73~ItemGroupsSerializer2()
80void ItemGroupsSerializer2::
81serialize(
const ItemFamilySerializeArgs& args)
83 ISerializer* sbuf = args.serializer();
84 Int32 rank = args.rank();
87 case ISerializer::ModeReserve:
88 sbuf->reserve(DT_Int64,1);
89 sbuf->reserveSpan(DT_Int64,m_items_to_send[rank].size());
91 case ISerializer::ModePut:
92 sbuf->putInt64(m_items_to_send[rank].size());
93 sbuf->putSpan(m_items_to_send[rank]);
95 case ISerializer::ModeGet:
96 ARCANE_FATAL(
"Do no call this method for deserialization. Use method get()");
103void ItemGroupsSerializer2::
104get(ISerializer* sbuf,Int64Array& items_in_groups_uid)
107 Int64 nb_item_in_groups = sbuf->getInt64();
108 items_in_groups_uid.resize(nb_item_in_groups);
109 sbuf->getSpan(items_in_groups_uid);
111 info(4) <<
"Receiving groups family=" << itemFamily()->fullName()
112 <<
" n=" << nb_item_in_groups <<
" entities";
115 UniqueArray<Int32> items_in_group_local_id;
116 [[maybe_unused]]
Int32 group_index = 0;
117 for( ItemGroupList::Enumerator i_group(m_groups_to_exchange); ++i_group; ++group_index ){
118 ItemGroup group = *i_group;
120 Integer nb_item_in_group = CheckedConvert::toInteger(items_in_groups_uid[local_index]);
122 if (nb_item_in_group!=0){
123 Int64ArrayView items_in_group(nb_item_in_group,&items_in_groups_uid[local_index]);
125 info() <<
"Unserialize group " << group.name() <<
" index=" << group_index <<
" nb item " << nb_item_in_group;
126 for( Integer z=0; z<nb_item_in_group; ++z ){
127 info() <<
"UID = " << items_in_group[z];
130 items_in_group_local_id.resize(nb_item_in_group);
131 itemFamily()->itemsUniqueIdToLocalId(items_in_group_local_id,items_in_group);
132 group.addItems(items_in_group_local_id);
134 local_index += nb_item_in_group;
141void ItemGroupsSerializer2::
142prepareData(ConstArrayView< SharedArray<Int32> > items_exchange)
144 IParallelMng* pm = m_mesh->parallelMng();
150 Integer nb_group = m_groups_to_exchange.count();
151 Integer total_nb_group = pm->
reduce(Parallel::ReduceMax,nb_group);
152 if (nb_group!=total_nb_group){
153 for( ItemGroupList::Enumerator i_group(m_groups_to_exchange); ++i_group; ){
154 ItemGroup group = *i_group;
155 info() <<
"Group: " << group.name();
157 fatal() <<
"Number of groups different between subdomains"
158 <<
" family=" << itemFamily()->fullName()
159 <<
" current=" << nb_group
160 <<
" max=" << total_nb_group;
167 m_items_to_send.resize(nb_sub_domain);
168 UniqueArray<Integer> first_items_to_send(m_items_to_send.size());
169 first_items_to_send.fill(0);
171 UniqueArray<bool> items_in_exchange(itemFamily()->maxLocalId());
174 for( Integer i=0, is=send_sub_domains.size(); i<is; ++i ){
175 Integer dest_sub_domain = send_sub_domains[i];
176 items_in_exchange.fill(
false);
178 for( Integer z=0, zs=items_exchange_lid.size(); z<zs; ++ z)
179 items_in_exchange[items_exchange_lid[z]] =
true;
181 for( ItemGroupList::Enumerator i_group(m_groups_to_exchange); ++i_group; ){
182 ItemGroup group = *i_group;
183 info(4) <<
"Serialize group " << group.name();
184 first_items_to_send[dest_sub_domain] = m_items_to_send[dest_sub_domain].size();
185 m_items_to_send[dest_sub_domain].add(NULL_ITEM_ID);
190 if (items_in_exchange[iitem.itemLocalId()])
191 m_items_to_send[dest_sub_domain].add((*iitem).uniqueId().asInt64());
194 Integer first_item = first_items_to_send[dest_sub_domain];
195 Integer last_item = m_items_to_send[dest_sub_domain].size()-1;
196 info(5) <<
"Serialize for subdomain " << dest_sub_domain
197 <<
" first " << first_item <<
" last " << last_item;
198 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.