Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
HybridParallelDispatch.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/* HybridParallelDispatch.h (C) 2000-2026 */
9/* */
10/* Implementation of messages in hybrid MPI/Shared Memory mode.. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_PARALLEL_THREAD_HYBRIDPARALLELDISPATCH_H
13#define ARCANE_PARALLEL_THREAD_HYBRIDPARALLELDISPATCH_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/TraceAccessor.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/HPReal.h"
20#include "arcane/utils/DataTypeContainer.h"
21
22#include "arcane/core/IParallelDispatch.h"
23#include "arcane/core/ISerializer.h"
24
25#include "arcane/parallel/thread/ISharedMemoryMessageQueue.h"
26
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane
33{
34template <class Type>
36}
37
39{
40
43template <class Type>
45
46template <typename DataType>
48{
49 public:
50
52};
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
58: public ArcaneDataTypeContainer<MpiThreadDispatcherContainerTraits>
59{
60 public:
61
64 {
65 public:
66
68 };
69
70 public:
71
72 void resize(Integer n)
73 {
74 m_char.resize(n);
75 m_signed_char.resize(n);
76 m_unsigned_char.resize(n);
77 m_short.resize(n);
78 m_unsigned_short.resize(n);
79 m_int.resize(n);
80 m_unsigned_int.resize(n);
81 m_long.resize(n);
82 m_unsigned_long.resize(n);
83 m_long_long.resize(n);
84 m_unsigned_long_long.resize(n);
85 m_float.resize(n);
86 m_double.resize(n);
87 m_long_double.resize(n);
88 m_apreal.resize(n);
89 m_real2.resize(n);
90 m_real3.resize(n);
91 m_real2x2.resize(n);
92 m_real3x3.resize(n);
93 m_hpreal.resize(n);
94 }
95
96 public:
97
98 CreateSubParallelMngInfo m_create_sub_parallel_mng_info;
99};
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
107template <class Type>
108class HybridParallelDispatch
109: public TraceAccessor
110, public IParallelDispatchT<Type>
112, public ITypeDispatcher<Type>
113{
115
117 {
118 public:
119
120 Span<const Type> send_buf;
121 Int32ConstArrayView send_count;
122 Int32ConstArrayView send_index;
123 Span<Type> recv_buf;
124 Int32ConstArrayView recv_count;
125 Int32ConstArrayView recv_index;
126 };
127
129 {
130 public:
131
132 Span<const Type> send_buf;
133 Span<Type> reduce_buf_span;
134 Type reduce_value;
135 int m_index;
136 };
137
138 private:
139
141 {
142 public:
143
144 Int32 m_min_rank = A_NULL_RANK;
145 Int32 m_max_rank = A_NULL_RANK;
146 Type m_min_value = Type();
147 Type m_max_value = Type();
148 Type m_sum_value = Type();
149 };
150
151 public:
152
153 HybridParallelDispatch(ITraceMng* tm, HybridParallelMng* parallel_mng, HybridMessageQueue* message_queue,
154 ArrayView<HybridParallelDispatch<Type>*> all_dispatchs);
155 ~HybridParallelDispatch() override;
156 void finalize() override;
157
158 public:
159
160 using ITypeDispatcher<Type>::gather;
161
162 public:
163
165 void broadcast(Span<Type> send_buf, Int32 sub_domain) override;
166 void allGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
167 void allGatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf) override;
168 void gather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
169 void gatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf, Int32 rank) override;
170 void scatterVariable(Span<const Type> send_buf, Span<Type> recv_buf, Int32 root) override;
171 void allReduce(eReduceType op, Span<Type> send_buf) override;
172 void allReduce(eReduceType op, Span<const Type> send_buf, Span<Type> receive_buf) override;
173 void allToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
174 void allToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
175 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
176 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
177 Request send(Span<const Type> send_buffer, Int32 proc, bool is_blocked) override;
178 Request send(Span<const Type> send_buffer, const PointToPointMessageInfo& message) override;
179 Request receive(Span<Type> recv_buffer, Int32 rank, bool is_blocked) override;
180 Request receive(Span<Type> recv_buffer, const PointToPointMessageInfo& message) override;
181 Request nonBlockingAllReduce(eReduceType op, Span<const Type> send_buf, Span<Type> recv_buf) override;
182 Request nonBlockingAllGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
183 Request nonBlockingBroadcast(Span<Type> send_buf, Int32 rank) override;
184 Request nonBlockingGather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
185 Request nonBlockingAllToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
186 Request nonBlockingAllToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
187 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
188 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
189 Request gather(Arccore::MessagePassing::GatherMessageInfo<Type>&) override;
191
192 void broadcast(ArrayView<Type> send_buf, Integer sub_domain) override
193 {
194 this->broadcast(Span<Type>(send_buf), sub_domain);
195 }
196 void allGather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf) override
197 {
198 this->allGather(Span<const Type>(send_buf), Span<Type>(recv_buf));
199 }
200 void allGatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf) override
201 {
202 this->allGatherVariable(Span<const Type>(send_buf), recv_buf);
203 }
204 void gather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer rank) override
205 {
206 this->gather(Span<const Type>(send_buf), Span<Type>(recv_buf), rank);
207 }
208 void gatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf, Integer rank) override
209 {
210 this->gatherVariable(Span<const Type>(send_buf), recv_buf, rank);
211 }
212 void scatterVariable(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer root) override
213 {
214 this->scatterVariable(Span<const Type>(send_buf), Span<Type>(recv_buf), root);
215 }
216 void allToAll(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer count) override
217 {
218 this->allToAll(Span<const Type>(send_buf), Span<Type>(recv_buf), count);
219 }
220 void allToAllVariable(ConstArrayView<Type> send_buf, Int32ConstArrayView send_count,
221 Int32ConstArrayView send_index, ArrayView<Type> recv_buf,
222 Int32ConstArrayView recv_count, Int32ConstArrayView recv_index) override
223 {
224 this->allToAllVariable(Span<const Type>(send_buf), send_count, send_index,
225 Span<Type>(recv_buf), recv_count, recv_index);
226 }
227 Request send(ConstArrayView<Type> send_buffer, Integer proc, bool is_blocked) override
228 {
229 return this->send(Span<const Type>(send_buffer), proc, is_blocked);
230 }
231 Request recv(ArrayView<Type> recv_buffer, Integer proc, bool is_blocked) override
232 {
233 return this->receive(Span<Type>(recv_buffer), proc, is_blocked);
234 }
235 void allReduce(eReduceType op, ArrayView<Type> send_buf) override
236 {
237 return this->allReduce(op, Span<Type>(send_buf));
238 }
239 void allReduce(eReduceType op, ConstArrayView<Type> send_buf, ArrayView<Type> receive_buf) override
240 {
241 return this->allReduce(op, Span<const Type>(send_buf), Span<Type>(receive_buf));
242 }
243
244 void send(ConstArrayView<Type> send_buffer, Integer proc) override;
245 void recv(ArrayView<Type> recv_buffer, Integer proc) override;
246 void sendRecv(ConstArrayView<Type> send_buffer, ArrayView<Type> recv_buffer, Integer proc) override;
247 Type allReduce(eReduceType op, Type send_buf) override;
248 Type scan(eReduceType op, Type send_buf) override;
249 void scan(eReduceType op, ArrayView<Type> send_buf) override;
250 void computeMinMaxSum(Type val, Type& min_val, Type& max_val, Type& sum_val,
251 Int32& min_rank,
252 Int32& max_rank) override;
253 void computeMinMaxSum(ConstArrayView<Type> values,
254 ArrayView<Type> min_values,
255 ArrayView<Type> max_values,
256 ArrayView<Type> sum_values,
257 ArrayView<Int32> min_ranks,
258 ArrayView<Int32> max_ranks) override;
259 ITypeDispatcher<Type>* toArccoreDispatcher() override { return this; }
260
261 private:
262
263 HybridParallelMng* m_parallel_mng = nullptr;
264 Int32 m_local_rank = A_NULL_RANK;
265 Int32 m_local_nb_rank = 0;
266 Int32 m_global_rank = A_NULL_RANK;
267 Int32 m_global_nb_rank = 0;
268 Int32 m_mpi_rank = A_NULL_RANK;
269 Int32 m_mpi_nb_rank = 0;
270
271 public:
272
273 using AllDispatchView = ArrayView<HybridParallelDispatch<Type>*>;
274 Int32 globalRank() const { return m_global_rank; }
275 AllDispatchView m_all_dispatchs;
276
277 private:
278
279 Span<Type> m_broadcast_view;
280 Span<const Type> m_const_view;
281 Span<Type> m_recv_view;
282 Span<const Type> m_send_view;
283 AllToAllVariableInfo m_alltoallv_infos;
284
285 public:
286
287 ReduceInfo m_reduce_infos;
288 MinMaxSumInfo m_min_max_sum_infos;
289
290 private:
291
292 HybridMessageQueue* m_message_queue = nullptr;
293 MpiParallelDispatchT<Type>* m_mpi_dispatcher = nullptr;
294
295 private:
296
297 void _collectiveBarrier();
298 void _allReduceOrScan(eReduceType op, Span<const Type> send_buf, Span<Type> receive_buf, bool is_scan);
299 void _applyReduceOperator(eReduceType op, Span<Type> result, AllDispatchView dispatch_view,
300 Int32 first_rank, Int32 last_rank);
301};
302
303/*---------------------------------------------------------------------------*/
304/*---------------------------------------------------------------------------*/
305
306} // End namespace Arcane::MessagePassing
307
308/*---------------------------------------------------------------------------*/
309/*---------------------------------------------------------------------------*/
310
311#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.
Parallel message handling for the type Type.
Brief information for a 'gather' message for data type DataType.
Interface for a message queue with threads.
Thread-based parallelism manager.
Parallel message handling for the type Type.
Message interface for type Type.
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.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
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