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/core/IMesh.h"
20#include "arcane/core/ISubDomain.h"
21#include "arcane/core/IParallelMng.h"
22#include "arcane/core/IParallelExchanger.h"
23#include "arcane/core/IItemFamily.h"
25#include "arcane/core/Item.h"
26#include "arcane/core/MeshVariable.h"
27#include "arcane/core/IParticleFamily.h"
28#include "arcane/core/ParallelMngUtils.h"
29#include "arcane/core/ConnectivityItemVector.h"
30#include "arcane/core/IndexedItemConnectivityView.h"
31#include "arcane/core/ItemPrinter.h"
32#include "arcane/core/IParallelMng.h"
33#include "arcane/core/VariableTypes.h"
34#include "arcane/core/IItemFamilyNetwork.h"
35#include "arcane/core/IGhostLayerMng.h"
36#include "arcane/core/ConnectivityItemVector.h"
37#include "arcane/core/IVariableSynchronizer.h"
38#include "arcane/core/ISerializeMessage.h"
39#include "arcane/core/ISerializer.h"
41#include "arcane/mesh/IndexedItemConnectivityAccessor.h"
42#include "arcane/mesh/MeshExchange.h"
43#include "arcane/mesh/NewItemOwnerBuilder.h"
60 IncrementalUnorderedMultiArray(
Integer size)
61 : m_current_increment(-1), m_current_size(0), m_index(size, -1),
66 IncrementalUnorderedMultiArray()
67 : m_current_increment(-1), m_current_size(0) {}
69 inline void resize(
Integer size)
71 m_index.resize(size, -1);
72 m_size.resize(size, 0);
77 return m_index.size();
80 inline void dataReserve(
Integer size)
85 inline void addData(
const T data)
96 inline void beginIncrement(
Integer id)
98 ARCANE_ASSERT((m_current_increment == -1),(
"call endIncrement before begin"));
99 m_current_increment = id;
101 m_index[m_current_increment] = m_data.size();
104 inline void endIncrement()
106 m_size[m_current_increment] = m_current_size;
107 m_current_increment = -1;
113 return m_data.
subView(m_index[
id],m_size[
id]);
118 return m_data.
subView(m_index[
id],m_size[
id]);
137 DynamicMultiArray(
Integer size)
140 DynamicMultiArray() {}
142 inline void resize(
Integer size) {
147 return m_data.size();
150 inline void addData(
Integer id,
const T data) {
151 m_data[id].add(data);
172MeshExchange(
IMesh* mesh)
175, m_parallel_mng(mesh->parallelMng())
176, m_nb_rank(m_parallel_mng->commSize())
177, m_rank(m_parallel_mng->commRank())
178, m_cell_family(mesh->itemFamily(
IK_Cell))
179, m_neighbour_cells_owner(NULL)
180, m_neighbour_cells_new_owner(NULL)
181, m_neighbour_extra_cells_owner(NULL)
182, m_neighbour_extra_cells_new_owner(NULL)
192 for(
const auto& itosend : m_items_to_send )
193 delete itosend.second;
194 delete m_neighbour_cells_owner;
195 delete m_neighbour_cells_new_owner;
196 delete m_neighbour_extra_cells_owner;
197 delete m_neighbour_extra_cells_new_owner;
198 for(
const auto& idestrank : m_item_dest_ranks_map)
199 delete idestrank.second;
200 for (
const auto& ighostdestrank_map : m_ghost_item_dest_ranks_map)
201 for (
const auto& ighostdestrank : ighostdestrank_map)
202 delete ighostdestrank.second;
212 auto iter = m_items_to_send.find(family);
213 if (iter==m_items_to_send.end())
215 return iter->second->constView();
225 auto iter = m_items_to_send.find(family);
226 if (iter==m_items_to_send.end())
228 return iter->second->view();
240 m_items_to_send.insert(std::make_pair(family,
new UniqueArray< std::set<Int32> >));
245 if(
m_mesh->isAmrActivated()){
247 _computeGraphConnectivityInfos();
248 _exchangeCellDataInfos(cells_new_owner,
true);
249 _markRemovableCells(cells_new_owner,
true);
250 _markRemovableParticles();
251 _computeItemsToSend2();
253 else if (
m_mesh->itemFamilyNetwork() &&
m_mesh->itemFamilyNetwork()->isActivated())
255 if(
m_mesh->useMeshItemFamilyDependencies())
258 _computeGraphConnectivityInfos();
259 _exchangeCellDataInfos3();
260 _exchangeGhostItemDataInfos();
261 _markRemovableItems();
262 _markRemovableParticles();
263 _computeItemsToSend3();
268 _computeMeshConnectivityInfos(cells_new_owner);
270 _computeGraphConnectivityInfos();
271 _exchangeCellDataInfos(cells_new_owner,
false);
272 _exchangeCellDataInfos3();
275 _markRemovableDoFs();
276 _markRemovableCells(cells_new_owner,
false);
277 _markRemovableParticles();
278 _computeItemsToSend(
true);
283 _computeMeshConnectivityInfos(cells_new_owner);
284 _computeGraphConnectivityInfos();
285 _exchangeCellDataInfos(cells_new_owner,
false);
286 _markRemovableCells(cells_new_owner,
false);
287 _markRemovableParticles();
288 _computeItemsToSend();
296_computeGraphConnectivityInfos()
301 tmp_new_owner.fill(NULL_ITEM_ID);
303 tmp_owner.fill(NULL_ITEM_ID);
306 tmp_link_new_owner.fill(NULL_ITEM_ID);
308 tmp_link_owner.fill(NULL_ITEM_ID);
310 mesh::NewItemOwnerBuilder owner_builder;
312 m_neighbour_extra_cells_owner =
new DynamicMultiArray<Int32>(cell_variable_size);
313 m_neighbour_extra_cells_new_owner =
new DynamicMultiArray<Int32>(cell_variable_size);
317 _addGraphConnectivityToNewConnectivityInfo();
325_addGraphConnectivityToNewConnectivityInfo()
328 Int32Array& extra_new_owners = m_neighbour_extra_cells_new_owner->at(icell.localId());
329 Int32Array& extra_owners = m_neighbour_extra_cells_owner->at(icell.localId());
330 ItemDestRankArray* item_dest_ranks =
nullptr;
332 item_dest_ranks = m_item_dest_ranks_map[m_cell_family];
334 item_dest_ranks= m_ghost_item_dest_ranks_map[icell->owner()][m_cell_family];
335 item_dest_ranks->at(icell.localId()).
addRange(extra_new_owners);
336 item_dest_ranks->at(icell.localId()).addRange(extra_owners);
339 _propagatesToChildDependencies(m_cell_family);
348 Integer cell_variable_size = m_cell_family->maxLocalId();
354 tmp_new_owner.fill(NULL_ITEM_ID);
356 tmp_owner.fill(NULL_ITEM_ID);
360 Integer cell_local_id = cell.localId();
362 tmp_owner[m_rank] = cell_local_id;
364 m_neighbour_cells_owner->beginIncrement(cell_local_id);
365 m_neighbour_cells_new_owner->beginIncrement(cell_local_id);
369 Integer cell2_local_id = icell2.localId();
370 Integer cell2_new_owner = cells_new_owner[cell2_local_id];
371 Integer cell2_owner = icell2->owner();
374 if (tmp_new_owner[cell2_new_owner]!=cell_local_id){
375 tmp_new_owner[cell2_new_owner] = cell_local_id;
376 m_neighbour_cells_new_owner->addData(cell2_new_owner);
378 if (tmp_owner[cell2_owner]!=cell_local_id){
379 tmp_owner[cell2_owner] = cell_local_id;
380 m_neighbour_cells_owner->addData(cell2_owner);
384 m_neighbour_cells_owner->endIncrement();
385 m_neighbour_cells_new_owner->endIncrement();
393_exchangeCellDataInfos([[maybe_unused]]
Int32ConstArrayView cells_new_owner,
bool use_active_cells)
398 m_cell_family->getCommunicatingSubDomains(recv_sub_domains);
399 for(
Integer i=0, is=recv_sub_domains.size(); i<is; ++i )
400 sd_exchange->addSender(recv_sub_domains[i]);
402 sd_exchange->initializeCommunicationsMessages(recv_sub_domains);
404 UniqueArray<Int64> cells_to_comm_uid;
405 UniqueArray<Int32> cells_to_comm_owner;
406 UniqueArray<Int32> cells_to_comm_owner_size;
407 UniqueArray<Int32> cells_to_comm_new_owner;
408 UniqueArray<Int32> cells_to_comm_new_owner_size;
410 ItemGroup own_items = m_cell_family->allItems().own();
411 ItemGroup all_items = m_cell_family->allItems();
413 if (use_active_cells){
414 own_items = m_cell_family->allItems().ownActiveCellGroup();
415 all_items = m_cell_family->allItems().activeCellGroup();
418 for(
Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
419 ISerializeMessage* comm = sd_exchange->messageToSend(i);
420 Int32 dest_sub_domain = comm->destination().value();
421 ISerializer* sbuf = comm->serializer();
423 cells_to_comm_uid.clear();
424 cells_to_comm_owner.clear();
425 cells_to_comm_owner_size.clear();
426 cells_to_comm_new_owner.clear();
427 cells_to_comm_new_owner_size.clear();
431 Integer cell_local_id = cell.localId();
433 bool need_send = owners.
contains(dest_sub_domain);
436 need_send = extra_owners.contains(dest_sub_domain);
443 const Integer nb_owner = owners.size();
445 Int32ConstArrayView extra_new_owner = m_neighbour_extra_cells_new_owner->at(cell_local_id);
446 const Integer nb_extra_new_owner = extra_new_owner.
size();
448 cells_to_comm_uid.add(cell.uniqueId().asInt64());
449 cells_to_comm_owner_size.add(nb_owner);
450 cells_to_comm_new_owner_size.add(nb_new_owner+nb_extra_new_owner);
451 for(
Integer zz=0; zz<nb_owner; ++zz )
452 cells_to_comm_owner.add(owners[zz]);
453 for(
Integer zz=0; zz<nb_new_owner; ++zz )
454 cells_to_comm_new_owner.add(new_owners[zz]);
455 for(
Integer zz=0; zz<nb_extra_new_owner; ++zz )
456 cells_to_comm_new_owner.add(extra_new_owner[zz]);
458 sbuf->setMode(ISerializer::ModeReserve);
460 sbuf->reserveInt64(1);
461 sbuf->reserveArray(cells_to_comm_uid);
462 sbuf->reserveArray(cells_to_comm_owner_size);
463 sbuf->reserveArray(cells_to_comm_owner);
464 sbuf->reserveArray(cells_to_comm_new_owner_size);
465 sbuf->reserveArray(cells_to_comm_new_owner);
467 sbuf->allocateBuffer();
470 sbuf->putInt64(cells_to_comm_uid.size());
471 sbuf->putArray(cells_to_comm_uid);
472 sbuf->putArray(cells_to_comm_owner_size);
473 sbuf->putArray(cells_to_comm_owner);
474 sbuf->putArray(cells_to_comm_new_owner_size);
475 sbuf->putArray(cells_to_comm_new_owner);
478 sd_exchange->processExchange();
481 for(
Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
482 ISerializeMessage* comm = sd_exchange->messageToReceive(i);
483 ISerializer* sbuf = comm->serializer();
486 Int64 nb_cell = sbuf->getInt64();
487 sbuf->getArray(cells_to_comm_uid);
488 sbuf->getArray(cells_to_comm_owner_size);
489 sbuf->getArray(cells_to_comm_owner);
490 sbuf->getArray(cells_to_comm_new_owner_size);
491 sbuf->getArray(cells_to_comm_new_owner);
492 cells_to_comm_local_id.resize(nb_cell);
493 m_cell_family->itemsUniqueIdToLocalId(cells_to_comm_local_id,cells_to_comm_uid);
494 for(
Integer icell=0; icell<nb_cell; ++icell ){
495 Integer cell_local_id = cells_to_comm_local_id[icell];
496 Integer cell_nb_owner = cells_to_comm_owner_size[icell];
497 Integer cell_nb_new_owner = cells_to_comm_new_owner_size[icell];
499 info()<<
" cell "<<icell
500 <<
" lid=" <<cell_local_id
501 <<
" uid=" <<cells_to_comm_uid[icell]
502 <<
" ind=" <<m_neighbour_cells_owner->index(cell_local_id);
504 if (m_neighbour_cells_owner->index(cell_local_id)!=(-1))
505 fatal() <<
"Cell uid=" << cells_to_comm_uid[icell] <<
" already has neighbours 'owner'!";
506 if (m_neighbour_cells_new_owner->index(cell_local_id)!=(-1))
507 fatal() <<
"Cell uid=" << cells_to_comm_uid[icell] <<
" already has neighbours 'new_owner'!";
508 m_neighbour_cells_owner->beginIncrement(cell_local_id);
509 m_neighbour_cells_new_owner->beginIncrement(cell_local_id);
511 info()<<
" cell "<< icell
512 <<
" lid=" << cell_local_id
513 <<
" uid=" << cells_to_comm_uid[icell]
514 <<
" ind=" << m_neighbour_cells_owner->index(cell_local_id);
516 for(
Integer zz=0; zz<cell_nb_owner; ++zz )
517 m_neighbour_cells_owner->addData(cells_to_comm_owner[owner_index+zz]);
518 owner_index += cell_nb_owner;
519 m_neighbour_cells_owner->endIncrement();
521 for(
Integer zz=0; zz<cell_nb_new_owner; ++zz )
522 m_neighbour_cells_new_owner->addData(cells_to_comm_new_owner[new_owner_index+zz]);
523 new_owner_index += cell_nb_new_owner;
524 m_neighbour_cells_new_owner->endIncrement();
533_addItemToSend(ArrayView< std::set<Int32> > items_to_send,
535 bool use_itemfamily_network)
538 for(
Integer zz=0, nb_new_owner = new_owners.size(); zz<nb_new_owner; ++zz )
539 items_to_send[new_owners[zz]].insert(local_id);
541 Int32ConstArrayView extra_new_owners = m_neighbour_extra_cells_new_owner->at(cell_local_id);
542 for(
Integer zz=0, nb_extra_new_owner = extra_new_owners.size(); zz<nb_extra_new_owner; ++zz )
543 items_to_send[extra_new_owners[zz]].insert(local_id);
545 if(use_itemfamily_network)
547 Int32ConstArrayView network_new_owners = m_item_dest_ranks_map[m_cell_family]->at(cell_local_id);
548 for(
Integer zz=0, nb_network_new_owner = network_new_owners.size(); zz<nb_network_new_owner; ++zz )
550 items_to_send[network_new_owners[zz]].insert(local_id);
559_computeItemsToSend(
bool send_dof)
561 for(
const auto& iter : m_items_to_send )
562 iter.second->resize(m_nb_rank);
564 IItemFamily* node_family = mesh()->nodeFamily();
565 IItemFamily* edge_family = mesh()->edgeFamily();
566 IItemFamily* face_family = mesh()->faceFamily();
567 IItemFamily* cell_family = m_cell_family;
569 ArrayView<std::set<Int32>> nodes_to_send =
_getItemsToSend(node_family);
570 ArrayView<std::set<Int32>> edges_to_send =
_getItemsToSend(edge_family);
571 ArrayView<std::set<Int32>> faces_to_send =
_getItemsToSend(face_family);
572 ArrayView<std::set<Int32>> cells_to_send =
_getItemsToSend(cell_family);
576 bool use_itemfamily_network =
m_mesh->itemFamilyNetwork() &&
m_mesh->itemFamilyNetwork()->isActivated() ;
578 _addItemToSend(cells_to_send,icell.itemLocalId(),icell.itemLocalId(),use_itemfamily_network);
583 Integer node_local_id = node.localId();
585 _addItemToSend(nodes_to_send,node_local_id,icell.localId(),use_itemfamily_network);
590 Integer edge_local_id = edge.localId();
592 _addItemToSend(edges_to_send,edge_local_id,icell.localId(),use_itemfamily_network);
597 Integer face_local_id = face.localId();
599 _addItemToSend(faces_to_send,face_local_id,icell.localId(),use_itemfamily_network);
604 for( IItemFamily* family :
m_mesh->itemFamilies())
606 IParticleFamily* particle_family = family->toParticleFamily();
607 if (particle_family && particle_family->getEnableGhostItems()==
true){
610 _addItemToSend(to_send,iparticle->localId(),iparticle->cell().localId(),use_itemfamily_network);
613 if(send_dof && family->itemKind()==
IK_DoF)
615 _setItemsToSend(family);
621 for(
const auto& iter : m_items_to_send )
622 (*(iter.second))[m_rank].clear();
624 const bool is_print =
false;
626 debug() <<
"PRINT ITEM TO SEND V1";
651 Integer cell_variable_size = m_cell_family->maxLocalId();
657 tmp_new_owner.
fill(NULL_ITEM_ID);
659 tmp_owner.
fill(NULL_ITEM_ID);
661 ENUMERATE_CELL(icell,m_cell_family->allItems().ownActiveCellGroup()){
662 const Cell& cell = *icell;
665 tmp_owner[m_rank] = cell_local_id;
667 m_neighbour_cells_owner->beginIncrement(cell_local_id);
668 m_neighbour_cells_new_owner->beginIncrement(cell_local_id);
672 for(
CellEnumerator icell2((*inode)._internalActiveCells(local_ids)); icell2.hasNext(); ++icell2 ){
673 Integer cell2_local_id = icell2.localId();
674 Integer cell2_new_owner = cells_new_owner[cell2_local_id];
675 Integer cell2_owner = icell2->owner();
678 if (tmp_new_owner[cell2_new_owner]!=cell_local_id){
679 tmp_new_owner[cell2_new_owner] = cell_local_id;
680 m_neighbour_cells_new_owner->addData(cell2_new_owner);
682 if (tmp_owner[cell2_owner]!=cell_local_id){
683 tmp_owner[cell2_owner] = cell_local_id;
684 m_neighbour_cells_owner->addData(cell2_owner);
689 m_neighbour_cells_owner->endIncrement();
690 m_neighbour_cells_new_owner->endIncrement();
698_addTreeCellToSend(
ArrayView< std::set<Int32> > items_to_send,
704 Cell cell(cells[local_id]);
705 if(cell.level() == 0){
706 for(
Integer zz=0, nb_new_owner = new_owners.
size(); zz<nb_new_owner; ++zz )
707 items_to_send[new_owners[zz]].insert(local_id);
709 Int32ConstArrayView extra_new_owners = m_neighbour_extra_cells_new_owner->at(cell_local_id);
710 for(
Integer zz=0, nb_extra_new_owner = extra_new_owners.
size(); zz<nb_extra_new_owner; ++zz )
711 items_to_send[extra_new_owners[zz]].insert(local_id);
716 _familyTree(family,top_parent);
718 for(
Integer zz=0, nb_new_owner = new_owners.
size(); zz<nb_new_owner; ++zz )
719 items_to_send[new_owners[zz]].insert(family[c]);
728_addTreeItemToSend(
Int32 cell_local_id,CellInfoListView cells)
734 Cell cell(cells[cell_local_id]);
739 _familyTree(family,top_parent);
741 IItemFamily* node_family = mesh()->nodeFamily();
742 IItemFamily* edge_family = mesh()->edgeFamily();
743 IItemFamily* face_family = mesh()->faceFamily();
745 ArrayView<std::set<Int32>> nodes_to_send =
_getItemsToSend(node_family);
746 ArrayView<std::set<Int32>> edges_to_send =
_getItemsToSend(edge_family);
747 ArrayView<std::set<Int32>> faces_to_send =
_getItemsToSend(face_family);
751 for(
Integer c=0,cs=family.size();c<cs;c++)
752 for(
Integer zz=0, nb_new_owner = new_owners.size(); zz<nb_new_owner; ++zz ){
753 Cell cell2 = cells[family[c]];
754 for( Node node : cell2.nodes() )
755 nodes_to_send[new_owners[zz]].insert(node.localId());
756 for( Edge edge : cell2.edges() )
757 edges_to_send[new_owners[zz]].insert(edge.localId());
758 for( Face face : cell2.faces() )
759 faces_to_send[new_owners[zz]].insert(face.localId());
767_familyTree (
Int32Array& family,Cell item,
const bool reset)
const
769 ARCANE_ASSERT((!item.itemBase().isSubactive()),(
"The family tree doesn't include subactive items"));
774 family.add(item.localId());
777 if (!item.isActive())
778 for (
Integer c=0, cs=item.nbHChildren(); c<cs; c++){
779 Item ichild = item.hChild(c);
781 _familyTree (family,ichild.toCell(),
false);
789_computeItemsToSend2()
791 for(
const auto& iter : m_items_to_send )
792 iter.second->resize(m_nb_rank);
794 IItemFamily* node_family = mesh()->nodeFamily();
795 IItemFamily* edge_family = mesh()->edgeFamily();
796 IItemFamily* face_family = mesh()->faceFamily();
798 ArrayView<std::set<Int32>> nodes_to_send =
_getItemsToSend(node_family);
799 ArrayView<std::set<Int32>> edges_to_send =
_getItemsToSend(edge_family);
800 ArrayView<std::set<Int32>> faces_to_send =
_getItemsToSend(face_family);
801 ArrayView<std::set<Int32>> cells_to_send =
_getItemsToSend(m_cell_family);
806 CellInfoListView cells(m_cell_family);
807 ENUMERATE_CELL(icell,m_cell_family->allItems().ownActiveCellGroup()){
809 _addTreeCellToSend(cells_to_send,icell.itemLocalId(),icell.itemLocalId(),cells);
811 if(cell.level() == 0){
816 Integer node_local_id = node.localId();
820 _addItemToSend(nodes_to_send,node_local_id,icell2.localId());
828 Integer edge_local_id = edge.localId();
830 _addItemToSend(edges_to_send,edge_local_id,icell2.localId());
837 Integer face_local_id = face.localId();
839 _addItemToSend(faces_to_send,face_local_id,icell2.localId());
845 else if(cell.level() > 0)
846 _addTreeItemToSend(icell.itemLocalId(),cells);
849 for( IItemFamily* family :
m_mesh->itemFamilies()){
850 IParticleFamily* particle_family = family->toParticleFamily();
851 if (particle_family && particle_family->getEnableGhostItems()==
true){
854 _addItemToSend(to_send,iparticle->localId(),iparticle->cell().localId());
860 for(
const auto& iter : m_items_to_send )
861 (*(iter.second))[m_rank].clear();
885 if (!
m_mesh->itemFamilyNetwork())
info() <<
"Should have an IItemFamilyNetwork. Exiting.";
887 m_ghost_item_dest_ranks_map.resize(m_parallel_mng->commSize());
891 IItemFamilyNetwork::TopologicalOrder);
901 if (!
m_mesh->ghostLayerMng())
info() <<
"Should have a IGhostLayerMng. Exiting";
902 for (
int ghost_layer_index = 0; ghost_layer_index <
m_mesh->ghostLayerMng()->nbGhostLayer(); ++ghost_layer_index)
906 _propagatesToChildConnectivities(family);
908 IItemFamilyNetwork::TopologicalOrder);
921_propagatesToChildConnectivities(
IItemFamily* family)
934 for (
const auto& child_connectivity : child_connectivities){
935 if(child_connectivity)
937 VariableItemInt32& conn_item_new_owner = child_connectivity->targetFamily()->itemsNewOwner();
941 _addDestRank(*item,family,item_new_owner[item]);
943 _addDestRank(*item,family,conn_item_new_owner[connected_item]);
947 _addDestRank(*connected_item,child_connectivity->targetFamily(),*item,family);
952 if(!
m_mesh->useMeshItemFamilyDependencies()){
956 for( Cell cell : item->cells())
957 _addDestRank(cell,m_cell_family,*item,family);
962 for( Cell cell : item->cells() )
963 _addDestRank(cell,m_cell_family,*item,family);
968 for( Cell cell : item->cells())
969 _addDestRank(cell,m_cell_family,*item,family);
982_propagatesToChildDependencies(IItemFamily* family)
990 auto child_dependencies =
m_mesh->itemFamilyNetwork()->getChildDependencies(family);
991 for (
const auto& child_dependency :child_dependencies){
994 auto accessor = IndexedItemConnectivityAccessor(child_dependency);
998 _addDestRank(*connected_item,child_dependency->targetFamily(),*item, family);
1009_addDestRank(
const Item& item, IItemFamily* item_family,
const Integer new_owner)
1011 ItemDestRankArray* item_dest_ranks =
nullptr;
1012 if (item.owner() == m_rank) {
1013 item_dest_ranks = m_item_dest_ranks_map[item_family];
1016 item_dest_ranks= m_ghost_item_dest_ranks_map[item.owner()][item_family];
1019 auto& item_ranks_internal = item_dest_ranks->at(item.localId());
1020 if (!item_ranks_internal.contains(new_owner))
1021 item_dest_ranks->at(item.localId()).add(new_owner);
1028_addDestRank(
const Item& item, IItemFamily* item_family,
const Item& followed_item, IItemFamily* followed_item_family)
1031 ItemDestRankArray* item_dest_ranks =
nullptr;
1032 if (item.owner() == m_rank)
1034 item_dest_ranks = m_item_dest_ranks_map[item_family];
1038 item_dest_ranks= m_ghost_item_dest_ranks_map[item.owner()][item_family];
1040 ItemDestRankArray* followed_item_dest_ranks =
nullptr;
1041 if (followed_item.owner() == m_rank)
1042 followed_item_dest_ranks = m_item_dest_ranks_map[followed_item_family];
1044 followed_item_dest_ranks= m_ghost_item_dest_ranks_map[followed_item.owner()][followed_item_family];
1046 auto& new_dest_ranks = followed_item_dest_ranks->at(followed_item.localId());
1047 auto& current_dest_ranks = item_dest_ranks->at(item.localId());
1049 new_dest_rank_to_add.
reserve((new_dest_ranks.size()));
1050 for (
auto& new_dest_rank : new_dest_ranks){
1051 if (!current_dest_ranks.contains(new_dest_rank))
1052 new_dest_rank_to_add.add(new_dest_rank);
1054 current_dest_ranks.addRange(new_dest_rank_to_add);
1061_allocData(IItemFamily* family)
1063 m_item_dest_ranks_map[family] =
new ItemDestRankArray(family->maxLocalId());
1064 for (
auto& ghost_item_map : m_ghost_item_dest_ranks_map) {
1065 ghost_item_map[family] =
new ItemDestRankArray(family->maxLocalId());
1074 info() <<
"-ENTERING NEW EXCHANGE DEBUG PRINT";
1075 for(
auto& item_dest_ranks : m_item_dest_ranks_map){
1076 info() <<
"--PRINT NEW EXCHANGE INFO";
1077 info() <<
"---Destination rank for family " << item_dest_ranks.first->name();
1078 for (
int item_lid = 0; item_lid < item_dest_ranks.first->maxLocalId(); ++item_lid) {
1079 info() <<
"---Destination rank for item lid " << item_lid;
1080 for (
auto& item_dest_rank : item_dest_ranks.second->at(item_lid)) {
1081 info() <<
"---- Rank " << item_dest_rank;
1091_exchangeCellDataInfos3()
1097 m_cell_family->getCommunicatingSubDomains(recv_sub_domains);
1098 for(
Integer i=0, is=recv_sub_domains.size(); i<is; ++i )
1099 sd_exchange->addSender(recv_sub_domains[i]);
1101 sd_exchange->initializeCommunicationsMessages(recv_sub_domains);
1103 UniqueArray<IItemFamily*> item_families;
1110 for(
Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
1111 ISerializeMessage* comm = sd_exchange->messageToSend(i);
1112 Int32 dest_sub_domain = comm->destination().value();
1113 ISerializer* sbuf = comm->serializer();
1114 item_families.clear();
1115 item_dest_ranks.clear();
1116 item_nb_dest_ranks.clear();
1117 family_nb_items.clear();
1119 for (
const auto& family_ghost_item_dest_ranks : m_ghost_item_dest_ranks_map[dest_sub_domain]) {
1122 item_families.add(family_ghost_item_dest_ranks.first);
1123 for (
Integer item_lid = 0; item_lid < family_ghost_item_dest_ranks.second->size(); ++item_lid)
1125 if (family_ghost_item_dest_ranks.second->at(item_lid).size() == 0)
continue;
1126 item_lids.add(item_lid);
1127 item_dest_ranks.addRange(family_ghost_item_dest_ranks.second->at(item_lid));
1128 item_nb_dest_ranks.add(family_ghost_item_dest_ranks.second->at(item_lid).size());
1131 family_nb_items.add(family_nb_item);
1132 ENUMERATE_ITEM(item, family_ghost_item_dest_ranks.first->view(item_lids))
1134 item_uids.add(item->uniqueId().asInt64());
1137 sbuf->setMode(ISerializer::ModeReserve);
1138 sbuf->reserveInt64(1);
1139 for (
const auto& family: item_families)
1140 sbuf->
reserve(family->name());
1141 sbuf->reserveInteger(item_families.size());
1142 sbuf->reserveArray(item_uids);
1143 sbuf->reserveArray(family_nb_items);
1144 sbuf->reserveArray(item_nb_dest_ranks);
1145 sbuf->reserveArray(item_dest_ranks);
1147 sbuf->allocateBuffer();
1150 sbuf->putInt64(item_families.size());
1151 for (
const auto& family: item_families)
1152 sbuf->put(family->name());
1153 for (
const auto& family: item_families)
1154 sbuf->putInteger(family->itemKind());
1155 sbuf->putArray(item_uids);
1156 sbuf->putArray(family_nb_items);
1157 sbuf->putArray(item_nb_dest_ranks);
1158 sbuf->putArray(item_dest_ranks);
1161 sd_exchange->processExchange();
1163 for(
Integer i=0, n=recv_sub_domains.size(); i<n; ++i ){
1164 ISerializeMessage* comm = sd_exchange->messageToReceive(i);
1165 ISerializer* sbuf = comm->serializer();
1166 Int64 nb_families = sbuf->getInt64();
1169 for (
auto& family_name: item_family_names)
1170 sbuf->get(family_name);
1171 for (
auto& family_kind: item_family_kinds)
1172 family_kind = sbuf->getInteger();
1173 sbuf->getArray(item_uids);
1174 sbuf->getArray(family_nb_items);
1175 sbuf->getArray(item_nb_dest_ranks);
1176 sbuf->getArray(item_dest_ranks);
1178 Integer item_nb_dest_rank_index = 0;
1179 Integer item_dest_rank_index = 0;
1180 for (
int family_index = 0; family_index < nb_families; ++family_index)
1182 IItemFamily* family =
m_mesh->findItemFamily(
eItemKind(item_family_kinds[family_index]),
1183 item_family_names[family_index],
false);
1185 item_lids.resize(family_item_uids.size());
1186 family->itemsUniqueIdToLocalId(item_lids,family_item_uids,
true);
1187 for (
const auto& item_lid : item_lids){
1188 auto sub_view = item_dest_ranks.subView(item_dest_rank_index,item_nb_dest_ranks[item_nb_dest_rank_index]);
1189 m_item_dest_ranks_map[family]->at(item_lid).addRange(sub_view);
1190 item_dest_rank_index+= item_nb_dest_ranks[item_nb_dest_rank_index++];
1192 item_uid_index+= family_nb_items[family_index];
1197 for (
int ghost_layer_index = 0; ghost_layer_index <
m_mesh->ghostLayerMng()->nbGhostLayer(); ++ghost_layer_index)
1200 m_mesh->itemFamilyNetwork()->schedule([&](IItemFamily* family){
1201 _propagatesToChildConnectivities(family);
1203 IItemFamilyNetwork::TopologicalOrder);
1215_computeItemsToSend3()
1217 for(
const auto& iter : m_items_to_send )
1218 iter.second->resize(m_nb_rank);
1220 IItemFamily* node_family = mesh()->nodeFamily();
1221 IItemFamily* edge_family = mesh()->edgeFamily();
1222 IItemFamily* face_family = mesh()->faceFamily();
1223 IItemFamily* cell_family = m_cell_family;
1225 _setItemsToSend(node_family);
1226 _setItemsToSend(edge_family);
1227 _setItemsToSend(face_family);
1228 _setItemsToSend(cell_family);
1232 for( IItemFamily* family :
m_mesh->itemFamilies()){
1233 IParticleFamily* particle_family = family->toParticleFamily();
1234 if (particle_family && particle_family->getEnableGhostItems()==
true){
1237 for (
const auto& dest_rank : m_item_dest_ranks_map[m_cell_family]->at(iparticle->cell().localId())) {
1238 to_send[dest_rank].insert(iparticle->localId());
1246 for(
const auto& iter : m_items_to_send )
1247 (*(iter.second))[m_rank].clear();
1261_setItemsToSend(IItemFamily* family)
1263 if(family->nbItem()==0)
1265 auto iter = m_items_to_send.find(family);
1266 if (iter==m_items_to_send.end())
1267 ARCANE_FATAL(
"No items to send for family '{0}'",family->name());
1268 ArrayView<std::set<Int32>> items_to_send = iter->second->view();
1269 for (
Integer item_lid = 0 ; item_lid < m_item_dest_ranks_map[family]->size(); ++item_lid){
1270 for (
const auto& dest_rank : m_item_dest_ranks_map[family]->at(item_lid)){
1271 items_to_send[dest_rank].insert(item_lid);
1282 auto iter = m_items_to_send.find(family);
1283 if (iter==m_items_to_send.end())
1288 debug() <<
"= ITEM TO SEND FOR FAMILY " << family->
name();
1289 for (
const auto& owner_lids : items_to_send) {
1290 debug() <<
"== RANK " << rank++;
1291 for (
auto item_lid : owner_lids){
1292 debug() <<
"=== has items " << item_lid;
1304 debug() <<
"= ITEM TO REMOVE FOR FAMILY " << family->
name();
1307 debug() <<
"== TO REMOVE ITEM " << item->uniqueId() <<
" kind " << item->kind();
1316 for (
const auto& item_dest_ranks_iter : m_item_dest_ranks_map){
1318 IItemFamily* family = item_dest_ranks_iter.first;
1319 if(family->itemKind() ==
IK_DoF ){
1320 auto & item_new_owners = family->itemsNewOwner();
1325 item_dest_ranks = item_dest_ranks_iter.second->at(item->localId()).view();
1327 item_dest_ranks = m_ghost_item_dest_ranks_map[item->owner()][family]->at(item->localId()).view();
1329 if (!item_dest_ranks.contains(m_rank) && item_new_owners[item] != m_rank){
1339_markRemovableItems(
bool with_cell_family)
1341 for (
const auto& item_dest_ranks_iter : m_item_dest_ranks_map){
1343 IItemFamily* family = item_dest_ranks_iter.first;
1344 if(with_cell_family || family->name()!=m_cell_family->name() ){
1345 auto & item_new_owners = family->itemsNewOwner();
1350 item_dest_ranks = item_dest_ranks_iter.second->at(item.localId()).view();
1352 item_dest_ranks = m_ghost_item_dest_ranks_map[item->owner()][family]->at(item.localId()).view();
1354 if (!item_dest_ranks.contains(m_rank) && item_new_owners[item] != m_rank){
1383 ItemGroup all_items = m_cell_family->allItems();
1385 auto itemfamily_network =
m_mesh->itemFamilyNetwork() ;
1386 bool use_itemfamily_network = ( itemfamily_network!=
nullptr && itemfamily_network->isActivated() );
1389 if (use_active_cells)
1390 all_items = m_cell_family->allItems().activeCellGroup();
1394 Integer cell_local_id = cell.localId();
1395 if (cells_new_owner[cell_local_id]==m_rank)
1399 bool keep_cell = new_owners.
contains(m_rank);
1401 Int32ConstArrayView extra_new_owners = m_neighbour_extra_cells_new_owner->at(cell_local_id);
1402 keep_cell = extra_new_owners.
contains(m_rank);
1404 if(!keep_cell && use_itemfamily_network)
1409 item_dest_ranks = m_item_dest_ranks_map[m_cell_family]->at(icell->localId()).view();
1411 item_dest_ranks = m_ghost_item_dest_ranks_map[icell->owner()][m_cell_family]->at(icell->localId()).view();
1413 keep_cell = item_dest_ranks.contains(m_rank) ;
1425_markRemovableParticles()
1427 for( IItemFamily* family :
m_mesh->itemFamilies()){
1428 IParticleFamily* particle_family = family->toParticleFamily();
1429 if(particle_family && particle_family->getEnableGhostItems()==
true){
1430 mesh::NewItemOwnerBuilder owner_builder;
1433 Particle particle = *iparticle;
1434 Cell cell = owner_builder.connectedCellOfItem(particle);
1435 particle.mutableItemBase().setFlags(cell.itemBase().flags());
1445_checkSubItemsDestRanks()
1449 m_mesh->itemFamilyNetwork()->schedule([
this](IItemFamily* family){
1451 const auto& item_dest_ranks = m_item_dest_ranks_map[family]->at(item.localId());
1452 for (
const auto& child_dependency :
m_mesh->itemFamilyNetwork()->getChildDependencies(family))
1454 auto accessor = IndexedItemConnectivityAccessor(child_dependency);
1458 if (connected_item->isOwn()) {
1459 subitem_dest_ranks = m_item_dest_ranks_map[child_dependency->targetFamily()]->at(connected_item.localId()).constView();
1460 for (
auto dest_rank : item_dest_ranks) {
1461 if (! subitem_dest_ranks.contains(dest_rank))
1462 fatal() <<
"Dest Rank " << dest_rank <<
" for item " << item->kind() <<
" uid "<< item->uniqueId()
1463 <<
" not present in subitem " << connected_item->kind() <<
" uid " << connected_item->uniqueId()
1464 <<
" dest ranks " << subitem_dest_ranks <<
" ower " << connected_item->owner();
1470 }, IItemFamilyNetwork::TopologicalOrder);
1478_exchangeGhostItemDataInfos()
1495 m_cell_family->getCommunicatingSubDomains(recv_sub_domains);
1496 for(
Integer i=0, is=recv_sub_domains.size(); i<is; ++i )
1497 sd_exchange->addSender(recv_sub_domains[i]);
1499 sd_exchange->initializeCommunicationsMessages(recv_sub_domains);
1501 UniqueArray<IItemFamily*> item_families;
1507 for(
Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
1508 ISerializeMessage* comm = sd_exchange->messageToSend(i);
1509 Int32 dest_sub_domain = comm->destination().value();
1510 ISerializer* sbuf = comm->serializer();
1511 item_families.clear();
1512 item_dest_ranks.clear();
1513 item_nb_dest_ranks.clear();
1514 family_nb_items.clear();
1516 for (
const auto& family_item_dest_ranks : m_item_dest_ranks_map){
1518 IItemFamily* family = family_item_dest_ranks.first;
1519 if (family->nbItem() == 0)
continue;
1520 item_families.add(family);
1522 auto subdomain_index = _getSubdomainIndexInCommunicatingRanks(dest_sub_domain, family->allItemsSynchronizer()->communicatingRanks());
1523 auto shared_item_lids = family->allItemsSynchronizer()->sharedItems(subdomain_index);
1524 for (
const auto& item_lid : shared_item_lids){
1525 if (family_item_dest_ranks.second->at(item_lid).size() == 0)
continue;
1526 item_dest_ranks.addRange(family_item_dest_ranks.second->at(item_lid));
1527 item_nb_dest_ranks.add(family_item_dest_ranks.second->at(item_lid).size());
1530 family_nb_items.add(family_nb_item);
1531 ENUMERATE_ITEM(item, family_item_dest_ranks.first->view(shared_item_lids)) {
1532 item_uids.add(item->uniqueId().asInt64());
1535 sbuf->setMode(ISerializer::ModeReserve);
1537 sbuf->reserveInt64(1);
1538 for (
const auto& family: item_families)
1539 sbuf->
reserve(family->name());
1540 sbuf->reserveInt64(item_families.size());
1542 sbuf->reserveArray(item_uids);
1543 sbuf->reserveArray(family_nb_items);
1544 sbuf->reserveArray(item_nb_dest_ranks);
1545 sbuf->reserveArray(item_dest_ranks);
1547 sbuf->allocateBuffer();
1550 sbuf->putInt64(item_families.size());
1551 for (
const auto& family: item_families)
1552 sbuf->put(family->name());
1553 for (
const auto& family: item_families)
1554 sbuf->putInteger(family->itemKind());
1556 sbuf->putArray(item_uids);
1557 sbuf->putArray(family_nb_items);
1558 sbuf->putArray(item_nb_dest_ranks);
1559 sbuf->putArray(item_dest_ranks);
1562 sd_exchange->processExchange();
1564 for(
Integer i=0, is=recv_sub_domains.size(); i<is; ++i ){
1565 ISerializeMessage* comm = sd_exchange->messageToReceive(i);
1566 ISerializer* sbuf = comm->serializer();
1567 Int64 nb_families = sbuf->getInt64();
1570 for (
auto& family_name: item_family_names)
1571 sbuf->get(family_name);
1572 for (
auto& family_kind: item_family_kinds)
1573 family_kind = sbuf->getInteger();
1574 sbuf->getArray(item_uids);
1575 sbuf->getArray(family_nb_items);
1576 sbuf->getArray(item_nb_dest_ranks);
1577 sbuf->getArray(item_dest_ranks);
1579 Integer item_nb_dest_rank_index = 0;
1580 Integer item_dest_rank_index = 0;
1581 for (
int family_index = 0; family_index < nb_families; ++family_index) {
1582 IItemFamily* family =
m_mesh->findItemFamily(
eItemKind(item_family_kinds[family_index]),item_family_names[family_index],
false);
1585 family->itemsUniqueIdToLocalId(item_lids,family_item_uids,
true);
1586 for (
const auto& item_lid : item_lids) {
1587 auto sub_view = item_dest_ranks.subView(item_dest_rank_index,item_nb_dest_ranks[item_nb_dest_rank_index]);
1588 Int32 dest_rank = comm->destination().value();
1589 m_ghost_item_dest_ranks_map[dest_rank][family]->at(item_lid).addRange(sub_view);
1590 item_dest_rank_index+= item_nb_dest_ranks[item_nb_dest_rank_index++];
1592 item_uid_index+= family_nb_items[family_index];
1605 while (communicating_ranks[i]!=rank) {
1614ISubDomain* MeshExchange::
1617 return m_mesh->subDomain();
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
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.
void fill(const DataType &data)
Remplissage du tableau.
void clear()
Supprime les éléments du tableau.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
void addRange(ConstReferenceType val, Int64 n)
Ajoute n élément de valeur val à la fin du tableau.
Vue sur les informations des mailles.
Cell topHParent() const
parent de niveau 0 pour l'AMR
Vue constante d'un tableau de type T.
constexpr ConstArrayView< T > subView(Integer abegin, Integer asize) const noexcept
Sous-vue (constante) à 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
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
virtual SharedArray< IIncrementalItemConnectivity * > getChildDependencies(IItemFamily *source_family)=0
Obtenir la liste de toutes les dépendances, filles d'une famille source_family ou parentes d'une fami...
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 VariableItemInt32 & itemsNewOwner()=0
Variable contenant le numéro du nouveau sous-domaine propriétaire de l'entité.
virtual IItemFamilyNetwork * itemFamilyNetwork()=0
Interface du réseau de familles (familles connectées)
@ ModePut
Le sérialiseur attend des reserve()
@ 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.
TraceAccessor(ITraceMng *m)
Construit un accesseur via le gestionnaire de trace m.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flot pour un message de debug.
TraceMessage fatal() const
Flot pour un message d'erreur fatale.
TraceMessage info() const
Flot pour un message d'information.
ITraceMng * traceMng() const
Gestionnaire de trace.
Vecteur 1D de données avec sémantique par valeur (style STL).
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.
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.
ItemVariableScalarRefT< Int32 > VariableItemInt32
Grandeur de type entier 32 bits.
Ref< IParallelExchanger > createExchangerRef(IParallelMng *pm)
Retourne une interface pour transférer des messages entre rangs.
ArrayView< Int64 > Int64ArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
ArrayView< Int32 > Int32ArrayView
Equivalent C d'un tableau à 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.
UniqueArray< Integer > IntegerUniqueArray
Tableau dynamique à une dimension d'entiers.
std::int32_t Int32
Type entier signé sur 32 bits.