Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
GatherMessageInfo.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/* GatherMessageInfo.h (C) 2000-2025 */
9/* */
10/* Information for 'gather' messages. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_MESSAGEPASSING_GATHERMESSAGEINFO_H
13#define ARCCORE_MESSAGEPASSING_GATHERMESSAGEINFO_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/collections/Array.h"
18#include "arccore/message_passing/MessageRank.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
36class ARCCORE_MESSAGEPASSING_EXPORT GatherMessageInfoBase
37{
38 public:
39
41 enum class Mode
42 {
43 Gather,
44 GatherVariable,
45 GatherVariableNeedComputeInfo,
46 Null
47 };
48
49 public:
50
53
56 : m_destination_rank(dest_rank)
57 {}
58
61 : m_destination_rank(dest_rank)
62 , m_is_blocking(blocking_type == Blocking)
63 {}
64
65 public:
66
67 void setBlocking(bool is_blocking)
68 {
69 m_is_blocking = is_blocking;
70 }
72 bool isBlocking() const { return m_is_blocking; }
73
75 MessageRank destinationRank() const { return m_destination_rank; }
76
79 {
80 m_destination_rank = rank;
81 }
82
84 Mode mode() const { return m_mode; }
85
87 void print(std::ostream& o) const;
88
89 friend std::ostream& operator<<(std::ostream& o, const GatherMessageInfoBase& pmessage)
90 {
91 pmessage.print(o);
92 return o;
93 }
94
95 public:
96
97 // Indicates if the message is valid (i.e.: it has been initialized
98 // with a valid message)
99 bool isValid() const
100 {
101 if (m_mode == Mode::Null)
102 return false;
103 return true;
104 }
105
106 protected:
107
108 void _setType(Mode t)
109 {
110 m_mode = t;
111 }
112
113 private:
114
115 MessageRank m_destination_rank;
116 bool m_is_blocking = true;
117 Mode m_mode = Mode::Null;
118};
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
130template <typename DataType>
133{
134 public:
135
136 using BaseClass = GatherMessageInfoBase;
137
138 public:
139
141 GatherMessageInfo() = default;
142
144 explicit GatherMessageInfo(MessageRank dest_rank)
145 : BaseClass(dest_rank)
146 {}
147
150 : BaseClass(dest_rank, blocking_type)
151 {}
152
153 public:
154
163 {
164 _setType(Mode::Gather);
165 m_receive_buf = receive_buf;
166 m_send_buffer = send_buf;
167 }
168
185 {
186 _setType(Mode::GatherVariableNeedComputeInfo);
187 m_local_reception_buffer = receive_array;
188 m_send_buffer = send_buf;
189 }
190
200 Span<const Int32> receive_counts, Span<const Int32> receive_displacements)
201 {
202 _setType(Mode::GatherVariable);
203 m_receive_buf = receive_buf;
204 m_send_buffer = send_buf;
205 m_receive_displacements = receive_displacements;
206 m_receive_counts = receive_counts;
207 }
208
214 Array<DataType>* localReceptionBuffer() const { return m_local_reception_buffer; }
215
217 Span<const DataType> sendBuffer() const { return m_send_buffer; }
218
220 Span<DataType> receiveBuffer() const { return m_receive_buf; }
221
223 Span<const Int32> receiveDisplacement() { return m_receive_displacements; }
224
226 Span<const Int32> receiveCounts() const { return m_receive_counts; }
227
228 private:
229
230 Array<DataType>* m_local_reception_buffer = nullptr;
231 Span<const DataType> m_send_buffer;
232 Span<DataType> m_receive_buf;
233 Span<const Int32> m_receive_displacements;
234 Span<const Int32> m_receive_counts;
235};
236
237/*---------------------------------------------------------------------------*/
238/*---------------------------------------------------------------------------*/
239
240} // namespace Arcane::MessagePassing
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
245#endif
Base class for 1D data vectors.
Brief information for a 'gather' message.
GatherMessageInfoBase()=default
Message for everyone and blocking.
bool isBlocking() const
Indicates if the message is blocking.
void print(std::ostream &o) const
Prints the message.
GatherMessageInfoBase(MessageRank dest_rank)
Blocking message having destination rank.
void setDestinationRank(MessageRank rank)
Sets the rank of the message destination.
GatherMessageInfoBase(MessageRank dest_rank, eBlockingType blocking_type)
Message having destination dest_rank and blocking mode blocking_type.
MessageRank destinationRank() const
Rank of the message destination.
Span< const DataType > sendBuffer() const
Send buffer. It is used in all modes.
GatherMessageInfo()=default
Message for everyone and blocking.
Array< DataType > * localReceptionBuffer() const
Receive buffer for the T_GatherVariableNeedComputeInfo type.
GatherMessageInfo(MessageRank dest_rank, eBlockingType blocking_type)
Message having destination dest_rank and blocking mode blocking_type.
Span< const Int32 > receiveCounts() const
Counts array. Used in GatherVariable mode.
Span< DataType > receiveBuffer() const
Receive buffer. Used in Gather and GatherVariable mode by ranks that receive.
void setGatherVariable(Span< const DataType > send_buf, Array< DataType > *receive_array)
Brief message equivalent to MPI_Gatherv or MPI_Allgatherv.
GatherMessageInfo(MessageRank dest_rank)
Blocking message having destination rank.
void setGather(Span< const DataType > send_buf, Span< DataType > receive_buf)
Brief message equivalent to MPI_Gather or MPI_Allgather.
Span< const Int32 > receiveDisplacement()
Displacement array. Used in GatherVariable mode.
void setGatherVariable(Span< const DataType > send_buf, Span< DataType > receive_buf, Span< const Int32 > receive_counts, Span< const Int32 > receive_displacements)
Brief message equivalent to MPI_Gatherv or MPI_Allgatherv.
View of an array of elements of type T.
Definition Span.h:635
Declarations of types and methods used by message exchange mechanisms.
eBlockingType
Type indicating whether a message is blocking or not.