Arcane  4.1.12.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-2025 */
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 Ref<MP::Dispatchers> dispatchersRef() const { return m_dispatchers_ref; }
56 Ref<MP::MessagePassingMng> messagePassingMngRef() const { return m_message_passing_mng_ref; }
57
58 public:
59
60 bool is_parallel;
61
62 private:
63
64 Int32 comm_rank;
65 Int32 comm_nb_rank;
66
67 public:
68
69 Parallel::IStat* stat = nullptr;
70 ITraceMng* trace_mng = nullptr;
71 ITimerMng* timer_mng = nullptr;
72 IThreadMng* thread_mng = nullptr;
73 IParallelMng* world_parallel_mng = nullptr;
74
75 private:
76
77 MPI_Comm mpi_comm;
78 MPI_Comm mpi_machine_comm;
79
80 public:
81
82 bool is_mpi_comm_owned;
83 MpiLock* mpi_lock = nullptr;
84
85 private:
86
87 Ref<MP::Dispatchers> m_dispatchers_ref;
88 Ref<MP::MessagePassingMng> m_message_passing_mng_ref;
89};
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
97class ARCANE_MPI_EXPORT MpiParallelMng
98: public ParallelMngDispatcher
99{
100 public:
101
102 friend ArcaneMpiSerializeMessageList;
103 class RequestList;
104 class Impl;
105
106 public:
107
108 explicit MpiParallelMng(const MpiParallelMngBuildInfo& bi);
109 ~MpiParallelMng() override;
110
111 bool isParallel() const override { return m_is_parallel; }
112 Int32 commRank() const override { return m_comm_rank; }
113 Int32 commSize() const override { return m_comm_size; }
114 void* getMPICommunicator() override { return &m_communicator; }
115 bool isThreadImplementation() const override { return false; }
116 bool isHybridImplementation() const override { return false; }
117 ITraceMng* traceMng() const override { return m_trace; }
118 IThreadMng* threadMng() const override { return m_thread_mng; }
119 IParallelMng* worldParallelMng() const override { return m_world_parallel_mng; }
120 IIOMng* ioMng() const override { return m_io_mng; }
121
122 void initialize() override;
123 bool isMasterIO() const override { return commRank() == 0; }
124 Integer masterIORank() const override { return 0; }
125
126 ITimerMng* timerMng() const override { return m_timer_mng; }
127
128 void sendSerializer(ISerializer* values, Int32 rank) override;
129 Request sendSerializer(ISerializer* values, Int32 rank, ByteArray& bytes) override;
130 ISerializeMessage* createSendSerializer(Int32 rank) override;
131
132 void recvSerializer(ISerializer* values, Int32 rank) override;
133 ISerializeMessage* createReceiveSerializer(Int32 rank) override;
134
135 void freeRequests(ArrayView<Parallel::Request> requests) override;
136
137 void broadcastSerializer(ISerializer* values, Int32 rank) override;
138 MessageId probe(const PointToPointMessageInfo& message) override;
139 MessageSourceInfo legacyProbe(const PointToPointMessageInfo& message) override;
140 Request sendSerializer(const ISerializer* values, const PointToPointMessageInfo& message) override;
141 Request receiveSerializer(ISerializer* values, const PointToPointMessageInfo& message) override;
142
143 void printStats() override;
144 IParallelMng* sequentialParallelMng() override;
145 Ref<IParallelMng> sequentialParallelMngRef() override;
146 void barrier() override;
147 void waitAllRequests(ArrayView<Request> requests) override;
148 UniqueArray<Integer> waitSomeRequests(ArrayView<Request> requests) override;
149 UniqueArray<Integer> testSomeRequests(ArrayView<Request> requests) override;
150 ARCANE_DEPRECATED_260 Real reduceRank(eReduceType rt, Real v, Int32* rank)
151 {
152 Real rv = reduce(rt, v);
153 if (rank)
154 *rank = 0;
155 return rv;
156 }
157
158 IParallelNonBlockingCollective* nonBlockingCollective() const override { return m_non_blocking_collective; }
159
160 void build() override;
161
162 public:
163
164 MpiAdapter* adapter() { return m_adapter; }
165 Communicator communicator() const override { return Communicator(m_communicator); }
166 Communicator machineCommunicator() const override { return Communicator(m_machine_communicator); }
167
168 MpiLock* mpiLock() const { return m_mpi_lock; }
169
170 MpiDatatypeList* datatypes() { return m_datatype_list; }
171
172 MpiSerializeDispatcher* serializeDispatcher() const { return m_mpi_serialize_dispatcher; }
173
174 public:
175
176 IParallelMngInternal* _internalApi() override { return m_parallel_mng_internal; }
177
178 protected:
179
180 ISerializeMessageList* _createSerializeMessageList() override;
181 IParallelMng* _createSubParallelMng(Int32ConstArrayView kept_ranks) override;
182 bool _isAcceleratorAware() const override;
183 Ref<IParallelMng> _createSubParallelMngRef(Int32 color, Int32 key) override;
184
185 public:
186
187 IGetVariablesValuesParallelOperation* createGetVariablesValuesOperation() override;
188 ITransferValuesParallelOperation* createTransferValuesOperation() override;
189 IParallelExchanger* createExchanger() override;
190 IParallelTopology* createTopology() override;
191 IVariableSynchronizer* createSynchronizer(IItemFamily* family) override;
192 IVariableSynchronizer* createSynchronizer(const ItemGroup& group) override;
193 Parallel::IStat* stat() override { return m_stat; }
194 IParallelReplication* replication() const override;
195 void setReplication(IParallelReplication* v) override;
196 Ref<Parallel::IRequestList> createRequestListRef() override;
197 Ref<IParallelMngUtilsFactory> _internalUtilsFactory() const override;
198
199 private:
200
201 ITraceMng* m_trace = nullptr;
202 IThreadMng* m_thread_mng = nullptr;
203 IParallelMng* m_world_parallel_mng = nullptr;
204 IIOMng* m_io_mng = nullptr;
205 Ref<IParallelMng> m_sequential_parallel_mng;
206 ITimerMng* m_timer_mng = nullptr;
207 IParallelReplication* m_replication = nullptr;
208 bool m_is_timer_owned = false;
209 MpiDatatypeList* m_datatype_list = nullptr;
210 MpiAdapter* m_adapter = nullptr;
211 bool m_is_parallel = false;
212 Int32 m_comm_rank = A_NULL_RANK;
214 bool m_is_initialized = false;
215 Parallel::IStat* m_stat = nullptr;
216 MPI_Comm m_communicator = MPI_COMM_NULL;
217 MPI_Comm m_machine_communicator = MPI_COMM_NULL;
218 bool m_is_communicator_owned = false;
219 MpiLock* m_mpi_lock = nullptr;
220 IParallelNonBlockingCollective* m_non_blocking_collective = nullptr;
221 MpiSerializeDispatcher* m_mpi_serialize_dispatcher = nullptr;
222 Ref<IParallelMngUtilsFactory> m_utils_factory;
223 IParallelMngInternal* m_parallel_mng_internal = nullptr;
224
225 private:
226
227 void _checkFinishedSubRequests();
228 UniqueArray<Integer> _waitSomeRequests(ArrayView<Request> requests, bool is_non_blocking);
229 IParallelMng* _createSubParallelMng(MPI_Comm sub_communicator);
230};
231
232/*---------------------------------------------------------------------------*/
233/*---------------------------------------------------------------------------*/
234
235} // End namespace Arcane
236
237/*---------------------------------------------------------------------------*/
238/*---------------------------------------------------------------------------*/
239
240#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:83
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 manager.
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:121
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.
Info to construct an MpiParallelMng.