14#include "arcane/std/internal/ParallelDataWriter.h"
16#include "arcane/utils/Ref.h"
17#include "arcane/utils/Math.h"
19#include "arcane/core/IParallelMng.h"
20#include "arcane/core/IParallelExchanger.h"
21#include "arcane/core/ISerializer.h"
22#include "arcane/core/ISerializeMessage.h"
23#include "arcane/core/SerializeBuffer.h"
24#include "arcane/core/IData.h"
25#include "arcane/core/parallel/BitonicSortT.H"
26#include "arcane/core/ParallelMngUtils.h"
27#include "arcane/core/ItemGroup.h"
28#include "arcane/core/IItemFamily.h"
50 void setGatherAll(
bool v);
68 bool m_gather_all =
false;
69 bool m_is_verbose =
false;
94sortedUniqueIds()
const
96 return m_p->sortedUniqueIds();
98void ParallelDataWriter::
101 m_p->setGatherAll(v);
104void ParallelDataWriter::
107 m_p->sort(local_ids,items_uid);
110Ref<IData> ParallelDataWriter::
111getSortedValues(IData* data)
113 return m_p->getSortedValues(data);
119ParallelDataWriter::Impl::
120Impl(IParallelMng* pm)
121: TraceAccessor(pm->traceMng())
130sortedUniqueIds()
const
132 return m_sorted_unique_ids;
138void ParallelDataWriter::Impl::
147void ParallelDataWriter::Impl::
150 IParallelMng* pm = m_parallel_mng;
152 Parallel::BitonicSort<Int64> uid_sorter(pm);
153 uid_sorter.sort(items_uid);
155 ConstArrayView<Int32> key_indexes = uid_sorter.keyIndexes();
156 ConstArrayView<Int32> key_ranks = uid_sorter.keyRanks();
157 ConstArrayView<Int64> keys = uid_sorter.keys();
159 UniqueArray<Int64> global_all_keys;
160 UniqueArray<Int32> global_all_key_indexes;
161 UniqueArray<Int32> global_all_key_ranks;
163 Int32 nb_item = keys.size();
164 const Int32 my_rank = pm->commRank();
165 const bool is_verbose = m_is_verbose;
168 info() <<
"ORIGINAL I=" << i <<
" UID=" << items_uid[i]
169 <<
" INDEX=" << key_indexes[i]
170 <<
" RANK=" << key_ranks[i]
171 <<
" KEY=" << keys[i];
177 pm->allGatherVariable(keys,global_all_keys);
178 pm->allGatherVariable(key_indexes,global_all_key_indexes);
179 pm->allGatherVariable(key_ranks,global_all_key_ranks);
180 Int32 gather_rank = 0;
182 if (pm->commRank()!=gather_rank){
183 global_all_key_ranks.clear();
184 global_all_key_indexes.clear();
185 global_all_keys.clear();
187 nb_item = global_all_keys.size();
189 key_ranks = global_all_key_ranks.view();
190 key_indexes = global_all_key_indexes.view();
191 keys = global_all_keys.view();
196 m_sorted_unique_ids.resize(nb_item);
197 m_sorted_unique_ids.copy(keys);
202 info() <<
"I=" << i <<
" KEY=" << keys[i]
203 <<
" INDEX=" << key_indexes[i]
204 <<
" RANK=" << key_ranks[i];
208 UniqueArray<UniqueArray<Int32>> indexes_list(pm->commSize());
209 UniqueArray<UniqueArray<Int32>> own_indexes_list(pm->commSize());
212 for(
Integer i=0; i<nb_item; ++i ){
213 Int32 index = key_indexes[i];
214 Int32 rank = key_ranks[i];
215 if (rank != my_rank && indexes_list[rank].empty())
216 sd_exchange->addSender(rank);
217 indexes_list[rank].add(index);
218 own_indexes_list[rank].add(i);
220 m_local_indexes_to_recv = own_indexes_list[my_rank];
221 m_local_indexes_to_send.resize(indexes_list[my_rank].size());
223 sd_exchange->initializeCommunicationsMessages();
228 m_indexes_to_recv.resize(nb_send);
229 m_ranks_to_recv.resize(nb_send);
230 for(
Integer i=0; i<nb_send; ++i ){
232 ISerializeMessage* send_msg = sd_exchange->messageToSend(i);
233 Int32 dest_rank = send_sd[i];
234 ISerializer* serializer = send_msg->serializer();
235 m_indexes_to_recv[i] = own_indexes_list[dest_rank];
236 m_ranks_to_recv[i] = dest_rank;
237 serializer->setMode(ISerializer::ModeReserve);
239 serializer->reserveArray(indexes_list[dest_rank]);
241 serializer->allocateBuffer();
244 serializer->putArray(indexes_list[dest_rank]);
246 Integer nb_to_send = indexes_list[dest_rank].size();
247 for (
Integer z = 0; z < nb_to_send; ++z) {
248 Integer index = indexes_list[dest_rank][z];
249 info() <<
" SEND Z=" << z <<
" RANK=" << dest_rank <<
" index=" << index;
253 sd_exchange->processExchange();
255 ConstArrayView<Int32> recv_sd = sd_exchange->receiverRanks();
256 const Int32 nb_recv = recv_sd.size();
257 m_indexes_to_send.resize(nb_recv);
258 m_ranks_to_send.resize(nb_recv);
259 for(
Integer i=0; i<nb_recv; ++i ){
261 ISerializeMessage* recv_msg = sd_exchange->messageToReceive(i);
262 Int32 orig_rank = recv_sd[i];
263 ISerializer* serializer = recv_msg->serializer();
265 Int32Array& recv_indexes = m_indexes_to_send[i];
266 m_ranks_to_send[i] = orig_rank;
267 serializer->getArray(recv_indexes);
268 const Int32 nb_to_recv = recv_indexes.
size();
270 for(
Integer z=0; z<nb_to_recv; ++z ){
271 Int32 index = recv_indexes[z];
274 recv_indexes[z] = local_ids[index];
281 const Int32 nb_local = m_local_indexes_to_send.size();
282 for (
Int32 z = 0; z < nb_local; ++z) {
283 Int32 index = indexes_list[my_rank][z];
286 m_local_indexes_to_send[z] = local_ids[index];
296Ref<IData> ParallelDataWriter::Impl::
297getSortedValues(IData* data)
299 IParallelMng* pm = m_parallel_mng;
300 Ref<IData> sorted_data = data->cloneEmptyRef();
303 for (
Int32 rank_to_send : m_ranks_to_send)
304 sd_exchange->addSender(rank_to_send);
306 UniqueArray<Int32> ranks_to_recv2;
307 for (
Int32 rank_to_receive : m_ranks_to_recv)
308 ranks_to_recv2.add(rank_to_receive);
310 sd_exchange->initializeCommunicationsMessages(ranks_to_recv2);
313 for(
Integer i=0; i<nb_send; ++i ){
315 ISerializeMessage* send_msg = sd_exchange->messageToSend(i);
317 ISerializer* serializer = send_msg->serializer();
318 serializer->setMode(ISerializer::ModeReserve);
319 data->serialize(serializer,m_indexes_to_send[i],0);
320 serializer->allocateBuffer();
322 data->serialize(serializer,m_indexes_to_send[i],0);
325 sd_exchange->processExchange();
329 sorted_data->resize(m_nb_item);
330 for(
Integer i=0; i<nb_recv; ++i ){
332 ISerializeMessage* recv_msg = sd_exchange->messageToReceive(i);
334 ISerializer* serializer = recv_msg->serializer();
336 sorted_data->serialize(serializer,m_indexes_to_recv[i],0);
341 ConstArrayView<Int32> local_recv_indexes = m_local_indexes_to_recv;
342 const Int32 nb_local_index = local_recv_indexes.size();
343 if (nb_local_index>0){
344 SerializeBuffer sbuf;
345 sbuf.setMode(ISerializer::ModeReserve);
346 data->serialize(&sbuf, m_local_indexes_to_send,
nullptr);
347 sbuf.allocateBuffer();
349 data->serialize(&sbuf, m_local_indexes_to_send,
nullptr);
351 sorted_data->serialize(&sbuf, local_recv_indexes,
nullptr);
363Ref<ParallelDataWriter> ParallelDataWriterList::
364getOrCreateWriter(
const ItemGroup& group)
366 auto i = m_data_writers.find(group);
367 if (i != m_data_writers.end())
369 IParallelMng* pm = group.itemFamily()->parallelMng();
370 Ref<ParallelDataWriter> writer =
makeRef(
new ParallelDataWriter(pm));
373 ItemGroup own_group = group.own();
374 MeshUtils::fillUniqueIds(own_group.view(), items_uid);
376 writer->sort(local_ids, items_uid);
378 m_data_writers.try_emplace(group, writer);
Fonctions utilitaires sur le maillage.
Integer size() const
Nombre d'éléments du vecteur.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Interface du gestionnaire de parallélisme pour un sous-domaine.
@ ModePut
Le sérialiseur attend des reserve()
@ ModeGet
Le sérialiseur attend des get()
UniqueArray< Int32 > m_ranks_to_recv
Tableau indiquant les rangs des process auxquels on envoie des infos.
UniqueArray< Int32 > m_ranks_to_send
Tableau indiquant les rangs des process dont on recoit des infos.
Référence à une instance.
TraceAccessor(ITraceMng *m)
Construit un accesseur via le gestionnaire de trace m.
Vecteur 1D de données avec sémantique par valeur (style STL).
__host__ __device__ Real2 min(Real2 a, Real2 b)
Retourne le minimum de deux Real2.
Ref< IParallelExchanger > createExchangerRef(IParallelMng *pm)
Retourne une interface pour transférer des messages entre rangs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
Array< Int32 > Int32Array
Tableau dynamique à une dimension d'entiers 32 bits.
std::int32_t Int32
Type entier signé sur 32 bits.