Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MachineShMemWinBase.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/* MachineShMemWinBase.h (C) 2000-2026 */
9/* */
10/* Class allowing the creation of memory windows for a computing node. */
11/* The segments of these windows are not contiguous in memory and can */
12/* be resized. */
13/*---------------------------------------------------------------------------*/
14#ifndef ARCANE_CORE_MACHINESHMEMWINBASE_H
15#define ARCANE_CORE_MACHINESHMEMWINBASE_H
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
20#include "arcane/utils/Ref.h"
21
22#include "arccore/base/Span.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33class IParallelMng;
34class IParallelMngInternal;
35namespace MessagePassing
36{
37 class IMachineShMemWinBaseInternal;
38}
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43/*!
44 * \brief Class allowing the creation of a shared memory window between the
45 * subdomains of the same node.
46 *
47 * The segments of this window are not contiguous in memory and can
48 * be resized.
49 *
50 * The \a add() method allows elements to be added iteratively.
51 */
52class ARCANE_CORE_EXPORT MachineShMemWinBase
53{
54
55 public:
56
57 /*!
58 * \brief Constructor.
59 * \param pm The parallelMng to use.
60 * \param sizeof_segment The total size of our segment (in bytes / must
61 * be divisible by \a sizeof_elem).
62 * \param sizeof_elem The size of an element in our segment (in bytes).
63 */
64 MachineShMemWinBase(IParallelMng* pm, Int64 sizeof_segment, Int32 sizeof_elem);
65
66 public:
67
68 /*!
69 * \brief Method to obtain the ranks that possess a segment
70 * in the window.
71 *
72 * Non-collective call.
73 *
74 * \return A view containing the rank IDs.
75 */
77
78 /*!
79 * \brief Method to wait until all processes/threads
80 * on the node call this method to continue execution.
81 */
82 void barrier() const;
83
84 /*!
85 * \brief Method to obtain a view of our segment.
86 *
87 * Non-collective call.
88 *
89 * \return A view.
90 */
92
93 /*!
94 * \brief Method to obtain a view of the segment of another
95 * subdomain on the node.
96 *
97 * Non-collective call.
98 *
99 * \param rank The rank of the subdomain.
100 * \return A view.
101 */
103
104 /*!
105 * \brief Method to obtain a view of our segment.
106 *
107 * Non-collective call.
108 *
109 * \return A view.
110 */
112
113 /*!
114 * \brief Method to obtain a view of the segment of another
115 * subdomain on the node.
116 *
117 * Non-collective call.
118 *
119 * \param rank The rank of the subdomain.
120 * \return A view.
121 */
123
124 /*!
125 * \brief Method to add elements into our segment.
126 *
127 * Collective call.
128 *
129 * \note The methods add(..) and addToAnotherSegment(..) must not be mixed.
130 *
131 * If the segment is too small, it will be resized.
132 *
133 * Subdomains that do not wish to add elements can call the
134 * \a add() method without parameters or this method with an empty view.
135 *
136 * \param elem The elements to add.
137 */
138 void add(Span<const std::byte> elem);
139 /*!
140 * \brief Method to be called by the subdomain(s) that do not wish to add
141 * elements to its segment.
142 *
143 * Collective call.
144 *
145 * \note The methods add(..) and addToAnotherSegment(..) must not be mixed.
146 *
147 * See the documentation for \a add(Span<const std::byte> elem).
148 */
149 void add();
150
151 /*!
152 * \brief Method to add elements into the segment of another
153 * subdomain.
154 *
155 * Collective call.
156 *
157 * \note The methods add(..) and addToAnotherSegment(..) must not be mixed.
158 *
159 * Two subdomains must not add elements to the same subdomain segment.
160 *
161 * If the target segment is too small, it will be resized.
162 *
163 * Subdomains that do not wish to add elements can call the
164 * \a addToAnotherSegment() method without parameters.
165 *
166 * \param rank The rank of the subdomain whose segment is to be modified.
167 * \param elem The elements to add.
168 */
170
171 /*!
172 * \brief Method to be called by the subdomain(s) that do not wish to add
173 * elements into the segment of another subdomain.
174 *
175 * Collective call.
176 *
177 * \note The methods add(..) and addToAnotherSegment(..) must not be mixed.
178 *
179 * See the documentation for \a addToAnotherSegment(Int32 rank, Span<const Type> elem).
180 */
181 void addToAnotherSegment();
182
183 /*!
184 * \brief Method to reserve memory space in our segment.
185 *
186 * Collective call.
187 *
188 * This method does nothing if \a new_capacity is less than the memory space
189 * already allocated for the segment.
190 * For subdomains that do not wish to increase the available memory space
191 * for their segment, it is possible to set the \a new_capacity parameter
192 * to 0 or use the \a reserve() method (without arguments).
193 *
194 * The reserved space will have a size greater than or equal to
195 * \a new_capacity.
196 *
197 * This method does not resize the segment; you must always use the add()
198 * method to add elements.
199 *
200 * To resize the segment, the \a resize(Int64 new_size) method is
201 * available.
202 *
203 * \param new_nb_elem_segment_capacity The requested new capacity (in number of elements, not in bytes).
204 */
205 void reserve(Int64 new_nb_elem_segment_capacity);
206
207 /*!
208 * \brief Method to be called by the subdomain(s) that do not wish to reserve
209 * more memory for their segments.
210 *
211 * Collective call.
212 *
213 * See the documentation for \a reserve(Int64 new_nb_elem_segment_capacity).
214 */
215 void reserve();
216
217 /*!
218 * \brief Method to resize our segment.
219 *
220 * Collective call.
221 *
222 * If the provided size is less than the current size of the segment, elements
223 * located after the provided size will be deleted.
224 *
225 * For subdomains that do not wish to resize their segment, it is
226 * possible to set the \a new_size argument to -1 or call the method
227 * \a resize() (without arguments).
228 *
229 * \param new_nb_elem_segment The new size (in number of elements, not in bytes).
230 */
231 void resize(Int64 new_nb_elem_segment);
232
233 /*!
234 * \brief Method to be called by the subdomain(s) that do not wish to
235 * resize their segments.
236 *
237 * Collective call.
238 *
239 * See the documentation for \a resize(Int64 new_nb_elem_segment).
240 */
241 void resize();
242
243 /*!
244 * \brief Method to reduce the reserved memory space for the
245 * segments to the minimum necessary.
246 *
247 * Collective call.
248 */
249 void shrink();
250
251 private:
252
253 IParallelMngInternal* m_pm_internal;
255 Int32 m_sizeof_elem;
256};
257
258/*---------------------------------------------------------------------------*/
259/*---------------------------------------------------------------------------*/
260
261} // End namespace Arcane
262
263/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265
266#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.
void reserve(Int64 new_nb_elem_segment_capacity)
Method to reserve memory space in our segment.
void barrier() const
Method to wait until all processes/threads on the node call this method to continue execution.
MachineShMemWinBase(IParallelMng *pm, Int64 sizeof_segment, Int32 sizeof_elem)
Constructor.
Span< const std::byte > segmentConstView() const
Method to obtain a view of our segment.
void resize(Int64 new_nb_elem_segment)
Method to resize our segment.
void shrink()
Method to reduce the reserved memory space for the segments to the minimum necessary.
void addToAnotherSegment(Int32 rank, Span< const std::byte > elem)
Method to add elements into the segment of another subdomain.
ConstArrayView< Int32 > machineRanks() const
Method to obtain the ranks that possess a segment in the window.
void add(Span< const std::byte > elem)
Method to add elements into our segment.
Span< std::byte > segmentView()
Method to obtain a view of our segment.
Reference to an instance.
View of an array of elements of type T.
Definition Span.h:635
Declarations of types and methods used by message exchange mechanisms.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
std::int32_t Int32
Signed integer type of 32 bits.