Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
BasicSerializeMessage.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/* BasicSerialize.h (C) 2000-2025 */
9/* */
10/* Message using a BasicSerializer. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_MESSAGEPASSING_BASICSERIALIZEMESSAGE_H
13#define ARCCORE_MESSAGEPASSING_BASICSERIALIZEMESSAGE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/serialize/BasicSerializer.h"
18#include "arccore/message_passing/ISerializeMessage.h"
19#include "arccore/message_passing/MessageRank.h"
20#include "arccore/message_passing/MessageTag.h"
21#include "arccore/message_passing/MessageId.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane::MessagePassing::internal
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33/*!
34 * \internal
35 * \brief Serializing message using a BasicSerializer.
36 *
37 * This class is internal to %Arccore and should not be used
38 * directly. If you want to create an instance of ISerializeMessage,
39 * you must create a list of messages via
40 * ISerializeMessageList::createMessage();
41 *
42 * A message consists of a series of bytes sent or received from a rank
43 * (source()) to another (destination()). If isSend() is true,
44 * source() sends bytes to destination(), otherwise source()
45 * receives bytes from destination().
46 * If it is a reception message, the serializer() is allocated
47 * and filled automatically.
48 */
49class ARCCORE_MESSAGEPASSING_EXPORT BasicSerializeMessage
50: public ISerializeMessage
51{
52 public:
53
54 static const Int32 DEFAULT_SERIALIZE_TAG_VALUE = 101;
55
56 //! Default tag for serialization messages
57 static MessageTag defaultTag() { return MessageTag(DEFAULT_SERIALIZE_TAG_VALUE); }
58
59 protected:
60 public:
61
62 ~BasicSerializeMessage() override;
63 BasicSerializeMessage& operator=(const BasicSerializeMessage&) = delete;
65
66 protected:
67
74 BasicSerializer* serializer);
77 BasicSerializer* serializer);
78
79 BasicSerializeMessage(MessageRank orig_rank, MessageId message_id,
80 BasicSerializer* serializer);
81
82 public:
83
85 create(MessageRank source, MessageRank destination, ePointToPointMessageType type);
87 create(MessageRank source, MessageRank destination, MessageTag tag,
90 create(MessageRank source, MessageId message_id);
91
92 public:
93
94 bool isSend() const override { return m_is_send; }
95 eMessageType messageType() const override { return m_old_message_type; }
96 Int32 destRank() const override { return m_dest_rank.value(); }
97 Int32 origRank() const override { return m_orig_rank.value(); }
98 MessageRank destination() const override { return m_dest_rank; }
99 MessageRank source() const override { return m_orig_rank; }
100 ISerializer* serializer() override { return m_buffer; }
101 bool finished() const override { return m_finished; }
102 void setFinished(bool v) override { m_finished = v; }
103 void setTag(Int32 tag) override { m_tag = MessageTag(tag); }
104 Int32 tag() const override { return m_tag.value(); }
105 void setInternalTag(MessageTag tag) override { m_tag = tag; }
106 MessageTag internalTag() const override { return m_tag; }
107 MessageId _internalMessageId() const override { return m_message_id; }
108 void setStrategy(eStrategy strategy) override;
109 eStrategy strategy() const override { return m_strategy; }
110 bool isProcessed() const override { return m_is_processed; }
111
112 public:
113
114 BasicSerializer& buffer() { return *m_buffer; }
115 BasicSerializer* trueSerializer() const { return m_buffer; }
116 Int32 messageNumber() const { return m_message_number; }
117 void setMessageNumber(Int32 v) { m_message_number = v; }
118 void setIsProcessed(bool v) { m_is_processed = v; }
119 ePointToPointMessageType _internalMessageType() const { return m_message_type; }
120
121 protected:
122
123 static ePointToPointMessageType _toP2PType(eMessageType mtype);
124 static eMessageType _toMessageType(ePointToPointMessageType mtype);
125
126 private:
127
128 MessageRank m_orig_rank; //!< Rank of the request sender
129 MessageRank m_dest_rank; //!< Rank of the message recipient
130 MessageTag m_tag = defaultTag();
131 eMessageType m_old_message_type; //!< Message type (obsolete)
132 ePointToPointMessageType m_message_type; //!< Message type
133 eStrategy m_strategy = eStrategy::Default;
134 bool m_is_send; //!< \c true if sending, \c false if receiving
135 BasicSerializer* m_buffer = nullptr; //!< Buffer containing the info
136 bool m_finished = false; //!< \c true if message finished
137 MessageId m_message_id; //!< Associated MessageId (can be null)
138 Int32 m_message_number = 0; //! Message number when using multiple messages
139 bool m_is_processed = false;
140
141 private:
142
143 void _init();
144};
145
146/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
149} // namespace Arcane::MessagePassing::internal
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154#endif
Int32 destRank() const override
Destination rank (if isSend() is true) or sender.
eStrategy strategy() const override
Strategy used for sends/receives.
MessageRank source() const override
Message sender rank.
bool isSend() const override
true if it should send, false if it should receive
bool isProcessed() const override
Indicates if the message has already been processed.
MessageRank destination() const override
Destination rank (if isSend() is true) or sender.
static MessageTag defaultTag()
Default tag for serialization messages.
bool finished() const override
true if the message is finished
eMessageType messageType() const override
Message type.
Int32 origRank() const override
Message sender rank See also destRank() for interpretation based on the value of isSend().
Reference to an instance.
ePointToPointMessageType
Point-to-point message type.
eMessageType
Stream on which messages are sent.
std::int32_t Int32
Signed integer type of 32 bits.