Arcane  4.1.12.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-2024 */
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<Type> reduce_buf_span;
133 Type reduce_value;
134 int m_index;
135 };
136
137 private:
138
140 {
141 public:
142
143 Int32 m_min_rank = A_NULL_RANK;
144 Int32 m_max_rank = A_NULL_RANK;
145 Type m_min_value = Type();
146 Type m_max_value = Type();
147 Type m_sum_value = Type();
148 };
149
150 public:
151
152 HybridParallelDispatch(ITraceMng* tm, HybridParallelMng* parallel_mng, HybridMessageQueue* message_queue,
153 ArrayView<HybridParallelDispatch<Type>*> all_dispatchs);
154 ~HybridParallelDispatch() override;
155 void finalize() override;
156
157 public:
158
159 using ITypeDispatcher<Type>::gather;
160
161 public:
162
164 void broadcast(Span<Type> send_buf, Int32 sub_domain) override;
165 void allGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
166 void allGatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf) override;
167 void gather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
168 void gatherVariable(Span<const Type> send_buf, Array<Type>& recv_buf, Int32 rank) override;
169 void scatterVariable(Span<const Type> send_buf, Span<Type> recv_buf, Int32 root) override;
170 void allReduce(eReduceType op, Span<Type> send_buf) override;
171 void allToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
172 void allToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
173 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
174 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
175 Request send(Span<const Type> send_buffer, Int32 proc, bool is_blocked) override;
176 Request send(Span<const Type> send_buffer, const PointToPointMessageInfo& message) override;
177 Request receive(Span<Type> recv_buffer, Int32 rank, bool is_blocked) override;
178 Request receive(Span<Type> recv_buffer, const PointToPointMessageInfo& message) override;
179 Request nonBlockingAllReduce(eReduceType op, Span<const Type> send_buf, Span<Type> recv_buf) override;
180 Request nonBlockingAllGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
181 Request nonBlockingBroadcast(Span<Type> send_buf, Int32 rank) override;
182 Request nonBlockingGather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
183 Request nonBlockingAllToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
184 Request nonBlockingAllToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
185 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
186 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
187 Request gather(Arccore::MessagePassing::GatherMessageInfo<Type>&) override;
189
190 void broadcast(ArrayView<Type> send_buf, Integer sub_domain) override
191 {
192 this->broadcast(Span<Type>(send_buf), sub_domain);
193 }
194 void allGather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf) override
195 {
196 this->allGather(Span<const Type>(send_buf), Span<Type>(recv_buf));
197 }
198 void allGatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf) override
199 {
200 this->allGatherVariable(Span<const Type>(send_buf), recv_buf);
201 }
202 void gather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer rank) override
203 {
204 this->gather(Span<const Type>(send_buf), Span<Type>(recv_buf), rank);
205 }
206 void gatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf, Integer rank) override
207 {
208 this->gatherVariable(Span<const Type>(send_buf), recv_buf, rank);
209 }
210 void scatterVariable(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer root) override
211 {
212 this->scatterVariable(Span<const Type>(send_buf), Span<Type>(recv_buf), root);
213 }
214 void allToAll(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer count) override
215 {
216 this->allToAll(Span<const Type>(send_buf), Span<Type>(recv_buf), count);
217 }
218 void allToAllVariable(ConstArrayView<Type> send_buf, Int32ConstArrayView send_count,
219 Int32ConstArrayView send_index, ArrayView<Type> recv_buf,
220 Int32ConstArrayView recv_count, Int32ConstArrayView recv_index) override
221 {
222 this->allToAllVariable(Span<const Type>(send_buf), send_count, send_index,
223 Span<Type>(recv_buf), recv_count, recv_index);
224 }
225 Request send(ConstArrayView<Type> send_buffer, Integer proc, bool is_blocked) override
226 {
227 return this->send(Span<const Type>(send_buffer), proc, is_blocked);
228 }
229 Request recv(ArrayView<Type> recv_buffer, Integer proc, bool is_blocked) override
230 {
231 return this->receive(Span<Type>(recv_buffer), proc, is_blocked);
232 }
233 void allReduce(eReduceType op, ArrayView<Type> send_buf) override
234 {
235 return this->allReduce(op, Span<Type>(send_buf));
236 }
237
238 void send(ConstArrayView<Type> send_buffer, Integer proc) override;
239 void recv(ArrayView<Type> recv_buffer, Integer proc) override;
240 void sendRecv(ConstArrayView<Type> send_buffer, ArrayView<Type> recv_buffer, Integer proc) override;
241 Type allReduce(eReduceType op, Type send_buf) override;
242 Type scan(eReduceType op, Type send_buf) override;
243 void scan(eReduceType op, ArrayView<Type> send_buf) override;
244 void computeMinMaxSum(Type val, Type& min_val, Type& max_val, Type& sum_val,
245 Int32& min_rank,
246 Int32& max_rank) override;
247 void computeMinMaxSum(ConstArrayView<Type> values,
248 ArrayView<Type> min_values,
249 ArrayView<Type> max_values,
250 ArrayView<Type> sum_values,
251 ArrayView<Int32> min_ranks,
252 ArrayView<Int32> max_ranks) override;
253 ITypeDispatcher<Type>* toArccoreDispatcher() override { return this; }
254
255 private:
256
257 HybridParallelMng* m_parallel_mng = nullptr;
258 Int32 m_local_rank = A_NULL_RANK;
259 Int32 m_local_nb_rank = 0;
260 Int32 m_global_rank = A_NULL_RANK;
261 Int32 m_global_nb_rank = 0;
262 Int32 m_mpi_rank = A_NULL_RANK;
263 Int32 m_mpi_nb_rank = 0;
264
265 public:
266
267 using AllDispatchView = ArrayView<HybridParallelDispatch<Type>*>;
268 Int32 globalRank() const { return m_global_rank; }
269 AllDispatchView m_all_dispatchs;
270
271 private:
272
273 Span<Type> m_broadcast_view;
274 Span<const Type> m_const_view;
275 Span<Type> m_recv_view;
276 Span<const Type> m_send_view;
277 AllToAllVariableInfo m_alltoallv_infos;
278
279 public:
280
281 ReduceInfo m_reduce_infos;
282 MinMaxSumInfo m_min_max_sum_infos;
283
284 private:
285
286 HybridMessageQueue* m_message_queue = nullptr;
287 MpiParallelDispatchT<Type>* m_mpi_dispatcher = nullptr;
288
289 private:
290
291 void _collectiveBarrier();
292 void _allReduceOrScan(eReduceType op, Span<Type> send_buf, bool is_scan);
293 void _applyReduceOperator(eReduceType op, Span<Type> result, AllDispatchView dispatch_view,
294 Int32 first_rank, Int32 last_rank);
295};
296
297/*---------------------------------------------------------------------------*/
298/*---------------------------------------------------------------------------*/
299
300} // End namespace Arcane::MessagePassing
301
302/*---------------------------------------------------------------------------*/
303/*---------------------------------------------------------------------------*/
304
305#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:635
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:482
std::int32_t Int32
Signed integer type of 32 bits.
Type
Type of JSON value.
Definition rapidjson.h:730