Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
StandaloneMpiMessagePassingMng.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* StandaloneMpiMessagePassingMng.cc (C) 2000-2024 */
9/* */
10/* Implémentation MPI du gestionnaire des échanges de messages. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/message_passing_mpi/StandaloneMpiMessagePassingMng.h"
15
16#include "arccore/message_passing/Dispatchers.h"
17#include "arccore/message_passing/Stat.h"
18#include "arccore/trace/ITraceMng.h"
19#include "arccore/base/ReferenceCounter.h"
20#include "arccore/base/BFloat16.h"
21#include "arccore/base/Float16.h"
22
23#include "arccore/message_passing_mpi/MpiAdapter.h"
24#include "arccore/message_passing_mpi/MpiDatatype.h"
25#include "arccore/message_passing_mpi/MpiTypeDispatcher.h"
26#include "arccore/message_passing_mpi/MpiControlDispatcher.h"
27#include "arccore/message_passing_mpi/MpiSerializeDispatcher.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arccore::MessagePassing::Mpi
33{
34
36{
37 public:
38 explicit Impl(MPI_Comm mpi_comm, bool clean_comm=false)
39 : m_communicator(mpi_comm), m_clean_comm(clean_comm)
40 {
41 m_trace_mng = Arccore::arccoreCreateDefaultTraceMng();
42 ::MPI_Comm_rank(mpi_comm, &m_comm_rank);
43 ::MPI_Comm_size(mpi_comm, &m_comm_size);
44
45 m_stat = new Stat();
46 MpiLock* mpi_lock = nullptr;
47 m_adapter = new MpiAdapter(m_trace_mng.get(), m_stat, mpi_comm, mpi_lock);
48
49 m_dispatchers = new Dispatchers();
50 m_dispatchers->setDeleteDispatchers(true);
51 }
52
53 ~Impl()
54 {
55 try {
56 m_adapter->destroy();
57 }
58 catch (const Exception& ex) {
59 std::cerr << "ERROR: msg=" << ex << "\n";
60 }
61
62 delete m_dispatchers;
63 delete m_stat;
64
65 if (m_clean_comm)
66 MPI_Comm_free(&m_communicator);
67 }
68
70 buildInfo() const
71 {
72 return MpiMessagePassingMng::BuildInfo(m_comm_rank, m_comm_size, m_dispatchers, m_communicator);
73 }
74
75 public:
76
78 IStat* m_stat = nullptr;
79 Dispatchers* m_dispatchers = nullptr;
80 MpiAdapter* m_adapter = nullptr;
81 int m_comm_rank = A_NULL_RANK;
82 int m_comm_size = A_NULL_RANK;
83 MPI_Comm m_communicator = MPI_COMM_NULL;
84 bool m_clean_comm = false;
85};
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90StandaloneMpiMessagePassingMng::
91StandaloneMpiMessagePassingMng(Impl* p)
92: MpiMessagePassingMng(p->buildInfo())
93, m_p(p)
94{
95}
96
97/*---------------------------------------------------------------------------*/
98/*---------------------------------------------------------------------------*/
99
100StandaloneMpiMessagePassingMng::
101~StandaloneMpiMessagePassingMng()
102{
103 delete m_p;
104}
105
106namespace
107{
108 template <typename DataType> void
109 _createAndSetCustomDispatcher(Dispatchers* dispatchers, IMessagePassingMng* mpm,
110 MpiAdapter* adapter, MpiDatatype* datatype)
111 {
112 auto* x = new MpiTypeDispatcher<DataType>(mpm, adapter, datatype);
113 x->setDestroyDatatype(true);
114 dispatchers->setDispatcher(x);
115 }
116
117 template <typename DataType> void
118 _createAndSetDispatcher(Dispatchers* dispatchers, IMessagePassingMng* mpm,
119 MpiAdapter* adapter)
120 {
121 MPI_Datatype mpi_dt = MpiBuiltIn::datatype(DataType());
122 auto dt = new MpiDatatype(mpi_dt);
123 _createAndSetCustomDispatcher<DataType>(dispatchers, mpm, adapter, dt);
124 }
125
126} // namespace
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
132create(MPI_Comm mpi_comm, bool clean_comm)
133{
134 Impl* p = new Impl(mpi_comm, clean_comm);
136 auto adapter = p->m_adapter;
137 auto dsp = p->m_dispatchers;
138
153
154 dsp->setDispatcher(new MpiControlDispatcher(adapter));
155 dsp->setDispatcher(new MpiSerializeDispatcher(adapter));
156
157 MPI_Datatype uint8_datatype = MpiBuiltIn::datatype(uint8_t{});
158 {
159 // BFloat16
163 auto* x = new MpiDatatype(mpi_datatype, false, new StdMpiReduceOperator<BFloat16>(true));
165 }
166 {
167 // Float16
171 auto* x = new MpiDatatype(mpi_datatype, false, new StdMpiReduceOperator<Float16>(true));
173 }
174 return mpm;
175}
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
190} // End namespace Arccore::MessagePassing::Mpi
191
192/*---------------------------------------------------------------------------*/
193/*---------------------------------------------------------------------------*/
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Classe de base d'une exception.
Interface du conteneur des dispatchers.
Definition Dispatchers.h:34
void setDeleteDispatchers(bool v)
Indique si lors de la destruction on appelle l'opérateur delete sur les instances (faux par défaut)
Definition Dispatchers.h:84
Interface du gestionnaire des échanges de messages.
void destroy()
Détruit l'instance. Elle ne doit plus être utilisée par la suite.
Implémentation MPI du gestionnaire des échanges de messages.
static Ref< IMessagePassingMng > createRef(MPI_Comm comm, bool clean_comm=false)
Créé un gestionnaire associé au communicateur comm.
static MpiMessagePassingMng * create(MPI_Comm comm, bool clean_comm=false)
Créé un gestionnaire associé au communicateur comm.
Gestionnaire de statistiques sur le parallélisme.
Definition Stat.h:72