Arcane  4.2.3.0
User documentation
Loading...
Searching...
No Matches
Messages.h
Go to the documentation of this file.
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/* Messages.h (C) 2000-2026 */
9/* */
10/* Interface for the message exchange manager. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_MESSAGEPASSING_MESSAGES_H
13#define ARCCORE_MESSAGEPASSING_MESSAGES_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/message_passing/IMessagePassingMng.h"
18#include "arccore/message_passing/IDispatchers.h"
19#include "arccore/message_passing/ITypeDispatcher.h"
20#include "arccore/message_passing/Request.h"
21
23#include "arccore/base/Span.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34#define ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(type) \
35 /*! AllGather */ \
36 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
37 mpAllGather(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf); \
38 /*! gather */ \
39 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
40 mpGather(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf, Int32 rank); \
41 /*! Non-blocking AllGather */ \
42 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
43 mpNonBlockingAllGather(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf); \
44 /*! Non-blocking Gather */ \
45 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
46 mpNonBlockingGather(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf, Int32 rank); \
47 /*! AllGatherVariable */ \
48 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
49 mpAllGatherVariable(IMessagePassingMng* pm, Span<const type> send_buf, Array<type>& recv_buf); \
50 /*! GatherVariable */ \
51 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
52 mpGatherVariable(IMessagePassingMng* pm, Span<const type> send_buf, Array<type>& recv_buf, Int32 rank); \
53 /*! Generic Gather */ \
54 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
55 mpGather(IMessagePassingMng* pm, GatherMessageInfo<type>& gather_info); \
56 /*! ScatterVariable */ \
57 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
58 mpScatterVariable(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf, Int32 root); \
59 /*! AllReduce */ \
60 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT type \
61 mpAllReduce(IMessagePassingMng* pm, eReduceType rt, type v); \
62 /*! AllReduce in place */ \
63 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
64 mpAllReduce(IMessagePassingMng* pm, eReduceType rt, Span<type> buf); \
65 /*! AllReduce */ \
66 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
67 mpAllReduce(IMessagePassingMng* pm, eReduceType rt, Span<const type> send_buf, Span<type> receive_buf); \
68 /*! Scan Exclusive */ \
69 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
70 mpScanExclusive(IMessagePassingMng* pm, eReduceType rt, Span<const type> send_buf, Span<type> receive_buf); \
71 /*! Non-blocking AllReduce */ \
72 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
73 mpNonBlockingAllReduce(IMessagePassingMng* pm, eReduceType rt, Span<const type> send_buf, Span<type> recv_buf); \
74 /*! Broadcast */ \
75 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
76 mpBroadcast(IMessagePassingMng* pm, Span<type> send_buf, Int32 rank); \
77 /*! Non-blocking Broadcast */ \
78 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
79 mpNonBlockingBroadcast(IMessagePassingMng* pm, Span<type> send_buf, Int32 rank); \
80 /*! Send */ \
81 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
82 mpSend(IMessagePassingMng* pm, Span<const type> values, Int32 rank); \
83 /*! Receive */ \
84 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
85 mpReceive(IMessagePassingMng* pm, Span<type> values, Int32 rank); \
86 /*! Send */ \
87 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
88 mpSend(IMessagePassingMng* pm, Span<const type> values, Int32 rank, bool is_blocked); \
89 /*! Send */ \
90 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
91 mpSend(IMessagePassingMng* pm, Span<const type> values, const PointToPointMessageInfo& message); \
92 /*! Receive */ \
93 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
94 mpReceive(IMessagePassingMng* pm, Span<type> values, Int32 rank, bool is_blocked); \
95 /*! Receive */ \
96 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
97 mpReceive(IMessagePassingMng* pm, Span<type> values, const PointToPointMessageInfo& message); \
98 /*! AllToAll */ \
99 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
100 mpAllToAll(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf, Int32 count); \
101 /*! Non-blocking AllToAll */ \
102 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
103 mpNonBlockingAllToAll(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf, Int32 count); \
104 /*! AllToAllVariable */ \
105 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
106 mpAllToAllVariable(IMessagePassingMng* pm, Span<const type> send_buf, ConstArrayView<Int32> send_count, \
107 ConstArrayView<Int32> send_index, Span<type> recv_buf, \
108 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index); \
109 /*! Non-blocking AllToAllVariable */ \
110 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
111 mpNonBlockingAllToAllVariable(IMessagePassingMng* pm, Span<const type> send_buf, ConstArrayView<Int32> send_count, \
112 ConstArrayView<Int32> send_index, Span<type> recv_buf, \
113 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index);
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118/*!
119 * \brief Creates a list of requests.
120 *
121 * \sa IRequestList
122 */
123ARCCORE_MESSAGEPASSING_EXPORT Ref<IRequestList>
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
129/*!
130 * \brief Blocks until the requests in \a requests are finished.
131 */
132ARCCORE_MESSAGEPASSING_EXPORT void
133mpWaitAll(IMessagePassingMng* pm, ArrayView<Request> requests);
134
135/*---------------------------------------------------------------------------*/
136/*---------------------------------------------------------------------------*/
137
138/*!
139 * \brief Blocks until the request \a request is finished.
140 */
141ARCCORE_MESSAGEPASSING_EXPORT void
142mpWait(IMessagePassingMng* pm, Request request);
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
146
147/*!
148 * \brief Blocks until at least one of the requests in \a request is finished.
149 *
150 * In return, the array \a indexes contains the value \a true to indicate
151 * that a request is finished.
152 */
153ARCCORE_MESSAGEPASSING_EXPORT void
154mpWaitSome(IMessagePassingMng* pm, ArrayView<Request> requests, ArrayView<bool> indexes);
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159/*!
160 * \brief Tests if any of the requests in \a request are finished.
161 *
162 * In return, the array \a indexes contains the value \a true to indicate
163 * that a request is finished.
164 */
165ARCCORE_MESSAGEPASSING_EXPORT void
166mpTestSome(IMessagePassingMng* pm, ArrayView<Request> requests, ArrayView<bool> indexes);
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171/*!
172 * \brief General function for waiting for request completion.
173 *
174 * Depending on the value of \a wait_type, calls mpWait(), mpWaitSome(), or
175 * mpTestSome().
176 */
177ARCCORE_MESSAGEPASSING_EXPORT void
178mpWait(IMessagePassingMng* pm, ArrayView<Request> requests,
179 ArrayView<bool> indexes, eWaitType wait_type);
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184/*!
185 * \brief Tests if a message is available.
186 *
187 * This function checks if a message originating from the (rank,tag) pair
188 * is available. \a message must have been initialized with a (rank,tag) pair
189 * (message.isRankTag() must be true).
190 *
191 * Returns an instance of \a MessageId.
192 *
193 * In non-blocking mode, if no message is available, then
194 * MessageId::isValid() is false for the returned instance.
195 *
196 * The semantics are identical to MPI_Mprobe. The returned message is removed
197 * from the message list, and thus a subsequent call to this method with the same
198 * parameters will return another message or a null message. If you want behavior
199 * identical to MPI_Iprobe()/MPI_Probe(), you must use mpLegacyProbe().
200 */
201ARCCORE_MESSAGEPASSING_EXPORT MessageId
203
204/*---------------------------------------------------------------------------*/
205/*---------------------------------------------------------------------------*/
206
207/*!
208 * \brief Tests if a message is available.
209 *
210 * This function checks if a message originating from the (rank,tag) pair
211 * is available. \a message must have been initialized with a (rank,tag) pair
212 * (message.isRankTag() must be true).
213 *
214 * Returns an instance of \a MessageSourceInfo. In non-blocking mode, if no message
215 * is available, then MessageSourceInfo::isValid() is false for
216 * the returned instance.
217 *
218 * The semantics are identical to MPI_Probe. Therefore, it is possible
219 * to return the same message if this function is called multiple times.
220 * It is also not guaranteed that if you perform an mpReceive() with the instance
221 * returned, you will get the same message. For all these reasons, it is preferable
222 * to use the mpProbe() function.
223 */
224ARCCORE_MESSAGEPASSING_EXPORT MessageSourceInfo
226
227/*---------------------------------------------------------------------------*/
228/*---------------------------------------------------------------------------*/
229/*!
230 * \brief Creates a sub communicator.
231 *
232 * \a keep is true if this rank is present in the new communicator.
233 *
234 * The returned value is null if \a keep is false. If not null, the returned
235 * instance must be destroyed by calling the operator operator delete().
236 *
237 * \deprecated Use mpSplitCommunicator() instead.
238 */
239ARCCORE_DEPRECATED_REASON("Y2026: Use mpSplitCommunicator() instead.")
240ARCCORE_MESSAGEPASSING_EXPORT IMessagePassingMng*
241mpSplit(IMessagePassingMng* pm, bool keep);
242
243/*---------------------------------------------------------------------------*/
244/*---------------------------------------------------------------------------*/
245/*!
246 * \brief Creates a sub communicator.
247 *
248 * \a keep is true if this rank is present in the new communicator.
249 *
250 * The returned value is null if \a keep is false.
251 */
252ARCCORE_MESSAGEPASSING_EXPORT Ref<IMessagePassingMng>
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258/*!
259 * \brief Performs a barrier
260 *
261 * Blocks until all ranks have reached this call.
262 */
263ARCCORE_MESSAGEPASSING_EXPORT void
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
268
269/*!
270 * \brief Performs a non-blocking barrier.
271 */
272ARCCORE_MESSAGEPASSING_EXPORT Request
274
275/*---------------------------------------------------------------------------*/
276/*---------------------------------------------------------------------------*/
277
278/*!
279 * \brief Creates a serialization message list.
280 *
281 * \sa ISerializeMessageList
282 */
283ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessageList>
285
286//! Send message using an ISerializer.
287ARCCORE_MESSAGEPASSING_EXPORT Request
288mpSend(IMessagePassingMng* pm, const ISerializer* values, const PointToPointMessageInfo& message);
289
290//! Receive message using an ISerializer.
291ARCCORE_MESSAGEPASSING_EXPORT Request
292mpReceive(IMessagePassingMng* pm, ISerializer* values, const PointToPointMessageInfo& message);
293
294//! allGather() message for serialization
295ARCCORE_MESSAGEPASSING_EXPORT void
296mpAllGather(IMessagePassingMng* pm, const ISerializer* send_serializer, ISerializer* recv_serializer);
297
298/*---------------------------------------------------------------------------*/
299/*---------------------------------------------------------------------------*/
300
301/*!
302 * \brief Creates a serialization message.
303 *
304 * \a type is the message type and \a target is the target.
305 * If the message is a send, \a target is the message destination.
306 * If the message is a receive, \a target is the message source.
307 *
308 * \sa ISerializeMessageList
309 */
310ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessage>
312
313/*!
314 * \brief Creates a serialization message corresponding to \a id.
315 *
316 * \sa ISerializeMessageList
317 */
318ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessage>
320
321/*!
322 * \brief Creates a serialization message for sending.
323 *
324 * This method is equivalent to
325 * mpCreateSerializeMessage(pm, destination, ePointToPointMessageType::MsgSend).
326 *
327 * \sa ISerializeMessageList
328 */
329ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessage>
331
332/*!
333 * \brief Creates a serialization message for receiving.
334 *
335 * This method is equivalent to
336 * mpCreateSerializeMessage(pm, source, ePointToPointMessageType::MsgReceive).
337 *
338 * \sa ISerializeMessageList
339 */
340ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessage>
342
343/*---------------------------------------------------------------------------*/
344/*---------------------------------------------------------------------------*/
345
346ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(char)
347ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(signed char)
348ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned char)
349
350ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(short)
351ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned short)
352ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(int)
353ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned int)
354ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(long)
355ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned long)
356ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(long long)
357ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned long long)
358
359ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(float)
360ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(double)
361ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(long double)
362
363ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(BFloat16)
364ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(Float16)
365
366#undef ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE
367
368/*---------------------------------------------------------------------------*/
369/*---------------------------------------------------------------------------*/
370
371} // namespace Arcane::MessagePassing
372
373/*---------------------------------------------------------------------------*/
374/*---------------------------------------------------------------------------*/
375
377{
409} // namespace Arccore::MessagePassing
410
411/*---------------------------------------------------------------------------*/
412/*---------------------------------------------------------------------------*/
413
414#endif
Types and functions associated with the classes SpanImpl, SmallSpan and Span.
Half-precision floating-point type.
Interface of the message passing manager.
Information about the source of a message.
Information for sending/receiving a point-to-point message.
Declarations of types and methods used by message exchange mechanisms.
C void mpGather(IMessagePassingMng *pm, Span< const char > send_buf, Span< char > recv_buf, Int32 rank)
Ref< ISerializeMessage > mpCreateSerializeMessage(IMessagePassingMng *pm, MessageRank target, ePointToPointMessageType type)
Creates a serialization message.
Definition Messages.cc:335
C void mpScatterVariable(IMessagePassingMng *pm, Span< const char > send_buf, Span< char > recv_buf, Int32 root)
C Request mpNonBlockingAllGather(IMessagePassingMng *pm, Span< const char > send_buf, Span< char > recv_buf)
C void mpBroadcast(IMessagePassingMng *pm, Span< char > send_buf, Int32 rank)
void mpTestSome(IMessagePassingMng *pm, ArrayView< Request > requests, ArrayView< bool > indexes)
Tests if any of the requests in request are finished.
Definition Messages.cc:190
Ref< ISerializeMessageList > mpCreateSerializeMessageListRef(IMessagePassingMng *pm)
Creates a serialization message list.
Definition Messages.cc:279
Ref< ISerializeMessage > mpCreateSendSerializeMessage(IMessagePassingMng *pm, MessageRank destination)
Creates a serialization message for sending.
Definition Messages.cc:347
MessageSourceInfo mpLegacyProbe(IMessagePassingMng *pm, const PointToPointMessageInfo &message)
Tests if a message is available.
Definition Messages.cc:230
Ref< IMessagePassingMng > mpSplitCommunicator(IMessagePassingMng *pm, bool keep)
Creates a sub communicator.
Definition Messages.cc:250
Ref< ISerializeMessage > mpCreateReceiveSerializeMessage(IMessagePassingMng *pm, MessageRank source)
Creates a serialization message for receiving.
Definition Messages.cc:353
MessageId mpProbe(IMessagePassingMng *pm, const PointToPointMessageInfo &message)
Tests if a message is available.
Definition Messages.cc:220
C void mpAllToAll(IMessagePassingMng *pm, Span< const char > send_buf, Span< char > recv_buf, Int32 count)
C Request mpNonBlockingAllToAll(IMessagePassingMng *pm, Span< const char > send_buf, Span< char > recv_buf, Int32 count)
C void mpAllToAllVariable(IMessagePassingMng *pm, Span< const char > send_buf, ConstArrayView< Int32 > send_count, ConstArrayView< Int32 > send_index, Span< char > recv_buf, ConstArrayView< Int32 > recv_count, ConstArrayView< Int32 > recv_index)
C void mpGatherVariable(IMessagePassingMng *pm, Span< const char > send_buf, Array< char > &recv_buf, Int32 rank)
C char mpAllReduce(IMessagePassingMng *pm, eReduceType rt, char v)
Ref< IRequestList > mpCreateRequestListRef(IMessagePassingMng *pm)
Creates a list of requests.
Definition Messages.cc:155
C void mpAllGatherVariable(IMessagePassingMng *pm, Span< const char > send_buf, Array< char > &recv_buf)
void mpBarrier(IMessagePassingMng *pm)
Performs a barrier.
Definition Messages.cc:259
Request mpNonBlockingBarrier(IMessagePassingMng *pm)
Performs a non-blocking barrier.
Definition Messages.cc:269
void mpWait(IMessagePassingMng *pm, Request request)
Blocks until the request request is finished.
Definition Messages.cc:173
void mpAllGather(IMessagePassingMng *pm, const ISerializer *send_serializer, ISerializer *receive_serialize)
allGather() message for serialization
Definition Messages.cc:319
void mpWaitAll(IMessagePassingMng *pm, ArrayView< Request > requests)
Blocks until the requests in requests are finished.
Definition Messages.cc:164
IMessagePassingMng * mpSplit(IMessagePassingMng *pm, bool keep)
Creates a sub communicator.
Definition Messages.cc:240
C Request mpNonBlockingAllToAllVariable(IMessagePassingMng *pm, Span< const char > send_buf, ConstArrayView< Int32 > send_count, ConstArrayView< Int32 > send_index, Span< char > recv_buf, ConstArrayView< Int32 > recv_count, ConstArrayView< Int32 > recv_index)
ePointToPointMessageType
Point-to-point message type.
C Request mpNonBlockingGather(IMessagePassingMng *pm, Span< const char > send_buf, Span< char > recv_buf, Int32 rank)
Request mpReceive(IMessagePassingMng *pm, ISerializer *values, const PointToPointMessageInfo &message)
Receive message using an ISerializer.
Definition Messages.cc:300
void mpWaitSome(IMessagePassingMng *pm, ArrayView< Request > requests, ArrayView< bool > indexes)
Blocks until at least one of the requests in request is finished.
Definition Messages.cc:181
C Request mpNonBlockingBroadcast(IMessagePassingMng *pm, Span< char > send_buf, Int32 rank)
Request mpSend(IMessagePassingMng *pm, const ISerializer *values, const PointToPointMessageInfo &message)
Send message using an ISerializer.
Definition Messages.cc:289
C Request mpNonBlockingAllReduce(IMessagePassingMng *pm, eReduceType rt, Span< const char > send_buf, Span< char > recv_buf)
Namespace containing the types and declarations that manage the message-passing parallelism mechanism...