Arcane  4.2.3.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-2026 */
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 void allReduce(eReduceType op, ConstArrayView<Type> send_buf, ArrayView<Type> receive_buf) override
150 {
151 m_mp_dispatcher->allReduce(op, send_buf, receive_buf);
152 }
153
154 public:
155
156 ARCANE_MPI_EXPORT void sendRecv(ConstArrayView<Type> send_buffer, ArrayView<Type> recv_buffer, Int32 rank) override;
157 ARCANE_MPI_EXPORT Type scan(eReduceType op, Type send_buf) override;
158 ARCANE_MPI_EXPORT void scan(eReduceType op, ArrayView<Type> send_buf) override;
159 ARCANE_MPI_EXPORT void computeMinMaxSum(Type val, Type& min_val, Type& max_val, Type& sum_val,
160 Int32& min_rank,
161 Int32& max_rank) override;
162 ARCANE_MPI_EXPORT void computeMinMaxSum(ConstArrayView<Type> values,
163 ArrayView<Type> min_values,
164 ArrayView<Type> max_values,
165 ArrayView<Type> sum_values,
166 ArrayView<Int32> min_ranks,
167 ArrayView<Int32> max_ranks) override;
168
169 public:
170
171 ITypeDispatcher<Type>* toArccoreDispatcher() override;
172 MpiDatatype* datatype() const;
173
174 public:
175
176 virtual ARCANE_MPI_EXPORT void computeMinMaxSumNoInit(Type& min_val, Type& max_val, Type& sum_val,
177 Int32& min_rank, Int32& max_rank);
178
179 private:
180
181 MP::Mpi::MpiTypeDispatcher<Type>* m_mp_dispatcher;
182
183 private:
184
185 MPI_Datatype m_min_max_sum_datatype;
186 MPI_Op m_min_max_sum_operator;
187
188 private:
189
190 void _initialize();
191 MPI_Datatype _mpiDatatype();
192 MpiAdapter* _adapter();
193 MPI_Op _mpiReduceOperator(eReduceType rt);
194 static void ARCANE_MPIOP_CALL _MinMaxSumOperator(void* a, void* b, int* len, MPI_Datatype* type);
195};
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
200template <typename Type> inline MpiParallelDispatchT<Type>*
201createBuiltInDispatcher(ITraceMng* tm, IMessagePassingMng* pm, MpiAdapter* adapter, MpiDatatypeList* dtlist)
202{
203 MpiDatatype* dt = dtlist->datatype(Type());
204 return new MpiParallelDispatchT<Type>(tm, pm, adapter, dt);
205}
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
210} // End namespace Arcane
211
212/*---------------------------------------------------------------------------*/
213/*---------------------------------------------------------------------------*/
214
215#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:476
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