Arcane  4.1.12.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-2025 */
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 */ \
63 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
64 mpAllReduce(IMessagePassingMng* pm, eReduceType rt, Span<type> buf); \
65 /*! Non-blocking AllReduce */ \
66 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
67 mpNonBlockingAllReduce(IMessagePassingMng* pm, eReduceType rt, Span<const type> send_buf, Span<type> recv_buf); \
68 /*! Broadcast */ \
69 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
70 mpBroadcast(IMessagePassingMng* pm, Span<type> send_buf, Int32 rank); \
71 /*! Non-blocking Broadcast */ \
72 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
73 mpNonBlockingBroadcast(IMessagePassingMng* pm, Span<type> send_buf, Int32 rank); \
74 /*! Send */ \
75 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
76 mpSend(IMessagePassingMng* pm, Span<const type> values, Int32 rank); \
77 /*! Receive */ \
78 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
79 mpReceive(IMessagePassingMng* pm, Span<type> values, Int32 rank); \
80 /*! Send */ \
81 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
82 mpSend(IMessagePassingMng* pm, Span<const type> values, Int32 rank, bool is_blocked); \
83 /*! Send */ \
84 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
85 mpSend(IMessagePassingMng* pm, Span<const type> values, const PointToPointMessageInfo& message); \
86 /*! Receive */ \
87 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
88 mpReceive(IMessagePassingMng* pm, Span<type> values, Int32 rank, bool is_blocked); \
89 /*! Receive */ \
90 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
91 mpReceive(IMessagePassingMng* pm, Span<type> values, const PointToPointMessageInfo& message); \
92 /*! AllToAll */ \
93 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
94 mpAllToAll(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf, Int32 count); \
95 /*! Non-blocking AllToAll */ \
96 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
97 mpNonBlockingAllToAll(IMessagePassingMng* pm, Span<const type> send_buf, Span<type> recv_buf, Int32 count); \
98 /*! AllToAllVariable */ \
99 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT void \
100 mpAllToAllVariable(IMessagePassingMng* pm, Span<const type> send_buf, ConstArrayView<Int32> send_count, \
101 ConstArrayView<Int32> send_index, Span<type> recv_buf, \
102 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index); \
103 /*! Non-blocking AllToAllVariable */ \
104 extern "C++" ARCCORE_MESSAGEPASSING_EXPORT Request \
105 mpNonBlockingAllToAllVariable(IMessagePassingMng* pm, Span<const type> send_buf, ConstArrayView<Int32> send_count, \
106 ConstArrayView<Int32> send_index, Span<type> recv_buf, \
107 ConstArrayView<Int32> recv_count, ConstArrayView<Int32> recv_index);
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112/*!
113 * \brief Creates a list of requests.
114 *
115 * \sa IRequestList
116 */
117ARCCORE_MESSAGEPASSING_EXPORT Ref<IRequestList>
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123/*!
124 * \brief Blocks until the requests in \a requests are finished.
125 */
126ARCCORE_MESSAGEPASSING_EXPORT void
127mpWaitAll(IMessagePassingMng* pm, ArrayView<Request> requests);
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131
132/*!
133 * \brief Blocks until the request \a request is finished.
134 */
135ARCCORE_MESSAGEPASSING_EXPORT void
136mpWait(IMessagePassingMng* pm, Request request);
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
140
141/*!
142 * \brief Blocks until at least one of the requests in \a request is finished.
143 *
144 * In return, the array \a indexes contains the value \a true to indicate
145 * that a request is finished.
146 */
147ARCCORE_MESSAGEPASSING_EXPORT void
148mpWaitSome(IMessagePassingMng* pm, ArrayView<Request> requests, ArrayView<bool> indexes);
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
153/*!
154 * \brief Tests if any of the requests in \a request are finished.
155 *
156 * In return, the array \a indexes contains the value \a true to indicate
157 * that a request is finished.
158 */
159ARCCORE_MESSAGEPASSING_EXPORT void
160mpTestSome(IMessagePassingMng* pm, ArrayView<Request> requests, ArrayView<bool> indexes);
161
162/*---------------------------------------------------------------------------*/
163/*---------------------------------------------------------------------------*/
164
165/*!
166 * \brief General function for waiting for request completion.
167 *
168 * Depending on the value of \a wait_type, calls mpWait(), mpWaitSome(), or
169 * mpTestSome().
170 */
171ARCCORE_MESSAGEPASSING_EXPORT void
172mpWait(IMessagePassingMng* pm, ArrayView<Request> requests,
173 ArrayView<bool> indexes, eWaitType wait_type);
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
178/*!
179 * \brief Tests if a message is available.
180 *
181 * This function checks if a message originating from the (rank,tag) pair
182 * is available. \a message must have been initialized with a (rank,tag) pair
183 * (message.isRankTag() must be true).
184 *
185 * Returns an instance of \a MessageId.
186 *
187 * In non-blocking mode, if no message is available, then
188 * MessageId::isValid() is false for the returned instance.
189 *
190 * The semantics are identical to MPI_Mprobe. The returned message is removed
191 * from the message list, and thus a subsequent call to this method with the same
192 * parameters will return another message or a null message. If you want behavior
193 * identical to MPI_Iprobe()/MPI_Probe(), you must use mpLegacyProbe().
194 */
195ARCCORE_MESSAGEPASSING_EXPORT MessageId
197
198/*---------------------------------------------------------------------------*/
199/*---------------------------------------------------------------------------*/
200
201/*!
202 * \brief Tests if a message is available.
203 *
204 * This function checks if a message originating from the (rank,tag) pair
205 * is available. \a message must have been initialized with a (rank,tag) pair
206 * (message.isRankTag() must be true).
207 *
208 * Returns an instance of \a MessageSourceInfo. In non-blocking mode, if no message
209 * is available, then MessageSourceInfo::isValid() is false for
210 * the returned instance.
211 *
212 * The semantics are identical to MPI_Probe. Therefore, it is possible
213 * to return the same message if this function is called multiple times.
214 * It is also not guaranteed that if you perform an mpReceive() with the instance
215 * returned, you will get the same message. For all these reasons, it is preferable
216 * to use the mpProbe() function.
217 */
218ARCCORE_MESSAGEPASSING_EXPORT MessageSourceInfo
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
224/*!
225 * \brief Creates a new instance of \a IMessagePassingMng.
226 *
227 * \a keep is true if this rank is present in the new communicator.
228 *
229 * The returned instance must be destroyed by calling the operator
230 * operator delete().
231 */
232ARCCORE_MESSAGEPASSING_EXPORT IMessagePassingMng*
233mpSplit(IMessagePassingMng* pm, bool keep);
234
235/*---------------------------------------------------------------------------*/
236/*---------------------------------------------------------------------------*/
237
238/*!
239 * \brief Performs a barrier
240 *
241 * Blocks until all ranks have reached this call.
242 */
243ARCCORE_MESSAGEPASSING_EXPORT void
245
246/*---------------------------------------------------------------------------*/
247/*---------------------------------------------------------------------------*/
248
249/*!
250 * \brief Performs a non-blocking barrier.
251 */
252ARCCORE_MESSAGEPASSING_EXPORT Request
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258/*!
259 * \brief Creates a serialization message list.
260 *
261 * \sa ISerializeMessageList
262 */
263ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessageList>
265
266//! Send message using an ISerializer.
267ARCCORE_MESSAGEPASSING_EXPORT Request
268mpSend(IMessagePassingMng* pm, const ISerializer* values, const PointToPointMessageInfo& message);
269
270//! Receive message using an ISerializer.
271ARCCORE_MESSAGEPASSING_EXPORT Request
272mpReceive(IMessagePassingMng* pm, ISerializer* values, const PointToPointMessageInfo& message);
273
274//! allGather() message for serialization
275ARCCORE_MESSAGEPASSING_EXPORT void
276mpAllGather(IMessagePassingMng* pm, const ISerializer* send_serializer, ISerializer* recv_serializer);
277
278/*---------------------------------------------------------------------------*/
279/*---------------------------------------------------------------------------*/
280
281/*!
282 * \brief Creates a serialization message.
283 *
284 * \a type is the message type and \a target is the target.
285 * If the message is a send, \a target is the message destination.
286 * If the message is a receive, \a target is the message source.
287 *
288 * \sa ISerializeMessageList
289 */
290ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessage>
292
293/*!
294 * \brief Creates a serialization message corresponding to \a id.
295 *
296 * \sa ISerializeMessageList
297 */
298ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessage>
300
301/*!
302 * \brief Creates a serialization message for sending.
303 *
304 * This method is equivalent to
305 * mpCreateSerializeMessage(pm, destination, ePointToPointMessageType::MsgSend).
306 *
307 * \sa ISerializeMessageList
308 */
309ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessage>
311
312/*!
313 * \brief Creates a serialization message for receiving.
314 *
315 * This method is equivalent to
316 * mpCreateSerializeMessage(pm, source, ePointToPointMessageType::MsgReceive).
317 *
318 * \sa ISerializeMessageList
319 */
320ARCCORE_MESSAGEPASSING_EXPORT Ref<ISerializeMessage>
322
323/*---------------------------------------------------------------------------*/
324/*---------------------------------------------------------------------------*/
325
326ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(char)
327ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(signed char)
328ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned char)
329
330ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(short)
331ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned short)
332ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(int)
333ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned int)
334ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(long)
335ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned long)
336ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(long long)
337ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(unsigned long long)
338
339ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(float)
340ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(double)
341ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(long double)
342
343ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(BFloat16)
344ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE(Float16)
345
346#undef ARCCORE_GENERATE_MESSAGEPASSING_PROTOTYPE
347
348/*---------------------------------------------------------------------------*/
349/*---------------------------------------------------------------------------*/
350
351} // namespace Arcane::MessagePassing
352
353/*---------------------------------------------------------------------------*/
354/*---------------------------------------------------------------------------*/
355
357{
389} // namespace Arccore::MessagePassing
390
391/*---------------------------------------------------------------------------*/
392/*---------------------------------------------------------------------------*/
393
394#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:325
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:269
Ref< ISerializeMessage > mpCreateSendSerializeMessage(IMessagePassingMng *pm, MessageRank destination)
Creates a serialization message for sending.
Definition Messages.cc:337
MessageSourceInfo mpLegacyProbe(IMessagePassingMng *pm, const PointToPointMessageInfo &message)
Tests if a message is available.
Definition Messages.cc:230
Ref< ISerializeMessage > mpCreateReceiveSerializeMessage(IMessagePassingMng *pm, MessageRank source)
Creates a serialization message for receiving.
Definition Messages.cc:343
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:249
Request mpNonBlockingBarrier(IMessagePassingMng *pm)
Performs a non-blocking barrier.
Definition Messages.cc:259
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:309
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 new instance of IMessagePassingMng.
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:290
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:279
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...