Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
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/* Implementation of messages in shared memory. */
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
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
41template <class Type>
43
44namespace impl
45{
46 template <typename DataType>
48 {
49 public:
50
51 void resize(Int64 n)
52 {
53 all_dispatchs.resize(n);
54 all_dispatchs_base.resize(n);
55 }
56
57 public:
58
61 };
62} // namespace impl
63
64/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
66
67template <typename DataType>
69{
70 public:
71
73};
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
79: public ArcaneDataTypeContainer<ThreadDispatcherContainerTraits>
80{
81 public:
82
85 {
86 public:
87
89 };
90
91 public:
92
93 void resize(Integer n)
94 {
95 m_char.resize(n);
96 m_signed_char.resize(n);
97 m_unsigned_char.resize(n);
98 m_short.resize(n);
99 m_unsigned_short.resize(n);
100 m_int.resize(n);
101 m_unsigned_int.resize(n);
102 m_long.resize(n);
103 m_unsigned_long.resize(n);
104 m_long_long.resize(n);
105 m_unsigned_long_long.resize(n);
106 m_float.resize(n);
107 m_double.resize(n);
108 m_long_double.resize(n);
109 m_apreal.resize(n);
110 m_real2.resize(n);
111 m_real3.resize(n);
112 m_real2x2.resize(n);
113 m_real3x3.resize(n);
114 m_hpreal.resize(n);
115 }
116
117 public:
118
119 CreateSubParallelMngInfo m_create_sub_parallel_mng_info;
120};
121
122/*---------------------------------------------------------------------------*/
123/*---------------------------------------------------------------------------*/
124
128class SharedMemoryParallelDispatchBase
129: public TraceAccessor
131{
133
134 protected:
135
136 template <typename DataType> friend class SharedMemoryParallelDispatch;
137 using Request = Parallel::Request;
138 using PointToPointMessageInfo = Parallel::PointToPointMessageInfo;
139 using MessageRank = Parallel::MessageRank;
140 using MessageTag = Parallel::MessageTag;
141
142 protected:
143
145 {
146 public:
147
148 virtual ~IResizableArray() = default;
149
150 public:
151
152 virtual void resize(Int64 new_size) = 0;
153 virtual MutableMemoryView memoryView() const = 0;
154 };
155
157 {
158 public:
159
160 ConstMemoryView send_buf;
161 Span<const Int32> send_count;
162 Span<const Int32> send_index;
163 MutableMemoryView recv_buf;
164 Span<const Int32> recv_count;
165 Span<const Int32> recv_index;
166 };
167
168 protected:
169
170 SharedMemoryParallelDispatchBase(ITraceMng* tm, SharedMemoryParallelMng* parallel_mng,
171 ISharedMemoryMessageQueue* message_queue,
173
174 protected:
175
176 void _genericAllToAll(ConstMemoryView send_buf, MutableMemoryView recv_buf, Int32 count);
177 void _genericAllGather(ConstMemoryView send_buf, MutableMemoryView recv_buf);
178 void _genericAllGatherVariable(ConstMemoryView send_buf, IResizableArray* recv_buf);
179 void _genericAllToAllVariable(ConstMemoryView send_buf,
180 Span<const Int32> send_count, Span<const Int32> send_index,
181 MutableMemoryView recv_buf,
182 Span<const Int32> recv_count, Span<const Int32> recv_index);
183 void _genericScatterVariable(ConstMemoryView send_buf, MutableMemoryView recv_buf, Int32 root);
184 Request _genericSend(ConstMemoryView send_buffer, const PointToPointMessageInfo& message2);
185 Request _genericReceive(MutableMemoryView recv_buffer, const PointToPointMessageInfo& message2);
186 void _genericBroadcast(MutableMemoryView send_buf, Int32 rank);
187
188 protected:
189
190 // Accessible par 'SharedMemoryParallelDispatch'
191 ConstMemoryView m_const_view;
192 MutableMemoryView m_recv_view;
193 ConstMemoryView m_send_view;
194
195 private:
196
197 MutableMemoryView m_broadcast_view;
198
199 protected:
200
201 SharedMemoryParallelMng* m_parallel_mng = nullptr;
202 Int32 m_rank = -1;
203 Int32 m_nb_rank = 0;
204 ISharedMemoryMessageQueue* m_message_queue = nullptr;
205
206 protected:
207
208 void _collectiveBarrier();
209
210 private:
211
212 AllToAllVariableInfo m_alltoallv_infos;
214};
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
222template <class Type>
223class SharedMemoryParallelDispatch
224: public SharedMemoryParallelDispatchBase
225, public IParallelDispatchT<Type>
226, public ITypeDispatcher<Type>
227{
228 using BaseClass = SharedMemoryParallelDispatchBase;
229
230 class ResizableArrayRef : public IResizableArray
231 {
232 public:
233
234 explicit ResizableArrayRef(Array<Type>& v)
235 : m_array_ref(v)
236 {}
237
238 public:
239
240 void resize(Int64 new_size) override { m_array_ref.resize(new_size); }
241 MutableMemoryView memoryView() const override { return MutableMemoryView(m_array_ref.span()); }
242
243 private:
244
245 Array<Type>& m_array_ref;
246 };
247
249 {
250 public:
251
252 Span<const Type> reduce_buf;
253 Type reduce_value;
254 int m_index;
255 };
256
257 private:
258
260 {
261 public:
262
263 Int32 m_min_rank;
264 Int32 m_max_rank;
265 Type m_min_value;
266 Type m_max_value;
267 Type m_sum_value;
268 };
269
270 public:
271
272 using Request = Parallel::Request;
273 using PointToPointMessageInfo = Parallel::PointToPointMessageInfo;
274 using MessageRank = Parallel::MessageRank;
275 using MessageTag = Parallel::MessageTag;
276 typedef Parallel::eReduceType eReduceType;
277
278 public:
279
280 SharedMemoryParallelDispatch(ITraceMng* tm, SharedMemoryParallelMng* parallel_mng,
281 ISharedMemoryMessageQueue* message_queue,
283 ~SharedMemoryParallelDispatch() override;
284 void finalize() override;
285
286 public:
287
289 void broadcast(Span<Type> send_buf, Int32 sub_domain) override;
290 void allGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
291 void allGatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf) override;
292 void gather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
293 void gatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf, Int32 rank) override;
294 void scatterVariable(Span<const Type> send_buf, Span<Type> recv_buf, Int32 root) override;
295 void allReduce(eReduceType op, Span<Type> send_and_receive_buf) override;
296 void allReduce(eReduceType op, Span<const Type> send_buf, Span<Type> receive_buf) override;
297 void allToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
298 void allToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
299 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
300 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
301 Request send(Span<const Type> send_buffer, Int32 proc, bool is_blocked) override;
302 Request send(Span<const Type> send_buffer, const PointToPointMessageInfo& message) override;
303 Request receive(Span<Type> recv_buffer, Int32 rank, bool is_blocked) override;
304 Request receive(Span<Type> recv_buffer, const PointToPointMessageInfo& message) override;
305 Request nonBlockingAllReduce(eReduceType op, Span<const Type> send_buf, Span<Type> recv_buf) override;
306 Request nonBlockingAllGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
307 Request nonBlockingBroadcast(Span<Type> send_buf, Int32 rank) override;
308 Request nonBlockingGather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
309 Request nonBlockingAllToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
310 Request nonBlockingAllToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
311 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
312 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
313 Request gather(Arccore::MessagePassing::GatherMessageInfo<Type>&) override;
315
316 void broadcast(ArrayView<Type> send_buf, Integer sub_domain) override
317 {
318 this->broadcast(Span<Type>(send_buf), sub_domain);
319 }
320 void allGather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf) override
321 {
322 this->allGather(Span<const Type>(send_buf), Span<Type>(recv_buf));
323 }
324 void allGatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf) override
325 {
326 this->allGatherVariable(Span<const Type>(send_buf), recv_buf);
327 }
328 void gather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer rank) override
329 {
330 this->gather(Span<const Type>(send_buf), Span<Type>(recv_buf), rank);
331 }
332 void gatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf, Integer rank) override
333 {
334 this->gatherVariable(Span<const Type>(send_buf), recv_buf, rank);
335 }
336 void scatterVariable(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer root) override
337 {
338 this->scatterVariable(Span<const Type>(send_buf), Span<Type>(recv_buf), root);
339 }
340 void allToAll(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer count) override
341 {
342 this->allToAll(Span<const Type>(send_buf), Span<Type>(recv_buf), count);
343 }
344 void allToAllVariable(ConstArrayView<Type> send_buf, Int32ConstArrayView send_count,
345 Int32ConstArrayView send_index, ArrayView<Type> recv_buf,
346 Int32ConstArrayView recv_count, Int32ConstArrayView recv_index) override
347 {
348 this->allToAllVariable(Span<const Type>(send_buf), send_count, send_index,
349 Span<Type>(recv_buf), recv_count, recv_index);
350 }
351 Request send(ConstArrayView<Type> send_buffer, Integer proc, bool is_blocked) override
352 {
353 return this->send(Span<const Type>(send_buffer), proc, is_blocked);
354 }
355 Request recv(ArrayView<Type> recv_buffer, Int32 rank, bool is_blocked) override
356 {
357 return this->receive(Span<Type>(recv_buffer), rank, is_blocked);
358 }
359 void allReduce(eReduceType op, ArrayView<Type> send_buf) override
360 {
361 return this->allReduce(op, Span<Type>(send_buf));
362 }
363 void allReduce(eReduceType op, ConstArrayView<Type> send_buf, ArrayView<Type> receive_buf) override
364 {
365 return this->allReduce(op, Span<const Type>(send_buf), Span<Type>(receive_buf));
366 }
367
368 void send(ConstArrayView<Type> send_buffer, Integer proc) override;
369 void recv(ArrayView<Type> recv_buffer, Integer proc) override;
370 void sendRecv(ConstArrayView<Type> send_buffer, ArrayView<Type> recv_buffer, Integer proc) override;
371 Type allReduce(eReduceType op, Type send_buf) override;
372 Type scan(eReduceType op, Type send_buf) override;
373 void scan(eReduceType op, ArrayView<Type> send_buf) override;
374 void computeMinMaxSum(Type val, Type& min_val, Type& max_val, Type& sum_val,
375 Int32& min_rank,
376 Int32& max_rank) override;
377 void computeMinMaxSum(ConstArrayView<Type> values,
378 ArrayView<Type> min_values,
379 ArrayView<Type> max_values,
380 ArrayView<Type> sum_values,
381 ArrayView<Int32> min_ranks,
382 ArrayView<Int32> max_ranks) override;
383 ITypeDispatcher<Type>* toArccoreDispatcher() override { return this; }
384
385 void waitAll();
386
387 public:
388
389 ArrayView<SharedMemoryParallelDispatch<Type>*> m_all_dispatchs;
390
391 public:
392
393 ReduceInfo m_reduce_infos;
394
395 private:
396
397 void _allReduceOrScan(eReduceType op, Span<const Type> send_buf, Span<Type> receive_buf, bool is_scan);
398};
399
400/*---------------------------------------------------------------------------*/
401/*---------------------------------------------------------------------------*/
402
403} // End namespace Arcane::MessagePassing
404
405/*---------------------------------------------------------------------------*/
406/*---------------------------------------------------------------------------*/
407
408#endif
#define ARCCORE_INTERNAL_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS(OPTIONAL_OVERRIDE)
Container containing an instance of a class per data type Arcane.
Modifiable view of an array of type T.
Base class for 1D data vectors.
Constant view of an array of type T.
Constant view on a contiguous memory region containing fixed-size elements.
Parallel message handling for the type Type.
Brief information for a 'gather' message for data type DataType.
Parallel message handling for the type Type.
Information for sending/receiving a point-to-point message.
Base class common to SharedMemoryParallelDispatch.
Mutable view on a contiguous memory region containing fixed-size elements.
Reference to an instance.
Thread-safe implementation of a reference counter.
View of an array of elements of type T.
Definition Span.h:633
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
1D data vector with value semantics (STL style).
Declarations of types and methods used by message exchange mechanisms.
eReduceType
Supported reduction types.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:476
std::int32_t Int32
Signed integer type of 32 bits.
Type
Type of JSON value.
Definition rapidjson.h:730