14#include "arcane/utils/Iterator.h"
15#include "arcane/utils/ITraceMng.h"
16#include "arcane/utils/ScopedPtr.h"
17#include "arcane/utils/Collection.h"
19#include "arcane/IMesh.h"
20#include "arcane/ISubDomain.h"
21#include "arcane/IParallelMng.h"
22#include "arcane/IParallelExchanger.h"
23#include "arcane/IItemFamily.h"
24#include "arcane/ItemEnumerator.h"
25#include "arcane/Item.h"
26#include "arcane/MeshVariable.h"
27#include "arcane/IParticleFamily.h"
28#include "arcane/ParallelMngUtils.h"
30#include "arcane/ConnectivityItemVector.h"
31#include "arcane/IndexedItemConnectivityView.h"
32#include "arcane/mesh/IndexedItemConnectivityAccessor.h"
33#include "arcane/mesh/MeshExchange.h"
34#include "arcane/mesh/NewItemOwnerBuilder.h"
36#include "arcane/ItemPrinter.h"
37#include "arcane/IParallelMng.h"
39#include "arcane/VariableTypes.h"
41#include "arcane/IItemFamilyNetwork.h"
42#include "arcane/IGhostLayerMng.h"
43#include "arcane/ConnectivityItemVector.h"
45#include "arcane/IVariableSynchronizer.h"
63 : m_current_increment(-1), m_current_size(0), m_index(size, -1),
69 : m_current_increment(-1), m_current_size(0) {}
71 inline void resize(Integer size)
77 inline Integer size()
const
79 return m_index.
size();
82 inline void dataReserve(Integer size)
87 inline void addData(
const T data)
93 inline Int32 index(Integer
id)
const
98 inline void beginIncrement(Integer
id)
100 ARCANE_ASSERT((m_current_increment == -1),(
"call endIncrement before begin"));
101 m_current_increment = id;
103 m_index[m_current_increment] = m_data.size();
106 inline void endIncrement()
108 m_size[m_current_increment] = m_current_size;
109 m_current_increment = -1;
115 return m_data.subView(m_index[
id],m_size[
id]);
120 return m_data.subView(m_index[
id],m_size[
id]);
124 Integer m_current_increment;
125 Integer m_current_size;
144 inline void resize(Integer size) {
148 inline Integer size()
const {
149 return m_data.size();
152 inline void addData(Integer
id,
const T data) {
153 m_data[id].add(data);
174MeshExchange(
IMesh* mesh)
177, m_parallel_mng(mesh->parallelMng())
178, m_nb_rank(m_parallel_mng->commSize())
179, m_rank(m_parallel_mng->commRank())
180, m_cell_family(mesh->itemFamily(
IK_Cell))
181, m_neighbour_cells_owner(
NULL)
182, m_neighbour_cells_new_owner(
NULL)
183, m_neighbour_extra_cells_owner(
NULL)
184, m_neighbour_extra_cells_new_owner(
NULL)
194 for(
const auto&
itosend : m_items_to_send )
196 delete m_neighbour_cells_owner;
197 delete m_neighbour_cells_new_owner;
198 delete m_neighbour_extra_cells_owner;
199 delete m_neighbour_extra_cells_new_owner;
200 for(
const auto&
idestrank : m_item_dest_ranks_map)
214 auto iter = m_items_to_send.find(family);
215 if (iter==m_items_to_send.end())
217 return iter->second->constView();
227 auto iter = m_items_to_send.find(family);
228 if (iter==m_items_to_send.end())
230 return iter->second->view();
242 m_items_to_send.insert(std::make_pair(family,
new UniqueArray< std::set<Int32> >));
247 if(
m_mesh->isAmrActivated()){
249 _computeGraphConnectivityInfos();
252 _markRemovableParticles();
253 _computeItemsToSend2();
260 _computeGraphConnectivityInfos();
261 _exchangeCellDataInfos3();
262 _exchangeGhostItemDataInfos();
263 _markRemovableItems();
264 _markRemovableParticles();
265 _computeItemsToSend3();
272 _computeGraphConnectivityInfos();
274 _exchangeCellDataInfos3();
277 _markRemovableDoFs();
279 _markRemovableParticles();
280 _computeItemsToSend(
true);
286 _computeGraphConnectivityInfos();
289 _markRemovableParticles();
290 _computeItemsToSend();
298_computeGraphConnectivityInfos()
319 _addGraphConnectivityToNewConnectivityInfo();
327_addGraphConnectivityToNewConnectivityInfo()
330 Int32Array& extra_new_owners = m_neighbour_extra_cells_new_owner->at(icell.localId());
331 Int32Array& extra_owners = m_neighbour_extra_cells_owner->at(icell.localId());
332 ItemDestRankArray* item_dest_ranks =
nullptr;
334 item_dest_ranks = m_item_dest_ranks_map[m_cell_family];
336 item_dest_ranks= m_ghost_item_dest_ranks_map[icell->owner()][m_cell_family];
337 item_dest_ranks->
at(icell.localId()).addRange(extra_new_owners);
338 item_dest_ranks->at(icell.localId()).addRange(extra_owners);
341 _propagatesToChildDependencies(m_cell_family);
352 m_neighbour_cells_owner =
new IncrementalUnorderedMultiArray<Int32>(cell_variable_size);
353 m_neighbour_cells_new_owner =
new IncrementalUnorderedMultiArray<Int32>(cell_variable_size);
356 tmp_new_owner.fill(NULL_ITEM_ID);
358 tmp_owner.fill(NULL_ITEM_ID);
362 Integer cell_local_id = cell.localId();
364 tmp_owner[m_rank] = cell_local_id;
366 m_neighbour_cells_owner->beginIncrement(cell_local_id);
367 m_neighbour_cells_new_owner->beginIncrement(cell_local_id);
369 for(
NodeEnumerator inode(cell.nodes()); inode.hasNext(); ++inode ){
370 for(
CellEnumerator icell2((*inode).cells()); icell2.hasNext(); ++icell2 ){
371 Integer cell2_local_id = icell2.localId();
372 Integer cell2_new_owner = cells_new_owner[cell2_local_id];
373 Integer cell2_owner = icell2->owner();
376 if (tmp_new_owner[cell2_new_owner]!=cell_local_id){
377 tmp_new_owner[cell2_new_owner] = cell_local_id;
378 m_neighbour_cells_new_owner->addData(cell2_new_owner);
380 if (tmp_owner[cell2_owner]!=cell_local_id){
381 tmp_owner[cell2_owner] = cell_local_id;
382 m_neighbour_cells_owner->addData(cell2_owner);
386 m_neighbour_cells_owner->endIncrement();
387 m_neighbour_cells_new_owner->endIncrement();
395_exchangeCellDataInfos([[maybe_unused]]
Int32ConstArrayView cells_new_owner,
bool use_active_cells)
401 for( Integer i=0, is=recv_sub_domains.size(); i<is; ++i )
402 sd_exchange->addSender(recv_sub_domains[i]);
404 sd_exchange->initializeCommunicationsMessages(recv_sub_domains);
406 UniqueArray<Int64> cells_to_comm_uid;
407 UniqueArray<Int32> cells_to_comm_owner;
408 UniqueArray<Int32> cells_to_comm_owner_size;
409 UniqueArray<Int32> cells_to_comm_new_owner;
410 UniqueArray<Int32> cells_to_comm_new_owner_size;
412 ItemGroup own_items = m_cell_family->
allItems().own();
413 ItemGroup all_items = m_cell_family->
allItems();
415 if (use_active_cells){
416 own_items = m_cell_family->
allItems().ownActiveCellGroup();
417 all_items = m_cell_family->
allItems().activeCellGroup();
420 for( Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
421 ISerializeMessage* comm = sd_exchange->messageToSend(i);
422 Int32 dest_sub_domain = comm->destination().value();
423 ISerializer* sbuf = comm->serializer();
425 cells_to_comm_uid.clear();
426 cells_to_comm_owner.clear();
427 cells_to_comm_owner_size.clear();
428 cells_to_comm_new_owner.clear();
429 cells_to_comm_new_owner_size.clear();
433 Integer cell_local_id = cell.localId();
435 bool need_send = owners.
contains(dest_sub_domain);
438 need_send = extra_owners.
contains(dest_sub_domain);
444 const Integer nb_new_owner = new_owners.size();
445 const Integer nb_owner = owners.size();
447 Int32ConstArrayView extra_new_owner = m_neighbour_extra_cells_new_owner->at(cell_local_id);
448 const Integer nb_extra_new_owner = extra_new_owner.size();
450 cells_to_comm_uid.add(cell.uniqueId().asInt64());
451 cells_to_comm_owner_size.add(nb_owner);
452 cells_to_comm_new_owner_size.add(nb_new_owner+nb_extra_new_owner);
453 for( Integer zz=0; zz<nb_owner; ++zz )
454 cells_to_comm_owner.add(owners[zz]);
455 for( Integer zz=0; zz<nb_new_owner; ++zz )
456 cells_to_comm_new_owner.add(new_owners[zz]);
457 for( Integer zz=0; zz<nb_extra_new_owner; ++zz )
458 cells_to_comm_new_owner.add(extra_new_owner[zz]);
460 sbuf->setMode(ISerializer::ModeReserve);
463 sbuf->reserveArray(cells_to_comm_uid);
464 sbuf->reserveArray(cells_to_comm_owner_size);
465 sbuf->reserveArray(cells_to_comm_owner);
466 sbuf->reserveArray(cells_to_comm_new_owner_size);
467 sbuf->reserveArray(cells_to_comm_new_owner);
469 sbuf->allocateBuffer();
472 sbuf->putInt64(cells_to_comm_uid.size());
473 sbuf->putArray(cells_to_comm_uid);
474 sbuf->putArray(cells_to_comm_owner_size);
475 sbuf->putArray(cells_to_comm_owner);
476 sbuf->putArray(cells_to_comm_new_owner_size);
477 sbuf->putArray(cells_to_comm_new_owner);
480 sd_exchange->processExchange();
483 for( Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
484 ISerializeMessage* comm = sd_exchange->messageToReceive(i);
485 ISerializer* sbuf = comm->serializer();
488 Int64 nb_cell = sbuf->getInt64();
489 sbuf->getArray(cells_to_comm_uid);
490 sbuf->getArray(cells_to_comm_owner_size);
491 sbuf->getArray(cells_to_comm_owner);
492 sbuf->getArray(cells_to_comm_new_owner_size);
493 sbuf->getArray(cells_to_comm_new_owner);
494 cells_to_comm_local_id.resize(nb_cell);
496 for( Integer icell=0; icell<nb_cell; ++icell ){
497 Integer cell_local_id = cells_to_comm_local_id[icell];
498 Integer cell_nb_owner = cells_to_comm_owner_size[icell];
499 Integer cell_nb_new_owner = cells_to_comm_new_owner_size[icell];
501 info()<<
" cell "<<icell
502 <<
" lid=" <<cell_local_id
503 <<
" uid=" <<cells_to_comm_uid[icell]
504 <<
" ind=" <<m_neighbour_cells_owner->index(cell_local_id);
506 if (m_neighbour_cells_owner->index(cell_local_id)!=(-1))
507 fatal() <<
"Cell uid=" << cells_to_comm_uid[icell] <<
" already has neighbours 'owner'!";
508 if (m_neighbour_cells_new_owner->index(cell_local_id)!=(-1))
509 fatal() <<
"Cell uid=" << cells_to_comm_uid[icell] <<
" already has neighbours 'new_owner'!";
510 m_neighbour_cells_owner->beginIncrement(cell_local_id);
511 m_neighbour_cells_new_owner->beginIncrement(cell_local_id);
513 info()<<
" cell "<< icell
514 <<
" lid=" << cell_local_id
515 <<
" uid=" << cells_to_comm_uid[icell]
516 <<
" ind=" << m_neighbour_cells_owner->index(cell_local_id);
518 for( Integer zz=0; zz<cell_nb_owner; ++zz )
519 m_neighbour_cells_owner->addData(cells_to_comm_owner[owner_index+zz]);
520 owner_index += cell_nb_owner;
521 m_neighbour_cells_owner->endIncrement();
523 for( Integer zz=0; zz<cell_nb_new_owner; ++zz )
524 m_neighbour_cells_new_owner->addData(cells_to_comm_new_owner[new_owner_index+zz]);
525 new_owner_index += cell_nb_new_owner;
526 m_neighbour_cells_new_owner->endIncrement();
535_addItemToSend(ArrayView< std::set<Int32> > items_to_send,
537 bool use_itemfamily_network)
540 for( Integer zz=0, nb_new_owner = new_owners.size(); zz<nb_new_owner; ++zz )
541 items_to_send[new_owners[zz]].insert(local_id);
543 Int32ConstArrayView extra_new_owners = m_neighbour_extra_cells_new_owner->at(cell_local_id);
544 for( Integer zz=0, nb_extra_new_owner = extra_new_owners.size(); zz<nb_extra_new_owner; ++zz )
545 items_to_send[extra_new_owners[zz]].insert(local_id);
547 if(use_itemfamily_network)
549 Int32ConstArrayView network_new_owners = m_item_dest_ranks_map[m_cell_family]->at(cell_local_id);
550 for( Integer zz=0, nb_network_new_owner = network_new_owners.size(); zz<nb_network_new_owner; ++zz )
552 items_to_send[network_new_owners[zz]].insert(local_id);
561_computeItemsToSend(
bool send_dof)
563 for(
const auto& iter : m_items_to_send )
564 iter.second->resize(m_nb_rank);
566 IItemFamily* node_family = mesh()->
nodeFamily();
567 IItemFamily* edge_family = mesh()->
edgeFamily();
568 IItemFamily* face_family = mesh()->
faceFamily();
569 IItemFamily* cell_family = m_cell_family;
571 ArrayView<std::set<Int32>> nodes_to_send =
_getItemsToSend(node_family);
572 ArrayView<std::set<Int32>> edges_to_send =
_getItemsToSend(edge_family);
573 ArrayView<std::set<Int32>> faces_to_send =
_getItemsToSend(face_family);
574 ArrayView<std::set<Int32>> cells_to_send =
_getItemsToSend(cell_family);
580 _addItemToSend(cells_to_send,icell.itemLocalId(),icell.itemLocalId(),use_itemfamily_network);
585 Integer node_local_id = node.localId();
586 for(
CellEnumerator icell(node.cells()); icell.hasNext(); ++icell )
587 _addItemToSend(nodes_to_send,node_local_id,icell.localId(),use_itemfamily_network);
592 Integer edge_local_id = edge.localId();
593 for(
CellEnumerator icell(edge.cells()); icell.hasNext(); ++icell )
594 _addItemToSend(edges_to_send,edge_local_id,icell.localId(),use_itemfamily_network);
599 Integer face_local_id = face.localId();
600 for(
CellEnumerator icell(face.cells()); icell.hasNext(); ++icell ){
601 _addItemToSend(faces_to_send,face_local_id,icell.localId(),use_itemfamily_network);
606 for( IItemFamily* family :
m_mesh->itemFamilies())
608 IParticleFamily* particle_family = family->toParticleFamily();
609 if (particle_family && particle_family->getEnableGhostItems()==
true){
612 _addItemToSend(to_send,iparticle->localId(),iparticle->cell().localId(),use_itemfamily_network);
615 if(send_dof && family->itemKind()==
IK_DoF)
617 _setItemsToSend(family);
623 for(
const auto& iter : m_items_to_send )
624 (*(iter.second))[m_rank].clear();
626 const bool is_print =
false;
628 debug() <<
"PRINT ITEM TO SEND V1";
691 m_neighbour_cells_owner->endIncrement();
692 m_neighbour_cells_new_owner->endIncrement();
706 Cell cell(cells[local_id]);
707 if(cell.level() == 0){
730_addTreeItemToSend(
Int32 cell_local_id,CellInfoListView cells)
736 Cell cell(cells[cell_local_id]);
741 _familyTree(family,top_parent);
743 IItemFamily* node_family = mesh()->
nodeFamily();
744 IItemFamily* edge_family = mesh()->
edgeFamily();
745 IItemFamily* face_family = mesh()->
faceFamily();
747 ArrayView<std::set<Int32>> nodes_to_send =
_getItemsToSend(node_family);
748 ArrayView<std::set<Int32>> edges_to_send =
_getItemsToSend(edge_family);
749 ArrayView<std::set<Int32>> faces_to_send =
_getItemsToSend(face_family);
753 for(Integer c=0,cs=family.size();c<cs;c++)
754 for( Integer zz=0, nb_new_owner = new_owners.size(); zz<nb_new_owner; ++zz ){
755 Cell cell2 = cells[family[c]];
756 for( Node node : cell2.nodes() )
757 nodes_to_send[new_owners[zz]].insert(node.localId());
758 for( Edge edge : cell2.edges() )
759 edges_to_send[new_owners[zz]].insert(edge.localId());
760 for( Face face : cell2.faces() )
761 faces_to_send[new_owners[zz]].insert(face.localId());
769_familyTree (
Int32Array& family,Cell item,
const bool reset)
const
771 ARCANE_ASSERT((!item.itemBase().isSubactive()),(
"The family tree doesn't include subactive items"));
776 family.add(item.localId());
779 if (!item.isActive())
780 for (Integer c=0, cs=item.nbHChildren(); c<cs; c++){
781 Item ichild = item.hChild(c);
783 _familyTree (family,ichild.toCell(),
false);
791_computeItemsToSend2()
793 for(
const auto& iter : m_items_to_send )
794 iter.second->resize(m_nb_rank);
796 IItemFamily* node_family = mesh()->
nodeFamily();
797 IItemFamily* edge_family = mesh()->
edgeFamily();
798 IItemFamily* face_family = mesh()->
faceFamily();
800 ArrayView<std::set<Int32>> nodes_to_send =
_getItemsToSend(node_family);
801 ArrayView<std::set<Int32>> edges_to_send =
_getItemsToSend(edge_family);
802 ArrayView<std::set<Int32>> faces_to_send =
_getItemsToSend(face_family);
803 ArrayView<std::set<Int32>> cells_to_send =
_getItemsToSend(m_cell_family);
808 CellInfoListView cells(m_cell_family);
811 _addTreeCellToSend(cells_to_send,icell.itemLocalId(),icell.itemLocalId(),cells);
813 if(cell.level() == 0){
815 for(
NodeEnumerator inode(cell.nodes()); inode.hasNext(); ++inode ){
818 Integer node_local_id = node.localId();
819 for(
CellEnumerator icell2(node.cells()); icell2.hasNext(); ++icell2 ){
822 _addItemToSend(nodes_to_send,node_local_id,icell2.localId());
827 for(
EdgeEnumerator iedge(cell.edges()); iedge.hasNext(); ++iedge ){
830 Integer edge_local_id = edge.localId();
831 for(
CellEnumerator icell2(edge.cells()); icell2.hasNext(); ++icell2 )
832 _addItemToSend(edges_to_send,edge_local_id,icell2.localId());
839 Integer face_local_id = face.localId();
840 for(
CellEnumerator icell2(face.cells()); icell2.hasNext(); ++icell2 ){
841 _addItemToSend(faces_to_send,face_local_id,icell2.localId());
847 else if(cell.level() > 0)
848 _addTreeItemToSend(icell.itemLocalId(),cells);
851 for( IItemFamily* family :
m_mesh->itemFamilies()){
852 IParticleFamily* particle_family = family->toParticleFamily();
853 if (particle_family && particle_family->getEnableGhostItems()==
true){
856 _addItemToSend(to_send,iparticle->localId(),iparticle->cell().localId());
862 for(
const auto& iter : m_items_to_send )
863 (*(iter.second))[m_rank].clear();
893 IItemFamilyNetwork::TopologicalOrder);
908 _propagatesToChildConnectivities(family);
910 IItemFamilyNetwork::TopologicalOrder);
923_propagatesToChildConnectivities(
IItemFamily* family)
958 for( Cell cell : item->cells())
959 _addDestRank(cell,m_cell_family,*item,family);
964 for( Cell cell : item->cells() )
965 _addDestRank(cell,m_cell_family,*item,family);
970 for( Cell cell : item->cells())
971 _addDestRank(cell,m_cell_family,*item,family);
984_propagatesToChildDependencies(IItemFamily* family)
993 for (
const auto& child_dependency :child_dependencies){
996 auto accessor = IndexedItemConnectivityAccessor(child_dependency);
1000 _addDestRank(*connected_item,child_dependency->targetFamily(),*item, family);
1011_addDestRank(
const Item& item, IItemFamily* item_family,
const Integer new_owner)
1013 ItemDestRankArray* item_dest_ranks =
nullptr;
1014 if (item.owner() == m_rank) {
1015 item_dest_ranks = m_item_dest_ranks_map[item_family];
1018 item_dest_ranks= m_ghost_item_dest_ranks_map[item.owner()][item_family];
1021 auto& item_ranks_internal = item_dest_ranks->
at(item.localId());
1022 if (!item_ranks_internal.contains(new_owner))
1023 item_dest_ranks->at(item.localId()).add(new_owner);
1030_addDestRank(
const Item& item, IItemFamily* item_family,
const Item& followed_item, IItemFamily* followed_item_family)
1033 ItemDestRankArray* item_dest_ranks =
nullptr;
1034 if (item.owner() == m_rank)
1036 item_dest_ranks = m_item_dest_ranks_map[item_family];
1040 item_dest_ranks= m_ghost_item_dest_ranks_map[item.owner()][item_family];
1042 ItemDestRankArray* followed_item_dest_ranks =
nullptr;
1043 if (followed_item.owner() == m_rank)
1044 followed_item_dest_ranks = m_item_dest_ranks_map[followed_item_family];
1046 followed_item_dest_ranks= m_ghost_item_dest_ranks_map[followed_item.owner()][followed_item_family];
1048 auto& new_dest_ranks = followed_item_dest_ranks->
at(followed_item.localId());
1049 auto& current_dest_ranks = item_dest_ranks->at(item.localId());
1051 new_dest_rank_to_add.
reserve((new_dest_ranks.size()));
1052 for (
auto& new_dest_rank : new_dest_ranks){
1053 if (!current_dest_ranks.contains(new_dest_rank))
1054 new_dest_rank_to_add.add(new_dest_rank);
1056 current_dest_ranks.addRange(new_dest_rank_to_add);
1063_allocData(IItemFamily* family)
1065 m_item_dest_ranks_map[family] =
new ItemDestRankArray(family->maxLocalId());
1066 for (
auto& ghost_item_map : m_ghost_item_dest_ranks_map) {
1067 ghost_item_map[family] =
new ItemDestRankArray(family->maxLocalId());
1076 info() <<
"-ENTERING NEW EXCHANGE DEBUG PRINT";
1077 for(
auto& item_dest_ranks : m_item_dest_ranks_map){
1078 info() <<
"--PRINT NEW EXCHANGE INFO";
1079 info() <<
"---Destination rank for family " << item_dest_ranks.first->name();
1080 for (
int item_lid = 0; item_lid < item_dest_ranks.first->maxLocalId(); ++item_lid) {
1081 info() <<
"---Destination rank for item lid " << item_lid;
1082 for (
auto& item_dest_rank : item_dest_ranks.second->at(item_lid)) {
1083 info() <<
"---- Rank " << item_dest_rank;
1093_exchangeCellDataInfos3()
1100 for( Integer i=0, is=recv_sub_domains.size(); i<is; ++i )
1101 sd_exchange->addSender(recv_sub_domains[i]);
1103 sd_exchange->initializeCommunicationsMessages(recv_sub_domains);
1105 UniqueArray<IItemFamily*> item_families;
1112 for( Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
1113 ISerializeMessage* comm = sd_exchange->messageToSend(i);
1114 Int32 dest_sub_domain = comm->destination().value();
1115 ISerializer* sbuf = comm->serializer();
1116 item_families.clear();
1117 item_dest_ranks.clear();
1118 item_nb_dest_ranks.clear();
1119 family_nb_items.clear();
1121 for (
const auto& family_ghost_item_dest_ranks : m_ghost_item_dest_ranks_map[dest_sub_domain]) {
1124 item_families.add(family_ghost_item_dest_ranks.first);
1125 for (Integer item_lid = 0; item_lid < family_ghost_item_dest_ranks.second->size(); ++item_lid)
1127 if (family_ghost_item_dest_ranks.second->at(item_lid).size() == 0)
continue;
1128 item_lids.add(item_lid);
1129 item_dest_ranks.addRange(family_ghost_item_dest_ranks.second->at(item_lid));
1130 item_nb_dest_ranks.add(family_ghost_item_dest_ranks.second->at(item_lid).size());
1133 family_nb_items.add(family_nb_item);
1134 ENUMERATE_ITEM(item, family_ghost_item_dest_ranks.first->view(item_lids))
1136 item_uids.add(item->uniqueId().asInt64());
1139 sbuf->setMode(ISerializer::ModeReserve);
1141 for (
const auto& family: item_families)
1142 sbuf->reserve(family->name());
1143 sbuf->reserveInteger(item_families.size());
1144 sbuf->reserveArray(item_uids);
1145 sbuf->reserveArray(family_nb_items);
1146 sbuf->reserveArray(item_nb_dest_ranks);
1147 sbuf->reserveArray(item_dest_ranks);
1149 sbuf->allocateBuffer();
1152 sbuf->putInt64(item_families.size());
1153 for (
const auto& family: item_families)
1154 sbuf->put(family->name());
1155 for (
const auto& family: item_families)
1156 sbuf->putInteger(family->itemKind());
1157 sbuf->putArray(item_uids);
1158 sbuf->putArray(family_nb_items);
1159 sbuf->putArray(item_nb_dest_ranks);
1160 sbuf->putArray(item_dest_ranks);
1163 sd_exchange->processExchange();
1165 for( Integer i=0, n=recv_sub_domains.size(); i<n; ++i ){
1166 ISerializeMessage* comm = sd_exchange->messageToReceive(i);
1167 ISerializer* sbuf = comm->serializer();
1168 Int64 nb_families = sbuf->getInt64();
1171 for (
auto& family_name: item_family_names)
1172 sbuf->get(family_name);
1173 for (
auto& family_kind: item_family_kinds)
1174 family_kind = sbuf->getInteger();
1175 sbuf->getArray(item_uids);
1176 sbuf->getArray(family_nb_items);
1177 sbuf->getArray(item_nb_dest_ranks);
1178 sbuf->getArray(item_dest_ranks);
1180 Integer item_nb_dest_rank_index = 0;
1181 Integer item_dest_rank_index = 0;
1182 for (
int family_index = 0; family_index < nb_families; ++family_index)
1185 item_family_names[family_index],
false);
1187 item_lids.resize(family_item_uids.size());
1188 family->itemsUniqueIdToLocalId(item_lids,family_item_uids,
true);
1189 for (
const auto& item_lid : item_lids){
1190 auto sub_view = item_dest_ranks.
subView(item_dest_rank_index,item_nb_dest_ranks[item_nb_dest_rank_index]);
1191 m_item_dest_ranks_map[family]->at(item_lid).addRange(sub_view);
1192 item_dest_rank_index+= item_nb_dest_ranks[item_nb_dest_rank_index++];
1194 item_uid_index+= family_nb_items[family_index];
1199 for (
int ghost_layer_index = 0; ghost_layer_index <
m_mesh->
ghostLayerMng()->nbGhostLayer(); ++ghost_layer_index)
1203 _propagatesToChildConnectivities(family);
1205 IItemFamilyNetwork::TopologicalOrder);
1217_computeItemsToSend3()
1219 for(
const auto& iter : m_items_to_send )
1220 iter.second->resize(m_nb_rank);
1222 IItemFamily* node_family = mesh()->
nodeFamily();
1223 IItemFamily* edge_family = mesh()->
edgeFamily();
1224 IItemFamily* face_family = mesh()->
faceFamily();
1225 IItemFamily* cell_family = m_cell_family;
1227 _setItemsToSend(node_family);
1228 _setItemsToSend(edge_family);
1229 _setItemsToSend(face_family);
1230 _setItemsToSend(cell_family);
1234 for( IItemFamily* family :
m_mesh->itemFamilies()){
1235 IParticleFamily* particle_family = family->toParticleFamily();
1236 if (particle_family && particle_family->getEnableGhostItems()==
true){
1239 for (
const auto& dest_rank : m_item_dest_ranks_map[m_cell_family]->at(iparticle->cell().localId())) {
1240 to_send[dest_rank].insert(iparticle->localId());
1248 for(
const auto& iter : m_items_to_send )
1249 (*(iter.second))[m_rank].clear();
1263_setItemsToSend(IItemFamily* family)
1265 if(family->nbItem()==0)
1267 auto iter = m_items_to_send.find(family);
1268 if (iter==m_items_to_send.end())
1269 ARCANE_FATAL(
"No items to send for family '{0}'",family->name());
1270 ArrayView<std::set<Int32>> items_to_send = iter->second->view();
1271 for (Integer item_lid = 0 ; item_lid < m_item_dest_ranks_map[family]->size(); ++item_lid){
1272 for (
const auto& dest_rank : m_item_dest_ranks_map[family]->at(item_lid)){
1273 items_to_send[dest_rank].insert(item_lid);
1284 auto iter = m_items_to_send.find(family);
1285 if (iter==m_items_to_send.end())
1290 debug() <<
"= ITEM TO SEND FOR FAMILY " << family->
name();
1292 debug() <<
"== RANK " << rank++;
1306 debug() <<
"= ITEM TO REMOVE FOR FAMILY " << family->
name();
1309 debug() <<
"== TO REMOVE ITEM " << item->uniqueId() <<
" kind " << item->kind();
1318 for (
const auto& item_dest_ranks_iter : m_item_dest_ranks_map){
1320 IItemFamily* family = item_dest_ranks_iter.first;
1321 if(family->itemKind() ==
IK_DoF ){
1327 item_dest_ranks = item_dest_ranks_iter.second->at(item->localId()).view();
1329 item_dest_ranks = m_ghost_item_dest_ranks_map[item->owner()][family]->
at(item->localId()).view();
1331 if (!item_dest_ranks.contains(m_rank) && item_new_owners[item] != m_rank){
1341_markRemovableItems(
bool with_cell_family)
1343 for (
const auto& item_dest_ranks_iter : m_item_dest_ranks_map){
1345 IItemFamily* family = item_dest_ranks_iter.first;
1346 if(with_cell_family || family->name()!=m_cell_family->
name() ){
1347 auto & item_new_owners = family->itemsNewOwner();
1352 item_dest_ranks = item_dest_ranks_iter.second->at(item.localId()).view();
1354 item_dest_ranks = m_ghost_item_dest_ranks_map[item->owner()][family]->
at(item.localId()).view();
1356 if (!item_dest_ranks.contains(m_rank) && item_new_owners[item] != m_rank){
1385 ItemGroup all_items = m_cell_family->
allItems();
1388 bool use_itemfamily_network = ( itemfamily_network!=
nullptr && itemfamily_network->isActivated() );
1391 if (use_active_cells)
1392 all_items = m_cell_family->
allItems().activeCellGroup();
1396 Integer cell_local_id = cell.localId();
1397 if (cells_new_owner[cell_local_id]==m_rank)
1401 bool keep_cell = new_owners.
contains(m_rank);
1403 Int32ConstArrayView extra_new_owners = m_neighbour_extra_cells_new_owner->at(cell_local_id);
1404 keep_cell = extra_new_owners.
contains(m_rank);
1406 if(!keep_cell && use_itemfamily_network)
1411 item_dest_ranks = m_item_dest_ranks_map[m_cell_family]->at(icell->localId()).view();
1413 item_dest_ranks = m_ghost_item_dest_ranks_map[icell->owner()][m_cell_family]->
at(icell->localId()).view();
1415 keep_cell = item_dest_ranks.contains(m_rank) ;
1427_markRemovableParticles()
1429 for( IItemFamily* family :
m_mesh->itemFamilies()){
1430 IParticleFamily* particle_family = family->toParticleFamily();
1431 if(particle_family && particle_family->getEnableGhostItems()==
true){
1432 mesh::NewItemOwnerBuilder owner_builder;
1435 Particle particle = *iparticle;
1436 Cell cell = owner_builder.connectedCellOfItem(particle);
1437 particle.mutableItemBase().setFlags(cell.itemBase().flags());
1447_checkSubItemsDestRanks()
1453 const auto& item_dest_ranks = m_item_dest_ranks_map[family]->at(item.localId());
1454 for (
const auto& child_dependency :
m_mesh->itemFamilyNetwork()->getChildDependencies(family))
1456 auto accessor = IndexedItemConnectivityAccessor(child_dependency);
1460 if (connected_item->isOwn()) {
1461 subitem_dest_ranks = m_item_dest_ranks_map[child_dependency->targetFamily()]->at(connected_item.localId()).constView();
1462 for (
auto dest_rank : item_dest_ranks) {
1463 if (! subitem_dest_ranks.contains(dest_rank))
1464 fatal() <<
"Dest Rank " << dest_rank <<
" for item " << item->kind() <<
" uid "<< item->uniqueId()
1465 <<
" not present in subitem " << connected_item->kind() <<
" uid " << connected_item->uniqueId()
1466 <<
" dest ranks " << subitem_dest_ranks <<
" ower " << connected_item->owner();
1472 }, IItemFamilyNetwork::TopologicalOrder);
1480_exchangeGhostItemDataInfos()
1498 for( Integer i=0, is=recv_sub_domains.size(); i<is; ++i )
1499 sd_exchange->addSender(recv_sub_domains[i]);
1501 sd_exchange->initializeCommunicationsMessages(recv_sub_domains);
1503 UniqueArray<IItemFamily*> item_families;
1509 for( Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
1510 ISerializeMessage* comm = sd_exchange->messageToSend(i);
1511 Int32 dest_sub_domain = comm->destination().value();
1512 ISerializer* sbuf = comm->serializer();
1513 item_families.clear();
1514 item_dest_ranks.clear();
1515 item_nb_dest_ranks.clear();
1516 family_nb_items.clear();
1518 for (
const auto& family_item_dest_ranks : m_item_dest_ranks_map){
1520 IItemFamily* family = family_item_dest_ranks.first;
1521 if (family->nbItem() == 0)
continue;
1522 item_families.add(family);
1524 auto subdomain_index = _getSubdomainIndexInCommunicatingRanks(dest_sub_domain, family->allItemsSynchronizer()->communicatingRanks());
1525 auto shared_item_lids = family->allItemsSynchronizer()->sharedItems(subdomain_index);
1526 for (
const auto& item_lid : shared_item_lids){
1527 if (family_item_dest_ranks.second->at(item_lid).size() == 0)
continue;
1528 item_dest_ranks.addRange(family_item_dest_ranks.second->at(item_lid));
1529 item_nb_dest_ranks.add(family_item_dest_ranks.second->at(item_lid).size());
1532 family_nb_items.add(family_nb_item);
1533 ENUMERATE_ITEM(item, family_item_dest_ranks.first->view(shared_item_lids)) {
1534 item_uids.add(item->uniqueId().asInt64());
1537 sbuf->setMode(ISerializer::ModeReserve);
1540 for (
const auto& family: item_families)
1541 sbuf->reserve(family->name());
1542 sbuf->reserve(
DT_Int64,item_families.size());
1544 sbuf->reserveArray(item_uids);
1545 sbuf->reserveArray(family_nb_items);
1546 sbuf->reserveArray(item_nb_dest_ranks);
1547 sbuf->reserveArray(item_dest_ranks);
1549 sbuf->allocateBuffer();
1552 sbuf->putInt64(item_families.size());
1553 for (
const auto& family: item_families)
1554 sbuf->put(family->name());
1555 for (
const auto& family: item_families)
1556 sbuf->putInteger(family->itemKind());
1558 sbuf->putArray(item_uids);
1559 sbuf->putArray(family_nb_items);
1560 sbuf->putArray(item_nb_dest_ranks);
1561 sbuf->putArray(item_dest_ranks);
1564 sd_exchange->processExchange();
1566 for( Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
1567 ISerializeMessage* comm = sd_exchange->messageToReceive(i);
1568 ISerializer* sbuf = comm->serializer();
1569 Int64 nb_families = sbuf->getInt64();
1572 for (
auto& family_name: item_family_names)
1573 sbuf->get(family_name);
1574 for (
auto& family_kind: item_family_kinds)
1575 family_kind = sbuf->getInteger();
1576 sbuf->getArray(item_uids);
1577 sbuf->getArray(family_nb_items);
1578 sbuf->getArray(item_nb_dest_ranks);
1579 sbuf->getArray(item_dest_ranks);
1581 Integer item_nb_dest_rank_index = 0;
1582 Integer item_dest_rank_index = 0;
1583 for (
int family_index = 0; family_index < nb_families; ++family_index) {
1587 family->itemsUniqueIdToLocalId(item_lids,family_item_uids,
true);
1588 for (
const auto& item_lid : item_lids) {
1589 auto sub_view = item_dest_ranks.subView(item_dest_rank_index,item_nb_dest_ranks[item_nb_dest_rank_index]);
1590 Int32 dest_rank = comm->destination().value();
1591 m_ghost_item_dest_ranks_map[dest_rank][family]->
at(item_lid).addRange(sub_view);
1592 item_dest_rank_index+= item_nb_dest_ranks[item_nb_dest_rank_index++];
1594 item_uid_index+= family_nb_items[family_index];
1604_getSubdomainIndexInCommunicatingRanks(Integer rank,
Int32ConstArrayView communicating_ranks)
1607 while (communicating_ranks[i]!=rank) {
1616ISubDomain* MeshExchange::
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Vue sur les informations des mailles.
Cell topHParent() const
parent de niveau 0 pour l'AMR
Interface d'une famille d'entités.
virtual ItemGroup allItems() const =0
Groupe de toutes les entités.
virtual Int32 maxLocalId() const =0
virtual String name() const =0
Nom de la famille.
virtual eItemKind itemKind() const =0
Genre des entités.
virtual void itemsUniqueIdToLocalId(Int32ArrayView local_ids, Int64ConstArrayView unique_ids, bool do_fatal=true) const =0
Converti un tableau de numéros uniques en numéros locaux.
virtual VariableItemInt32 & itemsNewOwner()=0
Variable contenant le numéro du nouveau sous-domaine propriétaire de l'entité.
virtual void getCommunicatingSubDomains(Int32Array &sub_domains) const =0
Liste des sous-domaines communiquants pour les entités.
virtual IItemFamily * nodeFamily()=0
Retourne la famille des noeuds.
virtual IItemFamily * edgeFamily()=0
Retourne la famille des arêtes.
virtual IItemFamily * findItemFamily(eItemKind ik, const String &name, bool create_if_needed=false, bool register_modifier_if_created=false)=0
Retourne la famille de nom name.
virtual IItemFamily * faceFamily()=0
Retourne la famille des faces.
virtual bool useMeshItemFamilyDependencies() const =0
check if the network itemFamily dependencies is activated
virtual ISubDomain * subDomain()=0
Sous-domaine associé
virtual IGhostLayerMng * ghostLayerMng() const =0
Gestionnare de couche fantômes associé
virtual IItemFamilyNetwork * itemFamilyNetwork()=0
Interface du réseau de familles (familles connectées)
virtual Int32 commSize() const =0
Nombre d'instance dans le communicateur.
@ II_NeedRemove
L'entité doit être supprimé
Index d'un Item dans une variable.
NodeConnectedListViewType nodes() const
Liste des noeuds de l'entité
constexpr Int32 localId() const
Identifiant local de l'entité dans le sous-domaine du processeur.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
ConstArrayView< std::set< Int32 > > getItemsToSend(IItemFamily *family) const
Liste par sous-domaine des entités à envoyer pour la famille family.
void computeInfos()
Calcule les infos.
ArrayView< std::set< Int32 > > _getItemsToSend(IItemFamily *family)
Liste par sous-domaine des entités à envoyer pour la famille family.
void _printItemToSend(IItemFamily *family)
Utilisant ItemFamilyNetwork.
void _computeMeshConnectivityInfos2(Int32ConstArrayView cells_new_owner)
AMR.
void _computeMeshConnectivityInfos3()
AMR OFF.
bool contains(ConstReferenceType v) const
Vrai si le tableau contient l'élément de valeur v.
Integer size() const
Nombre d'éléments du vecteur.
Vue modifiable d'un tableau d'un type T.
constexpr ArrayView< T > subView(Integer abegin, Integer asize) noexcept
Sous-vue à partir de l'élément abegin et contenant asize éléments.
bool contains(const_reference v) const
true si le tableau contient l'élément de valeur v
ConstReferenceType at(Int64 i) const
Elément d'indice i. Vérifie toujours les débordements.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
Vue constante d'un tableau de type T.
@ ModePut
Le sérialiseur attend des reserve()
Classe d'accès aux traces.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flot pour un message de debug.
TraceMessage info() const
Flot pour un message d'information.
TraceMessage fatal() const
Flot pour un message d'erreur fatale.
Vecteur 1D de données avec sémantique par valeur (style STL).
ItemEnumeratorT< Node > NodeEnumerator
Enumérateurs sur des noeuds.
ItemEnumeratorT< Face > FaceEnumerator
Enumérateurs sur des faces.
ItemEnumeratorT< Edge > EdgeEnumerator
Enumérateurs sur des arêtes.
ItemEnumeratorT< Cell > CellEnumerator
Enumérateurs sur des mailles.
Ref< IParallelExchanger > createExchangerRef(IParallelMng *pm)
Retourne une interface pour transférer des messages entre rangs.
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
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.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
eItemKind
Genre d'entité de maillage.
@ IK_Node
Entité de maillage de genre noeud.
@ IK_Cell
Entité de maillage de genre maille.
@ IK_Face
Entité de maillage de genre face.
@ IK_DoF
Entité de maillage de genre degre de liberte.
@ IK_Edge
Entité de maillage de genre arête.
Array< Int32 > Int32Array
Tableau dynamique à une dimension d'entiers 32 bits.
UniqueArray< String > StringUniqueArray
Tableau dynamique à une dimension de chaînes de caractères.
@ DT_Int64
Donnée de type entier 64 bits.
UniqueArray< Integer > IntegerUniqueArray
Tableau dynamique à une dimension d'entiers.
ArrayView< Int32 > Int32ArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Int32 Integer
Type représentant un entier.