14#include "arcane/utils/Array.h"
15#include "arcane/utils/HPReal.h"
16#include "arcane/utils/NumericTypes.h"
17#include "arcane/utils/NotImplementedException.h"
18#include "arcane/utils/ScopedPtr.h"
19#include "arcane/utils/ITraceMng.h"
20#include "arcane/utils/ValueConvert.h"
21#include "arcane/utils/FatalErrorException.h"
23#include "arcane/core/ParallelMngDispatcher.h"
24#include "arcane/core/IParallelDispatch.h"
25#include "arcane/core/Timer.h"
26#include "arcane/core/ITimeStats.h"
27#include "arcane/core/IParallelNonBlockingCollective.h"
28#include "arcane/core/internal/ParallelMngInternal.h"
30#include "arcane/accelerator/core/Runner.h"
31#include "arcane/accelerator/core/RunQueueBuildInfo.h"
33#include "arccore/message_passing/Dispatchers.h"
35#include "arccore/message_passing/MessagePassingMng.h"
36#include "arccore/message_passing/IControlDispatcher.h"
37#include "arccore/message_passing/ISerializeDispatcher.h"
38#include "arccore/message_passing/PointToPointMessageInfo.h"
39#include "arccore/message_passing/IRequestList.h"
40#include "arccore/message_passing/ISerializeMessageList.h"
41#include "arccore/trace/internal/TimeMetric.h"
48using namespace Arccore::MessagePassing;
53ParallelMngDispatcherBuildInfo::
56: m_comm_rank(mpm->commRank())
57, m_comm_size(mpm->commSize())
58, m_dispatchers(dispatchers)
59, m_message_passing_mng(mpm)
67ParallelMngDispatcherBuildInfo::
70: m_comm_rank(mpm_ref->commRank())
71, m_comm_size(mpm_ref->commSize())
72, m_dispatchers(dispatchers.get())
73, m_dispatchers_ref(dispatchers)
74, m_message_passing_mng(mpm_ref.get())
75, m_message_passing_mng_ref(mpm_ref)
83ParallelMngDispatcherBuildInfo::
84ParallelMngDispatcherBuildInfo(Int32 comm_rank,Int32 comm_size)
85: m_comm_rank(comm_rank)
86, m_comm_size(comm_size)
87, m_dispatchers(nullptr)
88, m_message_passing_mng(nullptr)
96void ParallelMngDispatcherBuildInfo::
101 m_dispatchers = m_dispatchers_ref.get();
103 if (!m_message_passing_mng){
104 auto* x =
new MP::MessagePassingMng(m_comm_rank,m_comm_size,m_dispatchers);
105 m_message_passing_mng = x;
106 m_message_passing_mng_ref =
makeRef(x);
108 if (!m_message_passing_mng_ref.get())
109 m_message_passing_mng_ref =
makeRef(m_message_passing_mng);
115ParallelMngDispatcher::DefaultControlDispatcher::
116DefaultControlDispatcher(IParallelMng* pm)
122void ParallelMngDispatcher::DefaultControlDispatcher::
125 m_parallel_mng->waitAllRequests(requests);
128void ParallelMngDispatcher::DefaultControlDispatcher::
130 bool is_non_blocking)
134 done_requests = m_parallel_mng->testSomeRequests(requests);
136 done_requests = m_parallel_mng->waitSomeRequests(requests);
138 for(
int x : done_requests )
149void ParallelMngDispatcher::DefaultControlDispatcher::
152 m_parallel_mng->barrier();
155Request ParallelMngDispatcher::DefaultControlDispatcher::
158 return m_parallel_mng->nonBlockingCollective()->barrier();
161MessageId ParallelMngDispatcher::DefaultControlDispatcher::
164 return m_parallel_mng->probe(message);
170 return m_parallel_mng->legacyProbe(message);
174createRequestListRef()
176 return m_parallel_mng->createRequestListRef();
182void ParallelMngDispatcher::DefaultControlDispatcher::
183setProfiler(MP::IProfiler* p)
193:
public MP::ISerializeDispatcher
204 return m_parallel_mng->createSerializeMessageListRef();
208 return m_parallel_mng->sendSerializer(s,message);
212 return m_parallel_mng->receiveSerializer(s,message);
224ParallelMngDispatcher::
227, m_unsigned_char(nullptr)
228, m_signed_char(nullptr)
230, m_unsigned_short(nullptr)
232, m_unsigned_int(nullptr)
234, m_unsigned_long(nullptr)
235, m_long_long(nullptr)
236, m_unsigned_long_long(nullptr)
239, m_long_double(nullptr)
246, m_time_stats(nullptr)
247, m_mp_dispatchers_ref(bi.dispatchersRef())
248, m_message_passing_mng_ref(bi.messagePassingMngRef())
249, m_control_dispatcher(new DefaultControlDispatcher(this))
250, m_serialize_dispatcher(new SerializeDispatcher(this))
251, m_parallel_mng_internal(new ParallelMngInternal(this))
258ParallelMngDispatcher::
259~ParallelMngDispatcher()
261 m_mp_dispatchers_ref.
reset();
263 delete m_parallel_mng_internal;
265 delete m_serialize_dispatcher;
266 delete m_control_dispatcher;
268 delete m_signed_char;
269 delete m_unsigned_char;
271 delete m_unsigned_short;
273 delete m_unsigned_int;
275 delete m_unsigned_long;
277 delete m_unsigned_long_long;
281 delete m_long_double;
292void ParallelMngDispatcher::
293_setControlDispatcher(MP::IControlDispatcher* d)
295 delete m_control_dispatcher;
296 m_control_dispatcher = d;
302void ParallelMngDispatcher::
303_setSerializeDispatcher(MP::ISerializeDispatcher* d)
305 delete m_serialize_dispatcher;
306 m_serialize_dispatcher = d;
312void ParallelMngDispatcher::
313_setArccoreDispatchers()
315 m_mp_dispatchers_ref->setDispatcher(m_char->toArccoreDispatcher());
316 m_mp_dispatchers_ref->setDispatcher(m_signed_char->toArccoreDispatcher());
317 m_mp_dispatchers_ref->setDispatcher(m_unsigned_char->toArccoreDispatcher());
318 m_mp_dispatchers_ref->setDispatcher(m_short->toArccoreDispatcher());
319 m_mp_dispatchers_ref->setDispatcher(m_unsigned_short->toArccoreDispatcher());
320 m_mp_dispatchers_ref->setDispatcher(m_int->toArccoreDispatcher());
321 m_mp_dispatchers_ref->setDispatcher(m_unsigned_int->toArccoreDispatcher());
322 m_mp_dispatchers_ref->setDispatcher(m_long->toArccoreDispatcher());
323 m_mp_dispatchers_ref->setDispatcher(m_unsigned_long->toArccoreDispatcher());
324 m_mp_dispatchers_ref->setDispatcher(m_long_long->toArccoreDispatcher());
325 m_mp_dispatchers_ref->setDispatcher(m_unsigned_long_long->toArccoreDispatcher());
326 m_mp_dispatchers_ref->setDispatcher(m_float->toArccoreDispatcher());
327 m_mp_dispatchers_ref->setDispatcher(m_double->toArccoreDispatcher());
328 m_mp_dispatchers_ref->setDispatcher(m_long_double->toArccoreDispatcher());
331 m_mp_dispatchers_ref->setDispatcher(m_control_dispatcher);
333 m_mp_dispatchers_ref->setDispatcher(m_serialize_dispatcher);
342 return m_message_passing_mng_ref.get();
351 ITimeMetricCollector* c =
nullptr;
367 _messagePassingMng()->setTimeMetricCollector(c);
374TimeMetricAction ParallelMngDispatcher::
375_communicationTimeMetricAction()
const
377 return Timer::phaseAction(
timeStats(),TP_Communication);
383void ParallelMngDispatcher::
384broadcastString(
String& str,Int32 rank)
390 len_info[0] = bytes.
size();
393 broadcast(utf8_array,rank);
398 broadcast(utf8_array,rank);
399 str = String::fromUtf8(utf8_array);
420 broadcast(bytes,rank);
430 mpAllGather(_messagePassingMng(), send_serializer, recv_serializer);
439 TimeMetricSentry tphase(Timer::phaseAction(
timeStats(),TP_Communication));
443 message_list->addMessage(m);
445 message_list->waitMessages(Parallel::WaitAll);
454 TimeMetricSentry tphase(Timer::phaseAction(
timeStats(), TP_Communication));
458 message_list->addMessage(v.get());
460 message_list->waitMessages(Parallel::WaitAll);
469 return makeRef(_createSerializeMessageList());
478 return _createSerializeMessageList();
487 return _createSubParallelMng(kept_ranks);
496 return makeRef(_createSubParallelMng(kept_ranks));
503_createSubParallelMngRef([[maybe_unused]]
Int32 color, [[maybe_unused]]
Int32 key)
514 Timer::Phase tphase(
timeStats(),TP_Communication);
517 request_list->add(requests);
518 request_list->wait(wait_type);
520 for (
Integer i=0; i<nb_request; ++i )
521 requests[i] = request_list->request(i);
522 return request_list->doneRequestIndexes();
546#define ARCANE_PARALLEL_MANAGER_DISPATCH(field,type)\
547void ParallelMngDispatcher::\
548allGather(ConstArrayView<type> send_buf,ArrayView<type> recv_buf)\
550 Timer::Phase tphase(timeStats(), TP_Communication); \
551 (field)->allGather(send_buf, recv_buf); \
553 void ParallelMngDispatcher:: \
554 gather(ConstArrayView<type> send_buf, ArrayView<type> recv_buf, Integer rank) \
556 Timer::Phase tphase(timeStats(), TP_Communication); \
557 (field)->gather(send_buf, recv_buf, rank); \
559 void ParallelMngDispatcher:: \
560 allGatherVariable(ConstArrayView<type> send_buf, Array<type>& recv_buf) \
562 Timer::Phase tphase(timeStats(), TP_Communication); \
563 (field)->allGatherVariable(send_buf, recv_buf); \
565 void ParallelMngDispatcher:: \
566 gatherVariable(ConstArrayView<type> send_buf, Array<type>& recv_buf, Integer rank) \
568 Timer::Phase tphase(timeStats(), TP_Communication); \
569 (field)->gatherVariable(send_buf, recv_buf, rank); \
571 void ParallelMngDispatcher:: \
572 scatterVariable(ConstArrayView<type> send_buf, ArrayView<type> recv_buf, Integer root) \
574 Timer::Phase tphase(timeStats(), TP_Communication); \
575 (field)->scatterVariable(send_buf, recv_buf, root); \
577 type ParallelMngDispatcher:: \
578 reduce(eReduceType rt, type v) \
580 Timer::Phase tphase(timeStats(), TP_Communication); \
581 return (field)->allReduce(rt, v); \
583 void ParallelMngDispatcher:: \
584 reduce(eReduceType rt, ArrayView<type> v) \
586 Timer::Phase tphase(timeStats(), TP_Communication); \
587 (field)->allReduce(rt, v); \
589 void ParallelMngDispatcher:: \
590 broadcast(ArrayView<type> send_buf, Integer id) \
592 Timer::Phase tphase(timeStats(), TP_Communication); \
593 (field)->broadcast(send_buf, id); \
595 void ParallelMngDispatcher:: \
596 send(ConstArrayView<type> values, Integer id) \
598 Timer::Phase tphase(timeStats(), TP_Communication); \
599 (field)->send(values, id); \
601 void ParallelMngDispatcher:: \
602 recv(ArrayView<type> values, Integer id) \
604 Timer::Phase tphase(timeStats(), TP_Communication); \
605 (field)->recv(values, id); \
607 Parallel::Request ParallelMngDispatcher:: \
608 send(ConstArrayView<type> values, Integer id, bool is_blocked) \
610 Timer::Phase tphase(timeStats(), TP_Communication); \
611 return (field)->send(values, id, is_blocked); \
613 Request ParallelMngDispatcher:: \
614 send(Span<const type> values, const PointToPointMessageInfo& message) \
616 Timer::Phase tphase(timeStats(), TP_Communication); \
617 return (field)->send(values, message); \
619 Parallel::Request ParallelMngDispatcher:: \
620 recv(ArrayView<type> values, Integer id, bool is_blocked) \
622 Timer::Phase tphase(timeStats(), TP_Communication); \
623 return (field)->recv(values, id, is_blocked); \
625 Request ParallelMngDispatcher:: \
626 receive(Span<type> values, const PointToPointMessageInfo& message) \
628 Timer::Phase tphase(timeStats(), TP_Communication); \
629 return (field)->receive(values, message); \
631 void ParallelMngDispatcher:: \
632 sendRecv(ConstArrayView<type> send_buf, ArrayView<type> recv_buf, Integer id) \
634 Timer::Phase tphase(timeStats(), TP_Communication); \
635 (field)->sendRecv(send_buf, recv_buf, id); \
637 void ParallelMngDispatcher:: \
638 allToAll(ConstArrayView<type> send_buf, ArrayView<type> recv_buf, Integer count) \
640 Timer::Phase tphase(timeStats(), TP_Communication); \
641 (field)->allToAll(send_buf, recv_buf, count); \
643 void ParallelMngDispatcher:: \
644 allToAllVariable(ConstArrayView<type> send_buf, Int32ConstArrayView send_count, \
645 Int32ConstArrayView send_index, ArrayView<type> recv_buf, \
646 Int32ConstArrayView recv_count, Int32ConstArrayView recv_index) \
648 Timer::Phase tphase(timeStats(), TP_Communication); \
649 (field)->allToAllVariable(send_buf, send_count, send_index, recv_buf, recv_count, recv_index); \
651 type ParallelMngDispatcher:: \
652 scan(eReduceType rt, type v) \
654 Timer::Phase tphase(timeStats(), TP_Communication); \
655 return (field)->scan(rt, v); \
657 void ParallelMngDispatcher:: \
658 computeMinMaxSum(type val, type& min_val, type& max_val, type& sum_val, Int32& min_proc, Int32& max_proc) \
660 Timer::Phase tphase(timeStats(), TP_Communication); \
661 (field)->computeMinMaxSum(val, min_val, max_val, sum_val, min_proc, max_proc); \
663 IParallelDispatchT<type>* ParallelMngDispatcher:: \
668 void ParallelMngDispatcher:: \
669 computeMinMaxSum(ConstArrayView<type> values, \
670 ArrayView<type> min_values, \
671 ArrayView<type> max_values, \
672 ArrayView<type> sum_values, \
673 ArrayView<Int32> min_ranks, \
674 ArrayView<Int32> max_ranks) \
676 Timer::Phase tphase(timeStats(), TP_Communication); \
677 (field)->computeMinMaxSum(values, min_values, max_values, sum_values, min_ranks, max_ranks); \
679void ParallelMngDispatcher:: \
680 scan(eReduceType rt, ArrayView<type> v) \
682 Timer::Phase tphase(timeStats(), TP_Communication); \
683 (field)->scan(rt, v); \
686ARCANE_PARALLEL_MANAGER_DISPATCH(m_char,
char)
687ARCANE_PARALLEL_MANAGER_DISPATCH(m_unsigned_char,
unsigned char)
688ARCANE_PARALLEL_MANAGER_DISPATCH(m_signed_char,
signed char)
689ARCANE_PARALLEL_MANAGER_DISPATCH(m_short,
short)
690ARCANE_PARALLEL_MANAGER_DISPATCH(m_unsigned_short,
unsigned short)
691ARCANE_PARALLEL_MANAGER_DISPATCH(m_int,
int)
692ARCANE_PARALLEL_MANAGER_DISPATCH(m_unsigned_int,
unsigned int)
693ARCANE_PARALLEL_MANAGER_DISPATCH(m_long,
long)
694ARCANE_PARALLEL_MANAGER_DISPATCH(m_unsigned_long,
unsigned long)
695ARCANE_PARALLEL_MANAGER_DISPATCH(m_long_long,
long long)
696ARCANE_PARALLEL_MANAGER_DISPATCH(m_unsigned_long_long,
unsigned long long)
697ARCANE_PARALLEL_MANAGER_DISPATCH(m_float,
float)
698ARCANE_PARALLEL_MANAGER_DISPATCH(m_double,
double)
699ARCANE_PARALLEL_MANAGER_DISPATCH(m_long_double,
long double)
700ARCANE_PARALLEL_MANAGER_DISPATCH(m_apreal,
APReal)
701ARCANE_PARALLEL_MANAGER_DISPATCH(m_real2,
Real2)
702ARCANE_PARALLEL_MANAGER_DISPATCH(m_real3,
Real3)
703ARCANE_PARALLEL_MANAGER_DISPATCH(m_real2x2,
Real2x2)
704ARCANE_PARALLEL_MANAGER_DISPATCH(m_real3x3,
Real3x3)
705ARCANE_PARALLEL_MANAGER_DISPATCH(m_hpreal,
HPReal)
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
Liste des fonctions d'échange de message.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(class_name)
Macro pour définir les méthodes et types une classe qui utilise un compteur de référence.
Emulation de réel en précision arbitraire.
Int64 largeSize() const
Nombre d'éléments du vecteur (en 64 bits)
Vue modifiable d'un tableau d'un type T.
void fill(const T &o) noexcept
Remplit le tableau avec la valeur o.
constexpr Integer size() const noexcept
Retourne la taille du tableau.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
Vue constante d'un tableau de type T.
Classe implémentant un réel Haute Précision.
Interface du gestionnaire de parallélisme pour un sous-domaine.
virtual Int32 commRank() const =0
Rang de cette instance dans le communicateur.
virtual Ref< Parallel::IRequestList > createRequestListRef()=0
Créé une liste de requêtes pour ce gestionnaire.
Interface d'un sérialiseur.
virtual ITimeMetricCollector * metricCollector()=0
Interface de collection associée.
Interface du conteneur des dispatchers.
Interface du gestionnaire des échanges de messages.
Interface d'une liste de messages de sérialisation.
Gestionnaire des échanges de messages.
Informations sur la source d'un message.
Informations pour envoyer/recevoir un message point à point.
Request sendSerializer(const ISerializer *s, const PointToPointMessageInfo &message) override
Message d'envoi.
Request receiveSerializer(ISerializer *s, const PointToPointMessageInfo &message) override
Message de réception.
Ref< ISerializeMessageList > createSerializeMessageListRef() override
Créé une liste de messages de sérialisation.
ISerializeMessageList * createSerializeMessageList() final
Créé une liste pour gérer les 'ISerializeMessage'.
void setTimeStats(ITimeStats *ts) override
Positionne le gestionnaire de statistiques.
void allGather(ISerializer *send_serializer, ISerializer *recv_serializer) override
Redéfinit ici allGather pour éviter de cacher le symbole dans les classes dérivées.
Ref< IParallelMng > createSubParallelMngRef(Int32ConstArrayView kept_ranks) override
Créé un nouveau gestionnaire de parallélisme pour un sous-ensemble des rangs.
void processMessages(ConstArrayView< ISerializeMessage * > messages) override
Exécute les opérations des messages messages.
IMessagePassingMng * messagePassingMng() const override
Gestionnaire de message de Arccore associé
ITimeMetricCollector * timeMetricCollector() const override
Collecteur Arccore des statistiques temporelles (peut être nul)
IParallelMng * createSubParallelMng(Int32ConstArrayView kept_ranks) final
Créé un nouveau gestionnaire de parallélisme pour un sous-ensemble des rangs.
UniqueArray< Integer > testSomeRequests(ArrayView< Request > requests) override
Test si une des requêtes rvalues est terminée.
ITimeStats * timeStats() const override
Gestionnaire de statistiques associé (peut être nul)
Ref< ISerializeMessageList > createSerializeMessageListRef() final
Créé une liste pour gérer les 'ISerializeMessage'.
UniqueArray< Integer > waitSomeRequests(ArrayView< Request > requests) override
Bloque en attendant qu'une des requêtes rvalues soit terminée.
void broadcastMemoryBuffer(ByteArray &bytes, Int32 rank) override
Effectue un broadcast d'une zone mémoire.
Classe gérant un vecteur de réel de dimension 2.
Classe gérant une matrice de réel de dimension 2x2.
Classe gérant un vecteur de réel de dimension 3.
Classe gérant une matrice de réel de dimension 3x3.
Référence à une instance.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Vue d'un tableau d'éléments de type T.
Chaîne de caractères unicode.
Span< const Byte > bytes() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
Positionne la phase de l'action en cours d'exécution.
Vecteur 1D de données avec sémantique par valeur (style STL).
void reset()
Positionne l'instance au pointeur nul.
@ WaitSome
Attend que tous les messages de la liste soient traités.
void mpAllGather(IMessagePassingMng *pm, const ISerializer *send_serializer, ISerializer *receive_serialize)
Message allGather() pour une sérialisation.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
ArrayView< Int64 > Int64ArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
Array< Byte > ByteArray
Tableau dynamique à une dimension de caractères.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
UniqueArray< Byte > ByteUniqueArray
Tableau dynamique à une dimension de caractères.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
std::int32_t Int32
Type entier signé sur 32 bits.
Espace de nom de Arccore.
Ref< TrueType > createRef(Args &&... args)
Créé une instance de type TrueType avec les arguments Args et retourne une référence dessus.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.