Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
PointToPointMessageInfo.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/* PointToPointMessageInfo.h (C) 2000-2025 */
9/* */
10/* Information for point-to-point messages. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_MESSAGEPASSING_POINTTOPOINTINFO_H
13#define ARCCORE_MESSAGEPASSING_POINTTOPOINTINFO_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/message_passing/MessageId.h"
18#include "arccore/message_passing/MessageTag.h"
19#include "arccore/message_passing/MessageRank.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30/*!
31 * \brief Information for sending/receiving a point-to-point message.
32 *
33 * There are two ways to construct an instance of this class:
34 *
35 * 1. By providing a pair (destination rank, tag). The tag is optional
36 * and if not specified, its value will be that of MessageTag::defaultTag().
37 * 2. Via a MessageId obtained during a call to mpProbe(). In this latter
38 * case, the instance can only be used for reception via mpReceive().
39 *
40 * It is possible to specify whether the message will be blocking during
41 * construction or via the call to setBlocking(). By default, a message
42 * is created in blocking mode.
43 *
44 * The sender (emiterRank()) of the message is the sender and the
45 * destination (destinationRank()) is the receiver. For a send message (mpSend()),
46 * destinationRank() is therefore the rank of the one who will receive the message. For a
47 * receive message (mpReceive()), destinationRank() is the rank of the one from whom
48 * we wish to receive the message or A_NULL_RANK if we wish to receive from
49 * anyone.
50 *
51 * \note The sender is generally positioned by the IMessagePassingMng implementation
52 * because it corresponds to the rank of the one posting the message.
53 * The user never needs to specify it.
54 */
55class ARCCORE_MESSAGEPASSING_EXPORT PointToPointMessageInfo
56{
57 public:
58
59 enum class Type
60 {
61 T_RankTag,
62 T_MessageId,
63 T_Null
64 };
65
66 public:
67
68 //! Null message.
70
71 //! Blocking message with default tag and destination rank \a rank
73 : m_destination_rank(dest_rank)
74 , m_type(Type::T_RankTag)
75 {}
76
77 //! Message with default tag, destination \a dest_rank, and blocking
78 //mode \a blocking_type
80 : m_destination_rank(dest_rank)
81 , m_is_blocking(blocking_type == Blocking)
82 , m_type(Type::T_RankTag)
83 {}
84
85 //! Blocking message with tag \a tag and destination \a rank
87 : m_destination_rank(dest_rank)
88 , m_tag(tag)
89 , m_type(Type::T_RankTag)
90 {}
91
92 //! Message with tag \a tag, destination \a dest_rank, and blocking
93 //mode \a blocking_type
95 : m_destination_rank(dest_rank)
96 , m_tag(tag)
97 , m_is_blocking(blocking_type == Blocking)
98 , m_type(Type::T_RankTag)
99 {}
100
101 //! Blocking message associated with \a message_id
103 : m_message_id(message_id)
104 , m_type(Type::T_MessageId)
105 {
106 _setInfosFromMessageId();
107 }
108
109 //! Message associated with \a message_id with blocking mode \a blocking_type
111 : m_message_id(message_id)
112 , m_is_blocking(blocking_type == Blocking)
113 , m_type(Type::T_MessageId)
114 {
115 _setInfosFromMessageId();
116 }
117
118 public:
119
120 /*!
121 * \brief Message with default tag and source \a emiter_rank,
122 * destination \a dest_rank, and blocking mode \a blocking_type
123 */
124 ARCCORE_DEPRECATED_REASON("Y2022: This constructor is internal to Arcane and deprecated")
125 PointToPointMessageInfo(MessageRank emiter_rank, MessageRank dest_rank, eBlockingType blocking_type)
126 : m_emiter_rank(emiter_rank)
127 , m_destination_rank(dest_rank)
128 , m_is_blocking(blocking_type == Blocking)
129 , m_type(Type::T_RankTag)
130 {}
131
132 //! Blocking message with tag \a tag, source \a emiter_rank, and destination \a rank
133 ARCCORE_DEPRECATED_REASON("Y2022: This constructor is internal to Arcane and deprecated")
135 : m_emiter_rank(emiter_rank)
136 , m_destination_rank(dest_rank)
137 , m_tag(tag)
138 , m_type(Type::T_RankTag)
139 {}
140
141 //! Blocking message with default tag, source \a emiter_rank, and destination \a dest_rank
142 ARCCORE_DEPRECATED_REASON("Y2022: This constructor is internal to Arcane and deprecated")
144 : m_emiter_rank(emiter_rank)
145 , m_destination_rank(dest_rank)
146 , m_type(Type::T_RankTag)
147 {}
148
149 public:
150
151 /*!
152 * \internal
153 * \brief Message with tag \a tag, source \a emiter_rank,
154 * destination \a dest_rank, and blocking mode \a blocking_type.
155 */
156 PointToPointMessageInfo(MessageRank emiter_rank, MessageRank dest_rank, MessageTag tag, eBlockingType blocking_type)
157 : m_emiter_rank(emiter_rank)
158 , m_destination_rank(dest_rank)
159 , m_tag(tag)
160 , m_is_blocking(blocking_type == Blocking)
161 , m_type(Type::T_RankTag)
162 {}
163
164 public:
165
166 PointToPointMessageInfo& setBlocking(bool is_blocking)
167 {
168 m_is_blocking = is_blocking;
169 return (*this);
170 }
171 //! Indicates if the message is blocking.
172 bool isBlocking() const { return m_is_blocking; }
173 //! True if the instance was created with a MessageId. In this case messageId() is valid
174 bool isMessageId() const { return m_type == Type::T_MessageId; }
175 //! True if the instance was created with a pair (rank,tag). In this case rank() and tag() are valid.
176 bool isRankTag() const { return m_type == Type::T_RankTag; }
177 //! Message identifier
178 MessageId messageId() const { return m_message_id; }
179 //! Positions the message identifier and changes the message type
180 void setMessageId(const MessageId& message_id)
181 {
182 m_type = Type::T_MessageId;
183 m_message_id = message_id;
184 _setInfosFromMessageId();
185 }
186 //! Positions the message destination rank and tag and changes the message type
188 {
189 m_type = Type::T_RankTag;
190 // Attention to properly call the methods to update
191 // the associated values of `m_message_id`
192 setDestinationRank(rank);
193 setTag(tag);
194 }
195 //! Message destination rank
196 MessageRank destinationRank() const { return m_destination_rank; }
197 //! Positions the message destination rank
199 {
200 m_destination_rank = rank;
201 MessageId::SourceInfo si = m_message_id.sourceInfo();
202 si.setRank(rank);
203 m_message_id.setSourceInfo(si);
204 }
205
206 //! Message sender rank
207 MessageRank emiterRank() const { return m_emiter_rank; }
208 //! Positions the message sender rank
209 void setEmiterRank(MessageRank rank) { m_emiter_rank = rank; }
210
211 //! Message tag
212 MessageTag tag() const { return m_tag; }
213 //! Positions the message tag
215 {
216 m_tag = tag;
217 MessageId::SourceInfo si = m_message_id.sourceInfo();
218 si.setTag(tag);
219 m_message_id.setSourceInfo(si);
220 }
221 //! Prints the message
222 void print(std::ostream& o) const;
223
224 friend std::ostream& operator<<(std::ostream& o, const PointToPointMessageInfo& pmessage)
225 {
226 pmessage.print(o);
227 return o;
228 }
229
230 public:
231
232 // Indicates if the message is valid (i.e.: it was initialized with a valid message)
233 bool isValid() const
234 {
235 if (m_type == Type::T_Null)
236 return false;
237 if (m_type == Type::T_MessageId)
238 return m_message_id.isValid();
239 if (m_type == Type::T_RankTag)
240 return true;
241 return false;
242 }
243
244 public:
245
246 //! Message origin rank
247 ARCCORE_DEPRECATED_REASON("Y2022: Use emiterRank() instead")
248 MessageRank sourceRank() const { return m_emiter_rank; }
249
250 //! Positions the message origin rank
251 ARCCORE_DEPRECATED_REASON("Y2022: Use setEmiterRank() instead")
252 void setSourceRank(MessageRank rank) { m_emiter_rank = rank; }
253
254 private:
255
256 MessageRank m_emiter_rank;
257 MessageRank m_destination_rank;
259 MessageId m_message_id;
260 bool m_is_blocking = true;
261 Type m_type = Type::T_Null;
262
263 void _setInfosFromMessageId()
264 {
265 m_destination_rank = m_message_id.sourceInfo().rank();
266 m_tag = m_message_id.sourceInfo().tag();
267 }
268};
269
270/*---------------------------------------------------------------------------*/
271/*---------------------------------------------------------------------------*/
272
273} // namespace Arcane::MessagePassing
274
275/*---------------------------------------------------------------------------*/
276/*---------------------------------------------------------------------------*/
277
278#endif
MessageSourceInfo sourceInfo() const
Information about the message source;.
Definition MessageId.h:160
void setTag(MessageTag tag)
Sets the message tag.
MessageRank rank() const
Source rank.
void setRank(MessageRank rank)
Sets the source rank.
static MessageTag defaultTag()
Default tag for send/receive without tag argument.
Definition MessageTag.h:82
Information for sending/receiving a point-to-point message.
MessageRank emiterRank() const
Message sender rank.
PointToPointMessageInfo(MessageId message_id, eBlockingType blocking_type)
Message associated with message_id with blocking mode blocking_type.
void setEmiterRank(MessageRank rank)
Positions the message sender rank.
PointToPointMessageInfo(MessageRank dest_rank, MessageTag tag)
Blocking message with tag tag and destination rank.
MessageRank sourceRank() const
Message origin rank.
void setDestinationRank(MessageRank rank)
Positions the message destination rank.
void setMessageId(const MessageId &message_id)
Positions the message identifier and changes the message type.
void print(std::ostream &o) const
Prints the message.
bool isBlocking() const
Indicates if the message is blocking.
void setSourceRank(MessageRank rank)
Positions the message origin rank.
void setRankTag(MessageRank rank, MessageTag tag)
Positions the message destination rank and tag and changes the message type.
bool isRankTag() const
True if the instance was created with a pair (rank,tag). In this case rank() and tag() are valid.
void setTag(MessageTag tag)
Positions the message tag.
PointToPointMessageInfo(MessageRank dest_rank, eBlockingType blocking_type)
Message with default tag, destination dest_rank, and blocking.
PointToPointMessageInfo(MessageRank dest_rank)
Blocking message with default tag and destination rank rank.
PointToPointMessageInfo(MessageId message_id)
Blocking message associated with message_id.
bool isMessageId() const
True if the instance was created with a MessageId. In this case messageId() is valid.
MessageRank destinationRank() const
Message destination rank.
PointToPointMessageInfo(MessageRank dest_rank, MessageTag tag, eBlockingType blocking_type)
Message with tag tag, destination dest_rank, and blocking.
Declarations of types and methods used by message exchange mechanisms.
eBlockingType
Type indicating whether a message is blocking or not.