Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MachineShMemWin.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/* MachineShMemWin.h (C) 2000-2026 */
9/* */
10/* Class allowing the creation of memory windows for a compute node. */
11/* The segments of these windows are not contiguous in memory and can */
12/* be resized. */
13/*---------------------------------------------------------------------------*/
14#ifndef ARCANE_CORE_MACHINESHMEMWIN_H
15#define ARCANE_CORE_MACHINESHMEMWIN_H
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19#include "arcane/core/MachineShMemWinBase.h"
21#include "arcane/utils/Ref.h"
22
23#include "arccore/base/Span.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34/*!
35 * \brief Class allowing the creation of a shared memory window between
36 * sub-domains of the same node.
37 *
38 * The segments of this window are not contiguous in memory and can
39 * be resized.
40 *
41 * The \a add() method allows adding elements iteratively.
42 *
43 * \tparam Type The type of the window elements.
44 */
45template <class Type>
47{
48
49 public:
50
51 /*!
52 * \brief Constructor.
53 * \param pm The parallelMng to use.
54 * \param nb_elem_segment The initial number of elements.
55 */
56 MachineShMemWin(IParallelMng* pm, Int64 nb_elem_segment)
57 : m_impl(pm, nb_elem_segment, static_cast<Int32>(sizeof(Type)))
58 {}
59
60 /*!
61 * \brief Constructor.
62 * \param pm The parallelMng to use.
63 */
65 : m_impl(pm, 0, static_cast<Int32>(sizeof(Type)))
66 {}
67
68 public:
69
70 /*!
71 * \brief Method to obtain the ranks that possess a segment
72 * in the window.
73 *
74 * Non-collective call.
75 *
76 * \return A view containing the rank IDs.
77 */
79 {
80 return m_impl.machineRanks();
81 }
82
83 /*!
84 * \brief Method to wait until all processes/threads
85 * on the node call this method to continue execution.
86 */
87 void barrier() const
88 {
89 m_impl.barrier();
90 }
91 /*!
92 * \brief Method to obtain a view of our segment.
93 *
94 * Non-collective call.
95 *
96 * \return A view.
97 */
99 {
100 return asSpan<Type>(m_impl.segmentView());
101 }
102
103 /*!
104 * \brief Method to obtain a view of the segment of another
105 * sub-domain on the node.
106 *
107 * Non-collective call.
108 *
109 * \param rank The rank of the sub-domain.
110 * \return A view.
111 */
113 {
114 return asSpan<Type>(m_impl.segmentView(rank));
115 }
116
117 /*!
118 * \brief Method to obtain a view of our segment.
119 *
120 * Non-collective call.
121 *
122 * \return A view.
123 */
125 {
126 return asSpan<const Type>(m_impl.segmentConstView());
127 }
128
129 /*!
130 * \brief Method to obtain a view of the segment of another
131 * sub-domain on the node.
132 *
133 * Non-collective call.
134 *
135 * \param rank The rank of the sub-domain.
136 * \return A view.
137 */
139 {
140 return asSpan<const Type>(m_impl.segmentConstView(rank));
141 }
142
143 /*!
144 * \brief Method to add elements to our segment.
145 *
146 * Collective call.
147 *
148 * \note The methods add(..) and addToAnotherSegment(..) must not be mixed.
149 *
150 * If the segment is too small, it will be resized.
151 *
152 * Sub-domains that do not wish to add elements can call the
153 * \a add() method without parameters or this method with an empty view.
154 *
155 * \param elem The elements to add.
156 */
158 {
159 const Span<const std::byte> span_bytes(reinterpret_cast<const std::byte*>(elem.data()), elem.sizeBytes());
160 m_impl.add(span_bytes);
161 }
162
163 /*!
164 * \brief Method to be called by the sub-domain(s) that do not wish to add
165 * elements to their segment.
166 *
167 * Collective call.
168 *
169 * \note The methods add(..) and addToAnotherSegment(..) must not be mixed.
170 *
171 * See the documentation for \a add(Span<const std::byte> elem).
172 */
173 void add()
174 {
175 m_impl.add();
176 }
177
178 /*!
179 * \brief Method to add elements to the segment of another
180 * sub-domain.
181 *
182 * Collective call.
183 *
184 * \note The methods add(..) and addToAnotherSegment(..) must not be mixed.
185 *
186 * Two sub-domains must not add elements to the same
187 * sub-domain segment.
188 *
189 * If the target segment is too small, it will be resized.
190 *
191 * Sub-domains that do not wish to add elements can call the
192 * \a addToAnotherSegment() method without parameters.
193 *
194 * \param rank The rank of the sub-domain with the segment to modify.
195 * \param elem The elements to add.
196 */
198 {
199 const Span<const std::byte> span_bytes(reinterpret_cast<const std::byte*>(elem.data()), elem.sizeBytes());
200 m_impl.addToAnotherSegment(rank, span_bytes);
201 }
202
203 /*!
204 * \brief Method to be called by the sub-domain(s) that do not wish to add
205 * elements to the segment of another sub-domain.
206 *
207 * Collective call.
208 *
209 * \note The methods add(..) and addToAnotherSegment(..) must not be mixed.
210 *
211 * See the documentation for \a addToAnotherSegment(Int32 rank, Span<const Type> elem).
212 */
214 {
215 m_impl.addToAnotherSegment();
216 }
217
218 /*!
219 * \brief Method to reserve memory space in our segment.
220 *
221 * Collective call.
222 *
223 * This method does nothing if \a new_capacity is less than the memory
224 * already allocated for the segment.
225 * For sub-domains that do not wish to increase the memory space
226 * available for their segment, it is possible to set the parameter
227 * \a new_capacity to 0 or use the \a reserve() method (without
228 * arguments).
229 *
230 * The reserved space will have a size greater than or equal to
231 * \a new_capacity.
232 *
233 * This method does not resize the segment; you must always use
234 * the add() method to add elements.
235 *
236 * To resize the segment, the \a resize(Int64 new_size) method is
237 * available.
238 *
239 * \param new_capacity The requested new capacity.
240 */
241 void reserve(Int64 new_capacity)
242 {
243 m_impl.reserve(new_capacity);
244 }
245
246 /*!
247 * \brief Method to be called by the sub-domain(s) that do not wish to reserve
248 * more memory for their segments.
249 *
250 * Collective call.
251 *
252 * See the documentation for \a reserve(Int64 new_capacity).
253 */
254 void reserve()
255 {
256 m_impl.reserve();
257 }
258
259 /*!
260 * \brief Method to resize our segment.
261 *
262 * Collective call.
263 *
264 * If the provided size is less than the current size of the segment,
265 * elements located after the provided size will be deleted.
266 *
267 * For sub-domains that do not wish to resize their segment, it is
268 * possible to set the argument \a new_size to -1 or call the method
269 * \a resize() (without arguments).
270 *
271 * \param new_nb_elem The new size.
272 */
273 void resize(Int64 new_nb_elem)
274 {
275 m_impl.resize(new_nb_elem);
276 }
277
278 /*!
279 * \brief Method to be called by the sub-domain(s) that do not wish to
280 * resize their segments.
281 *
282 * Collective call.
283 *
284 * See the documentation for \a resize(Int64 new_nb_elem).
285 */
286 void resize()
287 {
288 m_impl.resize();
289 }
290
291 /*!
292 * \brief Method to reduce the reserved memory space for the
293 * segments to the minimum necessary.
294 *
295 * Collective call.
296 */
297 void shrink()
298 {
299 m_impl.shrink();
300 }
301
302 private:
303
304 MachineShMemWinBase m_impl;
305};
306
307/*---------------------------------------------------------------------------*/
308/*---------------------------------------------------------------------------*/
309
310} // End namespace Arcane
311
312/*---------------------------------------------------------------------------*/
313/*---------------------------------------------------------------------------*/
314
315#endif
Declarations of Arcane's general types.
Types and functions associated with the classes SpanImpl, SmallSpan and Span.
Constant view of an array of type T.
Interface of the parallelism manager for a subdomain.
Class allowing the creation of a shared memory window between the subdomains of the same node.
void resize(Int64 new_nb_elem)
Method to resize our segment.
void shrink()
Method to reduce the reserved memory space for the segments to the minimum necessary.
Span< const Type > segmentConstView(Int32 rank) const
Method to obtain a view of the segment of another sub-domain on the node.
void resize()
Method to be called by the sub-domain(s) that do not wish to resize their segments.
void add()
Method to be called by the sub-domain(s) that do not wish to add elements to their segment.
ConstArrayView< Int32 > machineRanks() const
Method to obtain the ranks that possess a segment in the window.
Span< const Type > segmentConstView() const
Method to obtain a view of our segment.
Span< Type > segmentView(Int32 rank)
Method to obtain a view of the segment of another sub-domain on the node.
Span< Type > segmentView()
Method to obtain a view of our segment.
void addToAnotherSegment(Int32 rank, Span< const Type > elem)
Method to add elements to the segment of another sub-domain.
void add(Span< const Type > elem)
Method to add elements to our segment.
void addToAnotherSegment()
Method to be called by the sub-domain(s) that do not wish to add elements to the segment of another s...
MachineShMemWin(IParallelMng *pm, Int64 nb_elem_segment)
Constructor.
void barrier() const
Method to wait until all processes/threads on the node call this method to continue execution.
void reserve(Int64 new_capacity)
Method to reserve memory space in our segment.
MachineShMemWin(IParallelMng *pm)
Constructor.
void reserve()
Method to be called by the sub-domain(s) that do not wish to reserve more memory for their segments.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
Definition Span.h:539
constexpr __host__ __device__ SizeType sizeBytes() const noexcept
Returns the size of the array in bytes.
Definition Span.h:329
View of an array of elements of type T.
Definition Span.h:635
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Span< DataType > asSpan(Span< std::byte, Extent > bytes)
Converts a Span<std::byte> into a Span<DataType>.
Definition Span.h:1126
std::int32_t Int32
Signed integer type of 32 bits.