Arcane  4.2.3.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
SharedMemoryParallelDispatch.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* SharedMemoryParallelDispatch.h (C) 2000-2026 */
9/* */
10/* Implémentation des messages en mémoire partagée. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_PARALLEL_THREAD_SHAREDMEMORYPARALLELDISPATCH_H
13#define ARCANE_PARALLEL_THREAD_SHAREDMEMORYPARALLELDISPATCH_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/TraceAccessor.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/IThreadBarrier.h"
20#include "arcane/utils/HPReal.h"
21#include "arcane/utils/DataTypeContainer.h"
22#include "arcane/utils/MemoryView.h"
23
24#include "arcane/core/IParallelDispatch.h"
25#include "arcane/core/ISerializer.h"
26
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
33{
34
38template <class Type>
40
41namespace impl
42{
43 template <typename DataType>
45 {
46 public:
47
48 void resize(Int64 n)
49 {
50 all_dispatchs.resize(n);
51 all_dispatchs_base.resize(n);
52 }
53
54 public:
55
58 };
59} // namespace impl
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64template <typename DataType>
66{
67 public:
68
70};
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
76: public ArcaneDataTypeContainer<ThreadDispatcherContainerTraits>
77{
78 public:
79
82 {
83 public:
84
86 };
87
88 public:
89
90 void resize(Integer n)
91 {
92 m_char.resize(n);
93 m_signed_char.resize(n);
94 m_unsigned_char.resize(n);
95 m_short.resize(n);
96 m_unsigned_short.resize(n);
97 m_int.resize(n);
98 m_unsigned_int.resize(n);
99 m_long.resize(n);
100 m_unsigned_long.resize(n);
101 m_long_long.resize(n);
102 m_unsigned_long_long.resize(n);
103 m_float.resize(n);
104 m_double.resize(n);
105 m_long_double.resize(n);
106 m_apreal.resize(n);
107 m_real2.resize(n);
108 m_real3.resize(n);
109 m_real2x2.resize(n);
110 m_real3x3.resize(n);
111 m_hpreal.resize(n);
112 }
113
114 public:
115
116 CreateSubParallelMngInfo m_create_sub_parallel_mng_info;
117};
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
124class SharedMemoryParallelDispatchBase
125: public TraceAccessor
127{
129 protected:
130
131 template <typename DataType> friend class SharedMemoryParallelDispatch;
132 using Request = Parallel::Request;
133 using PointToPointMessageInfo = Parallel::PointToPointMessageInfo;
134 using MessageRank = Parallel::MessageRank;
135 using MessageTag = Parallel::MessageTag;
136
137 protected:
138
140 {
141 public:
142
143 virtual ~IResizableArray() = default;
144
145 public:
146
147 virtual void resize(Int64 new_size) = 0;
148 virtual MutableMemoryView memoryView() const = 0;
149 };
150
152 {
153 public:
154
155 ConstMemoryView send_buf;
156 Span<const Int32> send_count;
157 Span<const Int32> send_index;
158 MutableMemoryView recv_buf;
159 Span<const Int32> recv_count;
160 Span<const Int32> recv_index;
161 };
162
163 protected:
164
165 SharedMemoryParallelDispatchBase(ITraceMng* tm, SharedMemoryParallelMng* parallel_mng,
166 ISharedMemoryMessageQueue* message_queue,
168
169 protected:
170
171 void _genericAllToAll(ConstMemoryView send_buf, MutableMemoryView recv_buf, Int32 count);
172 void _genericAllGather(ConstMemoryView send_buf, MutableMemoryView recv_buf);
173 void _genericAllGatherVariable(ConstMemoryView send_buf, IResizableArray* recv_buf);
174 void _genericAllToAllVariable(ConstMemoryView send_buf,
175 Span<const Int32> send_count, Span<const Int32> send_index,
176 MutableMemoryView recv_buf,
177 Span<const Int32> recv_count, Span<const Int32> recv_index);
178 void _genericScatterVariable(ConstMemoryView send_buf, MutableMemoryView recv_buf, Int32 root);
179 Request _genericSend(ConstMemoryView send_buffer, const PointToPointMessageInfo& message2);
180 Request _genericReceive(MutableMemoryView recv_buffer, const PointToPointMessageInfo& message2);
181 void _genericBroadcast(MutableMemoryView send_buf, Int32 rank);
182
183 protected:
184
185 // Accessible par 'SharedMemoryParallelDispatch'
186 ConstMemoryView m_const_view;
187 MutableMemoryView m_recv_view;
188 ConstMemoryView m_send_view;
189
190 private:
191
192 MutableMemoryView m_broadcast_view;
193
194 protected:
195
196 SharedMemoryParallelMng* m_parallel_mng = nullptr;
197 Int32 m_rank = -1;
198 Int32 m_nb_rank = 0;
199 ISharedMemoryMessageQueue* m_message_queue = nullptr;
200
201 protected:
202
203 void _collectiveBarrier();
204
205 private:
206
207 AllToAllVariableInfo m_alltoallv_infos;
209};
210
211/*---------------------------------------------------------------------------*/
212/*---------------------------------------------------------------------------*/
216template <class Type>
217class SharedMemoryParallelDispatch
218: public SharedMemoryParallelDispatchBase
219, public IParallelDispatchT<Type>
220, public ITypeDispatcher<Type>
221{
222 using BaseClass = SharedMemoryParallelDispatchBase;
223
224 class ResizableArrayRef : public IResizableArray
225 {
226 public:
227
228 explicit ResizableArrayRef(Array<Type>& v)
229 : m_array_ref(v)
230 {}
231
232 public:
233
234 void resize(Int64 new_size) override { m_array_ref.resize(new_size); }
235 MutableMemoryView memoryView() const override { return MutableMemoryView(m_array_ref.span()); }
236
237 private:
238
239 Array<Type>& m_array_ref;
240 };
241
243 {
244 public:
245
246 Span<const Type> reduce_buf;
247 Type reduce_value;
248 int m_index;
249 };
250
251 private:
252
254 {
255 public:
256
257 Int32 m_min_rank;
258 Int32 m_max_rank;
259 Type m_min_value;
260 Type m_max_value;
261 Type m_sum_value;
262 };
263
264 public:
265
266 using Request = Parallel::Request;
267 using PointToPointMessageInfo = Parallel::PointToPointMessageInfo;
268 using MessageRank = Parallel::MessageRank;
269 using MessageTag = Parallel::MessageTag;
270 typedef Parallel::eReduceType eReduceType;
271
272 public:
273
274 SharedMemoryParallelDispatch(ITraceMng* tm, SharedMemoryParallelMng* parallel_mng,
275 ISharedMemoryMessageQueue* message_queue,
277 ~SharedMemoryParallelDispatch() override;
278 void finalize() override;
279
280 public:
281
283 void broadcast(Span<Type> send_buf, Int32 sub_domain) override;
284 void allGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
285 void allGatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf) override;
286 void gather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
287 void gatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf, Int32 rank) override;
288 void scatterVariable(Span<const Type> send_buf, Span<Type> recv_buf, Int32 root) override;
289 void allReduce(eReduceType op, Span<Type> send_and_receive_buf) override;
290 void allReduce(eReduceType op, Span<const Type> send_buf, Span<Type> receive_buf) override;
291 void allToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
292 void allToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
293 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
294 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
295 Request send(Span<const Type> send_buffer, Int32 proc, bool is_blocked) override;
296 Request send(Span<const Type> send_buffer, const PointToPointMessageInfo& message) override;
297 Request receive(Span<Type> recv_buffer, Int32 rank, bool is_blocked) override;
298 Request receive(Span<Type> recv_buffer, const PointToPointMessageInfo& message) override;
299 Request nonBlockingAllReduce(eReduceType op, Span<const Type> send_buf, Span<Type> recv_buf) override;
300 Request nonBlockingAllGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
301 Request nonBlockingBroadcast(Span<Type> send_buf, Int32 rank) override;
302 Request nonBlockingGather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
303 Request nonBlockingAllToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
304 Request nonBlockingAllToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
305 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
306 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
307 Request gather(Arccore::MessagePassing::GatherMessageInfo<Type>&) override;
309
310 void broadcast(ArrayView<Type> send_buf, Integer sub_domain) override
311 {
312 this->broadcast(Span<Type>(send_buf), sub_domain);
313 }
314 void allGather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf) override
315 {
316 this->allGather(Span<const Type>(send_buf), Span<Type>(recv_buf));
317 }
318 void allGatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf) override
319 {
320 this->allGatherVariable(Span<const Type>(send_buf), recv_buf);
321 }
322 void gather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer rank) override
323 {
324 this->gather(Span<const Type>(send_buf), Span<Type>(recv_buf), rank);
325 }
326 void gatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf, Integer rank) override
327 {
328 this->gatherVariable(Span<const Type>(send_buf), recv_buf, rank);
329 }
330 void scatterVariable(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer root) override
331 {
332 this->scatterVariable(Span<const Type>(send_buf), Span<Type>(recv_buf), root);
333 }
334 void allToAll(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer count) override
335 {
336 this->allToAll(Span<const Type>(send_buf), Span<Type>(recv_buf), count);
337 }
338 void allToAllVariable(ConstArrayView<Type> send_buf, Int32ConstArrayView send_count,
339 Int32ConstArrayView send_index, ArrayView<Type> recv_buf,
340 Int32ConstArrayView recv_count, Int32ConstArrayView recv_index) override
341 {
342 this->allToAllVariable(Span<const Type>(send_buf), send_count, send_index,
343 Span<Type>(recv_buf), recv_count, recv_index);
344 }
345 Request send(ConstArrayView<Type> send_buffer, Integer proc, bool is_blocked) override
346 {
347 return this->send(Span<const Type>(send_buffer), proc, is_blocked);
348 }
349 Request recv(ArrayView<Type> recv_buffer, Int32 rank, bool is_blocked) override
350 {
351 return this->receive(Span<Type>(recv_buffer), rank, is_blocked);
352 }
353 void allReduce(eReduceType op, ArrayView<Type> send_buf) override
354 {
355 return this->allReduce(op, Span<Type>(send_buf));
356 }
357 void allReduce(eReduceType op, ConstArrayView<Type> send_buf, ArrayView<Type> receive_buf) override
358 {
359 return this->allReduce(op, Span<const Type>(send_buf), Span<Type>(receive_buf));
360 }
361
362 void send(ConstArrayView<Type> send_buffer, Integer proc) override;
363 void recv(ArrayView<Type> recv_buffer, Integer proc) override;
364 void sendRecv(ConstArrayView<Type> send_buffer, ArrayView<Type> recv_buffer, Integer proc) override;
365 Type allReduce(eReduceType op, Type send_buf) override;
366 Type scan(eReduceType op, Type send_buf) override;
367 void scan(eReduceType op, ArrayView<Type> send_buf) override;
368 void computeMinMaxSum(Type val, Type& min_val, Type& max_val, Type& sum_val,
369 Int32& min_rank,
370 Int32& max_rank) override;
371 void computeMinMaxSum(ConstArrayView<Type> values,
372 ArrayView<Type> min_values,
373 ArrayView<Type> max_values,
374 ArrayView<Type> sum_values,
375 ArrayView<Int32> min_ranks,
376 ArrayView<Int32> max_ranks) override;
377 ITypeDispatcher<Type>* toArccoreDispatcher() override { return this; }
378
379 void waitAll();
380
381 public:
382
383 ArrayView<SharedMemoryParallelDispatch<Type>*> m_all_dispatchs;
384
385 public:
386
387 ReduceInfo m_reduce_infos;
388
389 private:
390
391 void _allReduceOrScan(eReduceType op, Span<const Type> send_buf, Span<Type> receive_buf, bool is_scan);
392};
393
394/*---------------------------------------------------------------------------*/
395/*---------------------------------------------------------------------------*/
396
397} // End namespace Arcane::MessagePassing
398
399/*---------------------------------------------------------------------------*/
400/*---------------------------------------------------------------------------*/
401
402#endif
403
#define ARCCORE_INTERNAL_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS(OPTIONAL_OVERRIDE)
Conteneur contenant une instance d'une classe par type de donnée Arcane.
Vue modifiable d'un tableau d'un type T.
Tableau d'items de types quelconques.
Vue constante d'un tableau de type T.
Vue constante sur une zone mémoire contigue contenant des éléments de taille fixe.
Gestion des messages parallèles pour le type Type.
Interface du gestionnaire de traces.
Informations pour un message 'gather' pour le type de données DataType.
Interface d'une file de messages avec les threads.
Gestion des messages parallèles pour le type Type.
Informations pour envoyer/recevoir un message point à point.
Requête d'un message.
Definition Request.h:77
Classe de base commune à SharedMemoryParallelDispatch.
Gestionnaire du parallélisme utilisant les threads.
Vue modifiable sur une zone mémoire contigue contenant des éléments de taille fixe.
Référence à une instance.
Implémentation thread-safe d'un compteur de référence.
Vue d'un tableau d'éléments de type T.
Definition Span.h:633
TraceAccessor(ITraceMng *m)
Construit un accesseur via le gestionnaire de trace m.
Vecteur 1D de données avec sémantique par valeur (style STL).
Déclarations des types et méthodes utilisés par les mécanismes d'échange de messages.
eReduceType
Types des réductions supportées.
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.
Definition UtilsTypes.h:480
std::int32_t Int32
Type entier signé sur 32 bits.
Type
Type of JSON value.
Definition rapidjson.h:730