Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
MpiParallelMng.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/* MpiParallelMng.h (C) 2000-2026 */
9/* */
10/* Implementation of messages using MPI. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_PARALLEL_MPI_MPIPARALLELMNG_H
13#define ARCANE_PARALLEL_MPI_MPIPARALLELMNG_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18#include "arcane/utils/Ref.h"
19
20#include "arcane/core/ParallelMngDispatcher.h"
21
22#include "arcane/parallel/mpi/ArcaneMpi.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34class MpiDatatypeList;
35class SerializeBuffer;
36class ArcaneMpiSerializeMessageList;
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
43struct ARCANE_MPI_EXPORT MpiParallelMngBuildInfo
44{
45 public:
46
47 MpiParallelMngBuildInfo(MPI_Comm comm, MPI_Comm machine_comm);
48
49 public:
50
51 Int32 commRank() const { return comm_rank; }
52 Int32 commSize() const { return comm_nb_rank; }
53 MPI_Comm mpiComm() const { return mpi_comm; }
54 MPI_Comm mpiMachineComm() const { return mpi_machine_comm; }
55
56 public:
57
58 bool is_parallel;
59
60 private:
61
62 Int32 comm_rank = -1;
63 Int32 comm_nb_rank = -1;
64
65 public:
66
67 Parallel::IStat* stat = nullptr;
68 ITraceMng* trace_mng = nullptr;
69 ITimerMng* timer_mng = nullptr;
70 IThreadMng* thread_mng = nullptr;
71 IParallelMng* world_parallel_mng = nullptr;
72
73 private:
74
75 MPI_Comm mpi_comm = MPI_COMM_NULL;
76 MPI_Comm mpi_machine_comm = MPI_COMM_NULL;
77
78 public:
79
80 bool is_mpi_comm_owned = false;
81 MpiLock* mpi_lock = nullptr;
82};
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
90class ARCANE_MPI_EXPORT MpiParallelMng
91: public ParallelMngDispatcher
92{
93 public:
94
95 friend ArcaneMpiSerializeMessageList;
96 class RequestList;
97 class Impl;
98
99 public:
100
101 explicit MpiParallelMng(const MpiParallelMngBuildInfo& bi);
102 ~MpiParallelMng() override;
103
104 bool isParallel() const override { return m_is_parallel; }
105 Int32 commRank() const override { return m_comm_rank; }
106 Int32 commSize() const override { return m_comm_size; }
107 void* getMPICommunicator() override { return &m_communicator; }
108 bool isThreadImplementation() const override { return false; }
109 bool isHybridImplementation() const override { return false; }
110 ITraceMng* traceMng() const override { return m_trace; }
111 IThreadMng* threadMng() const override { return m_thread_mng; }
112 IParallelMng* worldParallelMng() const override { return m_world_parallel_mng; }
113 IIOMng* ioMng() const override { return m_io_mng; }
114
115 void initialize() override;
116 bool isMasterIO() const override { return commRank() == 0; }
117 Integer masterIORank() const override { return 0; }
118
119 ITimerMng* timerMng() const override { return m_timer_mng; }
120
121 void sendSerializer(ISerializer* values, Int32 rank) override;
122 Request sendSerializer(ISerializer* values, Int32 rank, ByteArray& bytes) override;
123 ISerializeMessage* createSendSerializer(Int32 rank) override;
124
125 void recvSerializer(ISerializer* values, Int32 rank) override;
126 ISerializeMessage* createReceiveSerializer(Int32 rank) override;
127
128 void freeRequests(ArrayView<Parallel::Request> requests) override;
129
130 void broadcastSerializer(ISerializer* values, Int32 rank) override;
131 MessageId probe(const PointToPointMessageInfo& message) override;
132 MessageSourceInfo legacyProbe(const PointToPointMessageInfo& message) override;
133 Request sendSerializer(const ISerializer* values, const PointToPointMessageInfo& message) override;
134 Request receiveSerializer(ISerializer* values, const PointToPointMessageInfo& message) override;
135
136 void printStats() override;
137 IParallelMng* sequentialParallelMng() override;
138 Ref<IParallelMng> sequentialParallelMngRef() override;
139 void barrier() override;
140 void waitAllRequests(ArrayView<Request> requests) override;
141 UniqueArray<Integer> waitSomeRequests(ArrayView<Request> requests) override;
142 UniqueArray<Integer> testSomeRequests(ArrayView<Request> requests) override;
143 ARCANE_DEPRECATED_260 Real reduceRank(eReduceType rt, Real v, Int32* rank)
144 {
145 Real rv = reduce(rt, v);
146 if (rank)
147 *rank = 0;
148 return rv;
149 }
150
151 IParallelNonBlockingCollective* nonBlockingCollective() const override { return m_non_blocking_collective; }
152
153 void build() override;
154
155 public:
156
157 MpiAdapter* adapter() { return m_adapter; }
158 Communicator communicator() const override { return Communicator(m_communicator); }
159 Communicator machineCommunicator() const override { return Communicator(m_machine_communicator); }
160
161 MpiLock* mpiLock() const { return m_mpi_lock; }
162
163 MpiDatatypeList* datatypes() { return m_datatype_list; }
164
165 MpiSerializeDispatcher* serializeDispatcher() const { return m_mpi_serialize_dispatcher; }
166
167 public:
168
169 IParallelMngInternal* _internalApi() override { return m_parallel_mng_internal; }
170
171 protected:
172
173 ISerializeMessageList* _createSerializeMessageList() override;
174 IParallelMng* _createSubParallelMng(Int32ConstArrayView kept_ranks) override;
175 bool _isAcceleratorAware() const override;
176 Ref<IParallelMng> _createSubParallelMngRef(Int32 color, Int32 key) override;
177
178 public:
179
180 IGetVariablesValuesParallelOperation* createGetVariablesValuesOperation() override;
181 ITransferValuesParallelOperation* createTransferValuesOperation() override;
182 IParallelExchanger* createExchanger() override;
183 IParallelTopology* createTopology() override;
184 IVariableSynchronizer* createSynchronizer(IItemFamily* family) override;
185 IVariableSynchronizer* createSynchronizer(const ItemGroup& group) override;
186 Parallel::IStat* stat() override { return m_stat; }
187 IParallelReplication* replication() const override;
188 void setReplication(IParallelReplication* v) override;
189 Ref<Parallel::IRequestList> createRequestListRef() override;
190 Ref<IParallelMngUtilsFactory> _internalUtilsFactory() const override;
191
192 private:
193
194 ITraceMng* m_trace = nullptr;
195 IThreadMng* m_thread_mng = nullptr;
196 IParallelMng* m_world_parallel_mng = nullptr;
197 IIOMng* m_io_mng = nullptr;
198 Ref<IParallelMng> m_sequential_parallel_mng;
199 ITimerMng* m_timer_mng = nullptr;
200 IParallelReplication* m_replication = nullptr;
201 bool m_is_timer_owned = false;
202 MpiDatatypeList* m_datatype_list = nullptr;
203 MpiAdapter* m_adapter = nullptr;
204 bool m_is_parallel = false;
205 Int32 m_comm_rank = A_NULL_RANK;
207 bool m_is_initialized = false;
208 Parallel::IStat* m_stat = nullptr;
209 MPI_Comm m_communicator = MPI_COMM_NULL;
210 MPI_Comm m_machine_communicator = MPI_COMM_NULL;
211 bool m_is_communicator_owned = false;
212 MpiLock* m_mpi_lock = nullptr;
213 IParallelNonBlockingCollective* m_non_blocking_collective = nullptr;
214 MpiSerializeDispatcher* m_mpi_serialize_dispatcher = nullptr;
215 Ref<IParallelMngUtilsFactory> m_utils_factory;
216 IParallelMngInternal* m_parallel_mng_internal = nullptr;
217
218 private:
219
220 void _checkFinishedSubRequests();
221 UniqueArray<Integer> _waitSomeRequests(ArrayView<Request> requests, bool is_non_blocking);
222 IParallelMng* _createSubParallelMng(MPI_Comm sub_communicator);
223};
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
227
228} // End namespace Arcane
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
233#endif
Modifiable view of an array of type T.
Operations to access variable values from another subdomain.
Interface of the input/output manager.
Definition IIOMng.h:37
Interface of an entity family.
Definition IItemFamily.h:85
Information exchange between processors.
Internal part of IParallelMng.
Interface of the parallelism manager for a subdomain.
Interface for non-blocking collective parallel operations.
Brief information on parallel subdomain replication.
Information on the computing core allocation topology.
Interface of a thread manager.
Definition IThreadMng.h:32
Interface of a timer manager.
Definition ITimerMng.h:50
Sends values across different processors.
Interface of a variable synchronization service.
Mesh entity group.
Definition ItemGroup.h:51
Communicator for message exchange.
Information about the source of a message.
Information for sending/receiving a point-to-point message.
Manages the MPI_Datatypes associated with Arcane types.
Specialization of MpiRequestList for MpiParallelMng.
IParallelMng * worldParallelMng() const override
Parallelism manager over all allocated resources.
bool m_is_initialized
true if already initialized
Int32 commRank() const override
Rank of this instance in the communicator.
Communicator machineCommunicator() const override
MPI communicator derived from the communicator communicator() gathering all processes of the compute ...
IThreadMng * threadMng() const override
Thread manager.
IIOMng * ioMng() const override
I/O manager.
bool isThreadImplementation() const override
Indicates if the implementation uses threads.
void * getMPICommunicator() override
Address of the MPI communicator associated with this manager.
ITimerMng * timerMng() const override
Timer manager.
IParallelNonBlockingCollective * nonBlockingCollective() const override
Interface for non-blocking collective operations.
Int32 m_comm_size
Number of subdomains.
bool isParallel() const override
Returns true if the execution is parallel.
ITraceMng * traceMng() const override
Trace manager.
Int32 m_comm_rank
Current processor number.
Communicator communicator() const override
MPI communicator associated with this instance.
Integer masterIORank() const override
Rank of the instance managing I/O (for which isMasterIO() is true).
Parallel::IStat * stat() override
Statistics manager.
bool isMasterIO() const override
true if the instance is a master I/O manager.
bool isHybridImplementation() const override
Indicates if the implementation uses hybrid mode.
IParallelMngInternal * _internalApi() override
Internal Arcane API.
Int32 commSize() const override
Number of instances in the communicator.
Reference to an instance.
Implementation of a buffer for serialization.
1D data vector with value semantics (STL style).
eReduceType
Supported reduction types.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:115
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:476
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.
Info to construct an MpiParallelMng.