Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MpiParallelDispatch.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/* MpiParallelDispatch.h (C) 2000-2025 */
9/* */
10/* Implementation of messages with MPI. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_PARALLEL_MPI_MPIPARALLELDISPATCH_H
13#define ARCANE_PARALLEL_MPI_MPIPARALLELDISPATCH_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/TraceAccessor.h"
18
19#include "arcane/core/IParallelDispatch.h"
20
21#include "arcane/parallel/mpi/ArcaneMpi.h"
22#include "arcane/parallel/mpi/MpiDatatypeList.h"
23
24#include "arccore/message_passing_mpi/internal/MpiTypeDispatcher.h"
25#include "arccore/message_passing/PointToPointMessageInfo.h"
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arcane
32{
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37class MpiParallelMng;
38namespace MP = ::Arccore::MessagePassing;
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
45template <class Type>
46class MpiParallelDispatchT
47: public TraceAccessor
49, public IParallelDispatchT<Type>
50{
52
53 private:
54
55 class ARCANE_MPI_EXPORT MinMaxSumInfo
56 {
57 public:
58
59 Integer m_min_rank;
60 Integer m_max_rank;
61 Type m_min_value;
62 Type m_max_value;
63 Type m_sum_value;
64 };
65
66 public:
67
68 typedef Parallel::Request Request;
69 typedef Parallel::eReduceType eReduceType;
70 using PointToPointMessageInfo = Parallel::PointToPointMessageInfo;
71
72 public:
73
74 ARCANE_MPI_EXPORT MpiParallelDispatchT(ITraceMng* tm, IMessagePassingMng* parallel_mng, MpiAdapter* adapter, MpiDatatype* datatype);
75
76 public:
77
78 ARCANE_MPI_EXPORT ~MpiParallelDispatchT() override;
79 ARCANE_MPI_EXPORT void finalize() override;
80
81 public:
82
83 void broadcast(ArrayView<Type> send_buf, Int32 rank) override
84 {
85 m_mp_dispatcher->broadcast(send_buf, rank);
86 }
87 void allGather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf) override
88 {
89 m_mp_dispatcher->allGather(send_buf, recv_buf);
90 }
91 void allGatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf) override
92 {
93 m_mp_dispatcher->allGatherVariable(send_buf, recv_buf);
94 }
95 void gather(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Int32 rank) override
96 {
97 m_mp_dispatcher->gather(send_buf, recv_buf, rank);
98 }
99 void gatherVariable(ConstArrayView<Type> send_buf, Array<Type>& recv_buf, Int32 rank) override
100 {
101 m_mp_dispatcher->gatherVariable(send_buf, recv_buf, rank);
102 }
103 void scatterVariable(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Int32 root) override
104 {
105 m_mp_dispatcher->scatterVariable(send_buf, recv_buf, root);
106 }
107 void allToAll(ConstArrayView<Type> send_buf, ArrayView<Type> recv_buf, Integer count) override
108 {
109 m_mp_dispatcher->allToAll(send_buf, recv_buf, count);
110 }
111 void allToAllVariable(ConstArrayView<Type> send_buf, Int32ConstArrayView send_count,
112 Int32ConstArrayView send_index, ArrayView<Type> recv_buf,
113 Int32ConstArrayView recv_count, Int32ConstArrayView recv_index) override
114 {
115 m_mp_dispatcher->allToAllVariable(send_buf, send_count, send_index, recv_buf, recv_count, recv_index);
116 }
117 Request send(ConstArrayView<Type> send_buffer, Int32 rank, bool is_blocked) override
118 {
119 return m_mp_dispatcher->send(send_buffer, rank, is_blocked);
120 }
121 Request send(Span<const Type> recv_buffer, const PointToPointMessageInfo& message) override
122 {
123 return m_mp_dispatcher->send(recv_buffer, message);
124 }
125 Request recv(ArrayView<Type> recv_buffer, Int32 rank, bool is_blocked) override
126 {
127 return m_mp_dispatcher->receive(recv_buffer, rank, is_blocked);
128 }
129 Request receive(Span<Type> recv_buffer, const PointToPointMessageInfo& message) override
130 {
131 return m_mp_dispatcher->receive(recv_buffer, message);
132 }
133 void send(ConstArrayView<Type> send_buffer, Int32 rank) override
134 {
135 m_mp_dispatcher->send(send_buffer, rank, true);
136 }
137 void recv(ArrayView<Type> recv_buffer, Int32 rank) override
138 {
139 m_mp_dispatcher->receive(recv_buffer, rank, true);
140 }
141 Type allReduce(eReduceType op, Type send_buf) override
142 {
143 return m_mp_dispatcher->allReduce(op, send_buf);
144 }
145 void allReduce(eReduceType op, ArrayView<Type> send_buf) override
146 {
147 m_mp_dispatcher->allReduce(op, send_buf);
148 }
149
150 public:
151
152 ARCANE_MPI_EXPORT void sendRecv(ConstArrayView<Type> send_buffer, ArrayView<Type> recv_buffer, Int32 rank) override;
153 ARCANE_MPI_EXPORT Type scan(eReduceType op, Type send_buf) override;
154 ARCANE_MPI_EXPORT void scan(eReduceType op, ArrayView<Type> send_buf) override;
155 ARCANE_MPI_EXPORT void computeMinMaxSum(Type val, Type& min_val, Type& max_val, Type& sum_val,
156 Int32& min_rank,
157 Int32& max_rank) override;
158 ARCANE_MPI_EXPORT void computeMinMaxSum(ConstArrayView<Type> values,
159 ArrayView<Type> min_values,
160 ArrayView<Type> max_values,
161 ArrayView<Type> sum_values,
162 ArrayView<Int32> min_ranks,
163 ArrayView<Int32> max_ranks) override;
164
165 public:
166
167 ITypeDispatcher<Type>* toArccoreDispatcher() override;
168 MpiDatatype* datatype() const;
169
170 public:
171
172 virtual ARCANE_MPI_EXPORT void computeMinMaxSumNoInit(Type& min_val, Type& max_val, Type& sum_val,
173 Int32& min_rank, Int32& max_rank);
174
175 private:
176
177 MP::Mpi::MpiTypeDispatcher<Type>* m_mp_dispatcher;
178
179 private:
180
181 MPI_Datatype m_min_max_sum_datatype;
182 MPI_Op m_min_max_sum_operator;
183
184 private:
185
186 void _initialize();
187 MPI_Datatype _mpiDatatype();
188 MpiAdapter* _adapter();
189 MPI_Op _mpiReduceOperator(eReduceType rt);
190 static void ARCANE_MPIOP_CALL _MinMaxSumOperator(void* a, void* b, int* len, MPI_Datatype* type);
191};
192
193/*---------------------------------------------------------------------------*/
194/*---------------------------------------------------------------------------*/
195
196template <typename Type> inline MpiParallelDispatchT<Type>*
197createBuiltInDispatcher(ITraceMng* tm, IMessagePassingMng* pm, MpiAdapter* adapter, MpiDatatypeList* dtlist)
198{
199 MpiDatatype* dt = dtlist->datatype(Type());
200 return new MpiParallelDispatchT<Type>(tm, pm, adapter, dt);
201}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
206} // End namespace Arcane
207
208/*---------------------------------------------------------------------------*/
209/*---------------------------------------------------------------------------*/
210
211#endif
#define ARCCORE_INTERNAL_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS(OPTIONAL_OVERRIDE)
Modifiable view of an array of type T.
Constant view of an array of type T.
Parallel message handling for the type Type.
Interface of the message passing manager.
Information for sending/receiving a point-to-point message.
Manages the MPI_Datatypes associated with Arcane types.
Message interface for type Type.
Parallelism manager using MPI.
Thread-safe implementation of a reference counter.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
eReduceType
Supported reduction types.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
std::int32_t Int32
Signed integer type of 32 bits.
Namespace containing the types and declarations that manage the message-passing parallelism mechanism...
Type
Type of JSON value.
Definition rapidjson.h:730