Arcane  v3.14.10.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-2024 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-2024 */
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
35class SharedMemoryParallelMng;
36class ISharedMemoryMessageQueue;
37class SharedMemoryParallelDispatchBase;
38template <class Type>
39class SharedMemoryParallelDispatch;
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>
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/*---------------------------------------------------------------------------*/
125: public TraceAccessor
127{
128 ARCCORE_INTERNAL_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS();
129 protected:
130
131 template <typename DataType> friend class SharedMemoryParallelDispatch;
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
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);
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>
219, public IParallelDispatchT<Type>
220, public ITypeDispatcher<Type>
221{
223
225 {
226 public:
227
229 : m_array_ref(v)
230 {}
231
232 public:
233
234 virtual void resize(Int64 new_size) { m_array_ref.resize(new_size); }
235 virtual MutableMemoryView memoryView() const { return MutableMemoryView(m_array_ref.span()); }
236
237 private:
238
239 Array<Type>& m_array_ref;
240 };
241
243 {
244 public:
245
246 Span<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
271
272 public:
273
275 ISharedMemoryMessageQueue* message_queue,
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_buf) override;
290 void allToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
291 void allToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
292 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
293 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
294 Request send(Span<const Type> send_buffer, Int32 proc, bool is_blocked) override;
295 Request send(Span<const Type> send_buffer, const PointToPointMessageInfo& message) override;
296 Request receive(Span<Type> recv_buffer, Int32 rank, bool is_blocked) override;
297 Request receive(Span<Type> recv_buffer, const PointToPointMessageInfo& message) override;
298 Request nonBlockingAllReduce(eReduceType op, Span<const Type> send_buf, Span<Type> recv_buf) override;
299 Request nonBlockingAllGather(Span<const Type> send_buf, Span<Type> recv_buf) override;
300 Request nonBlockingBroadcast(Span<Type> send_buf, Int32 rank) override;
301 Request nonBlockingGather(Span<const Type> send_buf, Span<Type> recv_buf, Int32 rank) override;
302 Request nonBlockingAllToAll(Span<const Type> send_buf, Span<Type> recv_buf, Int32 count) override;
303 Request nonBlockingAllToAllVariable(Span<const Type> send_buf, ConstArrayView<Int32> send_count,
304 ConstArrayView<Int32> send_index, Span<Type> recv_buf,
305 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index) override;
308
309 void broadcast(ArrayView<Type> send_buf, Integer sub_domain) override
310 {
311 this->broadcast(Span<Type>(send_buf), sub_domain);
312 }
313 void allGather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf) override
314 {
315 this->allGather(Span<const Type>(send_buf), Span<Type>(recv_buf));
316 }
317 void allGatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf) override
318 {
319 this->allGatherVariable(Span<const Type>(send_buf), recv_buf);
320 }
321 void gather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer rank) override
322 {
323 this->gather(Span<const Type>(send_buf), Span<Type>(recv_buf), rank);
324 }
325 void gatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf, Integer rank) override
326 {
327 this->gatherVariable(Span<const Type>(send_buf), recv_buf, rank);
328 }
329 void scatterVariable(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer root) override
330 {
331 this->scatterVariable(Span<const Type>(send_buf), Span<Type>(recv_buf), root);
332 }
333 void allToAll(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer count) override
334 {
335 this->allToAll(Span<const Type>(send_buf), Span<Type>(recv_buf), count);
336 }
337 void allToAllVariable(ConstArrayView<Type> send_buf, Int32ConstArrayView send_count,
338 Int32ConstArrayView send_index, ArrayView<Type> recv_buf,
339 Int32ConstArrayView recv_count, Int32ConstArrayView recv_index) override
340 {
341 this->allToAllVariable(Span<const Type>(send_buf), send_count, send_index,
342 Span<Type>(recv_buf), recv_count, recv_index);
343 }
344 Request send(ConstArrayView<Type> send_buffer, Integer proc, bool is_blocked) override
345 {
346 return this->send(Span<const Type>(send_buffer), proc, is_blocked);
347 }
348 Request recv(ArrayView<Type> recv_buffer, Int32 rank, bool is_blocked) override
349 {
350 return this->receive(Span<Type>(recv_buffer), rank, is_blocked);
351 }
352 void allReduce(eReduceType op, ArrayView<Type> send_buf) override
353 {
354 return this->allReduce(op, Span<Type>(send_buf));
355 }
356
357 void send(ConstArrayView<Type> send_buffer, Integer proc) override;
358 void recv(ArrayView<Type> recv_buffer, Integer proc) override;
359 void sendRecv(ConstArrayView<Type> send_buffer, ArrayView<Type> recv_buffer, Integer proc) override;
360 Type allReduce(eReduceType op, Type send_buf) override;
361 Type scan(eReduceType op, Type send_buf) override;
362 void scan(eReduceType op, ArrayView<Type> send_buf) override;
363 void computeMinMaxSum(Type val, Type& min_val, Type& max_val, Type& sum_val,
364 Int32& min_rank,
365 Int32& max_rank) override;
366 void computeMinMaxSum(ConstArrayView<Type> values,
367 ArrayView<Type> min_values,
368 ArrayView<Type> max_values,
369 ArrayView<Type> sum_values,
370 ArrayView<Int32> min_ranks,
371 ArrayView<Int32> max_ranks) override;
372 ITypeDispatcher<Type>* toArccoreDispatcher() override { return this; }
373
374 void waitAll();
375
376 public:
377
378 ArrayView<SharedMemoryParallelDispatch<Type>*> m_all_dispatchs;
379
380 private:
381 public:
382
383 ReduceInfo m_reduce_infos;
384
385 private:
386
387 void _allReduceOrScan(eReduceType op, Span<Type> send_buf, bool is_scan);
388};
389
390/*---------------------------------------------------------------------------*/
391/*---------------------------------------------------------------------------*/
392
393} // End namespace Arcane::MessagePassing
394
395/*---------------------------------------------------------------------------*/
396/*---------------------------------------------------------------------------*/
397
398#endif
399
Conteneur contenant une instance d'une classe par type de donnée Arcane.
Gestion des messages parallèles pour le type Type.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Interface d'une file de messages avec les threads.
Classe de base commune à SharedMemoryParallelDispatch.
Gestionnaire du parallélisme utilisant les threads.
Interface du gestionnaire de traces.
Informations pour un message 'gather' pour le type de données DataType.
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
Implémentation thread-safe d'un compteur de référence.
Déclarations des types et méthodes utilisés par les mécanismes d'échange de messages.
Definition Parallel.h:94
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:640
eReduceType
Types des réductions supportées.
Type
Type of JSON value.
Definition rapidjson.h:665