Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ItemConnectivitySynchronizer.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ItemConnectivitySynchronizer.cc (C) 2000-2023 */
9/* */
10/* Synchronization des connectivités. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/mesh/ItemConnectivitySynchronizer.h"
15#include "arcane/mesh/IItemConnectivityGhostPolicy.h"
16
17#include <algorithm>
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
31: m_connectivity(connectivity)
32, m_ghost_policy(ghost_policy)
33, m_parallel_mng(m_connectivity->targetFamily()->mesh()->parallelMng())
34, m_added_ghost(m_parallel_mng->commSize())
35{
36}
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
43{
44 // Compute ghost element for ToFamily
45 mesh::ExtraGhostItemsManager extra_ghost_mng(this);
46 extra_ghost_mng.addExtraGhostItemsBuilder(this);
47 extra_ghost_mng.computeExtraGhostItems();
48}
49
52{
53 // Get, for each rank k, ToFamily item that have to be shared with rank k, the
54 m_data_to_send.clear();
56 m_data_to_send.resize(m_parallel_mng->commSize());
57 const Int32 my_rank = m_parallel_mng->commRank();
58 for (Integer i = 0; i < ranks.size(); ++i){
59 Integer rank = ranks[i];
60 Int32Array& data_to_send = m_data_to_send[rank];
61 Int32SharedArray shared_items = m_ghost_policy->sharedItems(rank,m_connectivity->targetFamily()->name());
62 Int32SharedArray shared_items_connected_items = m_ghost_policy->sharedItemsConnectedItems(rank,m_connectivity->sourceFamily()->name());
63 _getItemToSend(shared_items,shared_items_connected_items, rank);
64 data_to_send.add(shared_items.size());
65 data_to_send.addRange(shared_items);
67 data_to_send.addRange(my_rank,shared_items.size()); // shared item owner
68 }
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
76{
77 // Treat ghost item info : split into item_uids, nb_dof_per_item, dof_uids
82 // Convert in uids (items must belong to current process)
85 Integer i = 0, j= 0;
86 ENUMERATE_ITEM(item,m_connectivity->targetFamily()->view(shared_item_lids)){
87 shared_item_uids[i++] = item->uniqueId().asInt64();
88 }
89 ENUMERATE_ITEM(item,m_connectivity->sourceFamily()->view(shared_item_connected_item_lids)){
90 shared_item_connected_item_uids[j++] = item->uniqueId().asInt64();
91 }
92
93 // Serialize item_uid, nb_dof, shared_item_connected_item_uids
94 buffer->setMode(ISerializer::ModeReserve);
95 buffer->reserve(DT_Int64,1);
99
100 buffer->allocateBuffer();
102
103 buffer->putInt64(nb_shared_item);
104 buffer->putSpan(shared_item_uids);
107}
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112void ItemConnectivitySynchronizer::
113addExtraGhostItems (ISerializer* buffer)
114{
115 // Deserialiser le buffer et faire un addGhost classique, puis faire la connexion grace a l'item property
117
118 Int64 nb_shared_items = buffer->getInt64();
119
123
124 buffer->getSpan(shared_item_uids);
127
128 // Remove possible repetition in shared_items and impact owners. Necessary to add these items in the family
131 _removeDuplicatedValues(shared_item_uids_to_add,shared_item_owners_to_add);
132
133 // Add shared items
136 m_connectivity->targetFamily()->endUpdate();
137
138 // update connectivity
140 bool do_fatal = true; // shared_items have been adde to the family
141 m_connectivity->targetFamily() ->itemsUniqueIdToLocalId(shared_item_lids,shared_item_uids,do_fatal);
142 // shared_item_connected_item are not compulsory present on the new subdomain where shared_items have been send.
143 // Send shared_item_connected_items_uids to GhostPolicy where they will be handled (possibly converted to lid if they are present).
145
146}
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151void ItemConnectivitySynchronizer::
152_getItemToSend(Int32SharedArray& shared_items, Int32SharedArray& shared_items_connected_items, const Integer rank)
153{
154 // remove null items.
155 Int32UniqueArray non_null_shared_items, non_null_shared_items_connected_items;
156 non_null_shared_items.reserve(shared_items.size());
157 non_null_shared_items_connected_items.reserve(shared_items_connected_items.size());
158 auto i = 0;
159 for (auto item : shared_items) {
160 if (item != NULL_ITEM_LOCAL_ID) {
161 non_null_shared_items.add(shared_items[i]);
162 non_null_shared_items_connected_items.add(shared_items_connected_items[i]);
163 }
164 ++i;
165 }
166 shared_items.copy(non_null_shared_items);
167 shared_items_connected_items.copy(non_null_shared_items_connected_items);
168 // Filter: don't add ghost twice. The synchronizer remember the ghost added and don't add them twice.
169 Int64SharedArray shared_items_uids(shared_items.size());
170 ItemVectorView shared_items_view = m_connectivity->targetFamily()->view(shared_items);
171 for (Integer i = 0; i < shared_items_view.size(); ++i)
172 shared_items_uids[i] = shared_items_view[i].uniqueId().asInt64();
173 std::set<Int64>& added_ghost = m_added_ghost[rank];
174
175
176 // reverse order to handle index changes due to remove
177 for (Integer i = shared_items_uids.size()-1; i >=0 ; --i ){
178 if (!added_ghost.insert(shared_items_uids[i]).second){
179 // check if already added ghost
180 shared_items.remove(i);
181 shared_items_connected_items.remove(i);
182 }
183 }
184}
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189void ItemConnectivitySynchronizer::
190_removeDuplicatedValues(Int64SharedArray& shared_item_uids, IntegerSharedArray& shared_item_owners)
191{
192 // Reverse order for the loop : otherwise wrong !! (since elements are removed and thus index are modified)
193 std::set<Int64> shared_uids_set;
194 for (Integer i = shared_item_uids.size()-1; i >= 0 ; --i){
195 if (! shared_uids_set.insert(shared_item_uids[i]).second){
196 // element already in the set, remove it from both arrays.
197 shared_item_uids.remove(i);
198 shared_item_owners.remove(i);
199 }
200 }
201}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
206ISubDomain* ItemConnectivitySynchronizer::
207subDomain()
208{
209 return m_connectivity->targetFamily()->mesh()->subDomain();
210}
211
212/*---------------------------------------------------------------------------*/
213/*---------------------------------------------------------------------------*/
214
215} // End namespace Arcane
216
217/*---------------------------------------------------------------------------*/
218/*---------------------------------------------------------------------------*/
#define ENUMERATE_ITEM(name, group)
Enumérateur générique d'un groupe de noeuds.
Tableau d'items de types quelconques.
virtual Int32ConstArrayView sharedItems(const Integer rank, const String &family_name)=0
donne les local_ids des items de la famille family_name partagés pour la connectivité avec le process...
virtual Int32ConstArrayView communicatingRanks()=0
Rangs des sous-domaines avec lesquels on communique.
virtual Int32ConstArrayView sharedItemsConnectedItems(const Integer rank, const String &family_name)=0
donne les local_ids des items de la famille family_name connectés avec les sharedItems(rank).
virtual void updateConnectivity(Int32ConstArrayView ghost_items, Int64ConstArrayView ghost_items_connected_items)=0
mets à jour la connectivité en connectant les items fantômes ajoutés..
Interface pour gérer une connectivité.
virtual IItemFamily * targetFamily() const =0
Famille cible.
virtual IItemFamily * sourceFamily() const =0
Famille source.
virtual Int32 commRank() const =0
Rang de cette instance dans le communicateur.
virtual Int32 commSize() const =0
Nombre d'instance dans le communicateur.
void computeExtraItemsToSend()
Interface IExtraGhostItemsBuilder.
ItemConnectivitySynchronizer(IItemConnectivity *connectivity, IItemConnectivityGhostPolicy *ghost_policy)
void serializeGhostItems(ISerializer *buffer, Int32ConstArrayView ghost_item_lids)
Interface IExtraGhostItemsAdder : add extra ghost in TargetFamily.
void synchronize()
Interface IConnectivitySynchronizer.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
void remove(Int64 index)
Supprime l'entité ayant l'indice index.
Vue constante d'un tableau de type T.
virtual void allocateBuffer()=0
Alloue la mémoire du sérialiseur.
virtual void reserveSpan(eDataType dt, Int64 n)=0
Réserve de la mémoire pour n valeurs de dt.
virtual void putSpan(Span< const Real > values)
Ajoute le tableau values.
virtual void getSpan(Span< Real > values)
Récupère le tableau values.
virtual Int64 getInt64()=0
Récupère une taille.
virtual void reserve(eDataType dt, Int64 n)=0
Réserve de la mémoire pour n objets de type dt.
virtual void setMode(eMode new_mode)=0
Positionne le fonctionnement actuel.
virtual void putInt64(Int64 value)=0
Ajoute l'entier value.
Vecteur 1D de données avec sémantique par référence.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
SharedArray< Int64 > Int64SharedArray
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:545
SharedArray< Int32 > Int32SharedArray
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:547
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:515
SharedArray< Integer > IntegerSharedArray
Tableau dynamique à une dimension d'entiers.
Definition UtilsTypes.h:551
@ DT_Int64
Donnée de type entier 64 bits.
Definition DataTypes.h:44