Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ParallelMngDispatcher.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/* ParallelMngDispatcher.h (C) 2000-2024 */
9/* */
10/* Interface du gestionnaire du parallélisme sur un domaine. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_PARALLELMNGDISPATCHER_H
13#define ARCANE_PARALLELMNGDISPATCHER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/IParallelMng.h"
19#include "arccore/message_passing/MessagePassingMng.h"
20
21#include <atomic>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31template <typename T>
32class IParallelDispatchT;
33class ITimeStats;
34namespace MP = ::Arccore::MessagePassing;
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39class ARCANE_CORE_EXPORT ParallelMngDispatcherBuildInfo
40{
41 public:
42
43 ARCANE_DEPRECATED_REASON("Y2022: Use overload with Ref<MP::MessagePassingMng> and Ref<MP::Dispatchers> instead")
46 ParallelMngDispatcherBuildInfo(Ref<MP::Dispatchers> dispatchers,
47 Ref<MP::MessagePassingMng> mpm);
48 ParallelMngDispatcherBuildInfo(Int32 comm_rank, Int32 comm_size);
49
50 public:
51
52 Int32 commRank() const { return m_comm_rank; }
53 Int32 commSize() const { return m_comm_size; }
54 Ref<MP::Dispatchers> dispatchersRef() const { return m_dispatchers_ref; }
55 Ref<MP::MessagePassingMng> messagePassingMngRef() const { return m_message_passing_mng_ref; }
56
57 ARCANE_DEPRECATED_REASON("Y2022: Use messagePassingMngRef() instead")
58 MP::MessagePassingMng* messagePassingMng() const { return m_message_passing_mng; }
59 ARCANE_DEPRECATED_REASON("Y2022: Use dispatchersRef() instead")
60 MP::Dispatchers* dispatchers() const { return m_dispatchers; }
61
62 private:
63
64 Int32 m_comm_rank;
65 Int32 m_comm_size;
66 MP::Dispatchers* m_dispatchers;
67 Ref<MP::Dispatchers> m_dispatchers_ref;
68 MP::MessagePassingMng* m_message_passing_mng;
69 Ref<MP::MessagePassingMng> m_message_passing_mng_ref;
70
71 private:
72
73 void _init();
74};
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78/*!
79 * \internal
80 * \brief Redirige la gestion des messages des sous-domaines
81 * suivant le type de l'argument.
82 */
83class ARCANE_CORE_EXPORT ParallelMngDispatcher
85, public IParallelMng
86{
87 public:
88
89 //! Implémentation de Arccore::MessagePassing::IControlDispatcher.
90 class ARCANE_CORE_EXPORT DefaultControlDispatcher
92 {
93 public:
94
96
97 public:
98
99 void waitAllRequests(ArrayView<Request> requests) override;
100 void waitSomeRequests(ArrayView<Request> requests,
101 ArrayView<bool> indexes, bool is_non_blocking) override;
102 IMessagePassingMng* commSplit(bool keep) override;
103 void barrier() override;
104 Request nonBlockingBarrier() override;
105 MessageId probe(const PointToPointMessageInfo& message) override;
106 MP::MessageSourceInfo legacyProbe(const PointToPointMessageInfo& message) override;
107 Ref<Parallel::IRequestList> createRequestListRef() override;
108 MP::IProfiler* profiler() const override { return nullptr; }
109 void setProfiler(MP::IProfiler* p) override;
110
111 private:
112
113 IParallelMng* m_parallel_mng;
114 };
115
116 //! Implémentation de Arccore::MessagePassing::ISerializeDispatcher.
118
119 class Impl;
120
121 public:
122
124
125 public:
126
128 ~ParallelMngDispatcher() override;
129
130 public:
131
134 ParallelMngDispatcher& operator=(ParallelMngDispatcher&&) = delete;
135 ParallelMngDispatcher& operator=(const ParallelMngDispatcher&) = delete;
136
137 private:
138
139 void _setArccoreDispatchers();
140
141 public:
142
143 IMessagePassingMng* messagePassingMng() const override;
144 void broadcastString(String& str, Int32 rank) override;
145 void broadcastMemoryBuffer(ByteArray& bytes, Int32 rank) override;
146
147 //! Redéfinit ici allGather pour éviter de cacher le symbole dans les classes dérivées.
148 void allGather(ISerializer* send_serializer, ISerializer* recv_serializer) override;
149
150 public:
151
152#define ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(field, type) \
153 public:\
154 void allGather(ConstArrayView<type> send_buf, ArrayView<type> recv_buf) override; \
155 void gather(ConstArrayView<type> send_buf, ArrayView<type> recv_buf, Integer rank) override; \
156 void allGatherVariable(ConstArrayView<type> send_buf, Array<type>& recv_buf) override; \
157 void gatherVariable(ConstArrayView<type> send_buf, Array<type>& recv_buf, Integer rank) override; \
158 void scatterVariable(ConstArrayView<type> send_buf, ArrayView<type> recv_buf, Integer root) override; \
159 type reduce(eReduceType rt, type v) override; \
160 void reduce(eReduceType rt, ArrayView<type> v) override;\
161 void broadcast(ArrayView<type> send_buf, Integer id) override;\
162 void send(ConstArrayView<type> values, Integer id) override;\
163 void recv(ArrayView<type> values, Integer id) override;\
164 Request send(ConstArrayView<type> values, Int32 rank, bool is_blocked) override; \
165 Request send(Span<const type> values, const PointToPointMessageInfo& message) override; \
166 Request recv(ArrayView<type> values, Int32 rank, bool is_blocked) override;\
167 Request receive(Span<type> values, const PointToPointMessageInfo& message) override; \
168 void sendRecv(ConstArrayView<type> send_buf, ArrayView<type> recv_buf, Integer id) override;\
169 void allToAll(ConstArrayView<type> send_buf, ArrayView<type> recv_buf, Integer count) override;\
170 void allToAllVariable(ConstArrayView<type> send_buf, Int32ConstArrayView send_count,\
171 Int32ConstArrayView send_index, ArrayView<type> recv_buf,\
172 Int32ConstArrayView recv_count, Int32ConstArrayView recv_index) override;\
173 type scan(eReduceType rt, type v); \
174 void computeMinMaxSum(type val, type& min_val, type& max_val, type& sum_val, Int32& min_proc, Int32& max_proc) override;\
175 void computeMinMaxSum(ConstArrayView<type> values,\
176 ArrayView<type> min_values,\
177 ArrayView<type> max_values,\
178 ArrayView<type> sum_values,\
179 ArrayView<Int32> min_ranks,\
180 ArrayView<Int32> max_ranks) override;\
181 void scan(eReduceType rt, ArrayView<type> v) override;\
182 protected:\
183 IParallelDispatchT<type>* field;
184
185 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_char, char)
186 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_unsigned_char, unsigned char)
187 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_signed_char, signed char)
188 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_short, short)
189 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_unsigned_short, unsigned short)
190 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_int, int)
191 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_unsigned_int, unsigned int)
192 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_long, long)
193 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_unsigned_long, unsigned long)
194 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_long_long, long long)
195 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_unsigned_long_long, unsigned long long)
196 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_float, float)
197 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_double, double)
198 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_long_double, long double)
199 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_apreal, APReal)
200 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_real2, Real2)
201 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_real3, Real3)
202 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_real2x2, Real2x2)
203 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_real3x3, Real3x3)
204 ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE(m_hpreal, HPReal)
205
206#undef ARCANE_PARALLEL_MANAGER_DISPATCH_PROTOTYPE
207
208 public:
209
210 virtual IParallelDispatchT<char>* dispatcher(char*);
211 virtual IParallelDispatchT<signed char>* dispatcher(signed char*);
212 virtual IParallelDispatchT<unsigned char>* dispatcher(unsigned char*);
213 virtual IParallelDispatchT<short>* dispatcher(short*);
214 virtual IParallelDispatchT<unsigned short>* dispatcher(unsigned short*);
215 virtual IParallelDispatchT<int>* dispatcher(int*);
216 virtual IParallelDispatchT<unsigned int>* dispatcher(unsigned int*);
217 virtual IParallelDispatchT<long>* dispatcher(long*);
218 virtual IParallelDispatchT<unsigned long>* dispatcher(unsigned long*);
219 virtual IParallelDispatchT<long long>* dispatcher(long long*);
220 virtual IParallelDispatchT<unsigned long long>* dispatcher(unsigned long long*);
221 virtual IParallelDispatchT<APReal>* dispatcher(APReal*);
222 virtual IParallelDispatchT<float>* dispatcher(float*);
223 virtual IParallelDispatchT<double>* dispatcher(double*);
224 virtual IParallelDispatchT<long double>* dispatcher(long double*);
225 virtual IParallelDispatchT<Real2>* dispatcher(Real2*);
226 virtual IParallelDispatchT<Real3>* dispatcher(Real3*);
227 virtual IParallelDispatchT<Real2x2>* dispatcher(Real2x2*);
228 virtual IParallelDispatchT<Real3x3>* dispatcher(Real3x3*);
229 virtual IParallelDispatchT<HPReal>* dispatcher(HPReal*);
230
231 public:
232
233 template <class CreatorType> void
234 createDispatchers(CreatorType& ct)
235 {
236 m_char = ct.template create<char>();
237 m_signed_char = ct.template create<signed char>();
238 m_unsigned_char = ct.template create<unsigned char>();
239 m_short = ct.template create<short>();
240 m_unsigned_short = ct.template create<unsigned short>();
241 m_int = ct.template create<int>();
242 m_unsigned_int = ct.template create<unsigned int>();
243 m_long = ct.template create<long>();
244 m_unsigned_long = ct.template create<unsigned long>();
245 m_long_long = ct.template create<long long>();
246 m_unsigned_long_long = ct.template create<unsigned long long>();
247
248 m_float = ct.template create<float>();
249 m_double = ct.template create<double>();
250 m_long_double = ct.template create<long double>();
251
252 m_apreal = ct.template create<APReal>();
253 m_real2 = ct.template create<Real2>();
254 m_real3 = ct.template create<Real3>();
255 m_real2x2 = ct.template create<Real2x2>();
256 m_real3x3 = ct.template create<Real3x3>();
257 m_hpreal = ct.template create<HPReal>();
258
259 _setArccoreDispatchers();
260 }
261
262 public:
263
264 ITimeStats* timeStats() const override { return m_time_stats; }
265 void setTimeStats(ITimeStats* ts) override;
266 ITimeMetricCollector* timeMetricCollector() const override;
267
268 UniqueArray<Integer> waitSomeRequests(ArrayView<Request> requests) override;
269 UniqueArray<Integer> testSomeRequests(ArrayView<Request> requests) override;
270 void processMessages(ConstArrayView<ISerializeMessage*> messages) override;
271 ISerializeMessageList* createSerializeMessageList() final;
272 Ref<ISerializeMessageList> createSerializeMessageListRef() final;
273 IParallelMng* createSubParallelMng(Int32ConstArrayView kept_ranks) final;
274 Ref<IParallelMng> createSubParallelMngRef(Int32ConstArrayView kept_ranks) override;
275
276 public:
277
278 IParallelMngInternal* _internalApi() override { return m_parallel_mng_internal; }
279
280 protected:
281
282 MP::MessagePassingMng* _messagePassingMng() const { return m_message_passing_mng_ref.get(); }
283 UniqueArray<Integer> _doWaitRequests(ArrayView<Request> requests,Parallel::eWaitType wait_type);
284 virtual ISerializeMessageList* _createSerializeMessageList() =0;
285 virtual IParallelMng* _createSubParallelMng(Int32ConstArrayView kept_ranks) =0;
286 virtual bool _isAcceleratorAware() const { return false; }
287 virtual Ref<IParallelMng> _createSubParallelMngRef(Int32 color, Int32 key);
288
289 protected:
290
291 TimeMetricAction _communicationTimeMetricAction() const;
292 void _setControlDispatcher(MP::IControlDispatcher* d);
293 void _setSerializeDispatcher(MP::ISerializeDispatcher* d);
294
295 private:
296
297 ITimeStats* m_time_stats = nullptr;
298 Ref<MP::Dispatchers> m_mp_dispatchers_ref;
299 Ref<MP::MessagePassingMng> m_message_passing_mng_ref;
300 MP::IControlDispatcher* m_control_dispatcher = nullptr;
301 MP::ISerializeDispatcher* m_serialize_dispatcher = nullptr;
302 IParallelMngInternal* m_parallel_mng_internal = nullptr;
303};
304
305/*---------------------------------------------------------------------------*/
306/*---------------------------------------------------------------------------*/
307
311{
312 ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS();
313};
314
315/*---------------------------------------------------------------------------*/
316/*---------------------------------------------------------------------------*/
317
318} // End namespace Arcane
319
320/*---------------------------------------------------------------------------*/
321/*---------------------------------------------------------------------------*/
322
323#endif
#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro pour définir les méthodes gérant les compteurs de référence.
Classe implémentant un réel Haute Précision.
Definition HPReal.h:161
Interface du gestionnaire de parallélisme pour un sous-domaine.
Implémentation de Arccore::MessagePassing::IControlDispatcher.
ITimeStats * timeStats() const override
Gestionnaire de statistiques associé (peut être nul)
Classe gérant un vecteur de réel de dimension 2.
Definition Real2.h:121
Classe gérant une matrice de réel de dimension 2x2.
Definition Real2x2.h:53
Classe gérant un vecteur de réel de dimension 3.
Definition Real3.h:132
Classe gérant une matrice de réel de dimension 3x3.
Definition Real3x3.h:66
Emulation de réel en précision arbitraire.
Vue modifiable d'un tableau d'un type T.
Classe de base des vecteurs 1D de données.
Vue constante d'un tableau de type T.
Interface gérant les statistiques sur l'exécution.
Interface du conteneur des dispatchers.
Definition Dispatchers.h:34
Interface du gestionnaire des échanges de messages.
Interface d'un profiler pour les échanges de messages.
Definition IProfiler.h:31
Interface des messages de sérialisation.
Gestionnaire des échanges de messages.
Informations sur la source d'un message.
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.
Chaîne de caractères unicode.
Vecteur 1D de données avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Espace de nommage contenant les types et déclarations qui gèrent le mécanisme de parallélisme par éch...