Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MachineShMemWinVariable.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/* MachineShMemWinVariable.h (C) 2000-2026 */
9/* */
10/* Classes allowing the use of the MachineShMemWinVariable object pointed */
11/* to by the shared memory variable memory area. */
12/*---------------------------------------------------------------------------*/
13
14#ifndef ARCANE_CORE_MACHINESHMEMWINVARIABLE_H
15#define ARCANE_CORE_MACHINESHMEMWINVARIABLE_H
16
17/*---------------------------------------------------------------------------*/
18/*---------------------------------------------------------------------------*/
19
21
22#include "arcane/utils/Ref.h"
23#include "arcane/utils/NumArray.h"
24
25#include "arcane/core/MeshMDVariableRef.h"
26
27#include "arccore/base/FixedArray.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38class MachineShMemWinVariableBase;
39class MachineShMemWinVariable2DBase;
40class MachineShMemWinVariableMDBase;
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45/*!
46 * \brief Class allowing access to the shared elements of the variable
47 * in shared memory.
48 *
49 * To access all properties, it is necessary to use one of the child classes:
50 * - \a MachineShMemWinVariableArrayT for array variables without
51 * support,
52 * - \a MachineShMemWinVariableItemT for mesh variables.
53 */
54class ARCANE_CORE_EXPORT MachineShMemWinVariableCommon
55{
56
57 protected:
58
59 /*!
60 * \brief Constructor.
61 * \param var Variable having the property "IVariable::PInShMem".
62 */
64
65 public:
66
68
69 public:
70
71 /*!
72 * \brief Method allowing retrieval of ranks that possess a segment
73 * in the window.
74 *
75 * Non-collective call.
76 *
77 * \return A view containing the rank IDs.
78 */
80
81 /*!
82 * \brief Method allowing waiting until all processes/threads
83 * on the node call this method to continue execution.
84 */
85 void barrier() const;
86
87 protected:
88
90};
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98/*!
99 * \brief Class allowing access to the shared elements of the variable
100 * in shared memory.
101 *
102 * It is necessary that this variable be allocated in shared memory with
103 * the property "IVariable::PInShMem".
104 *
105 * This class works for array variables without support.
106 *
107 * If the size of the variable changes while an object of this type is used,
108 * it is necessary to call the \a updateVariable() method.
109 */
110template <class DataType>
113{
114
115 public:
116
117 /*!
118 * \brief Constructor.
119 * \param var Variable having the property "PInShMem".
120 */
121 ARCANE_CORE_EXPORT explicit MachineShMemWinVariableArrayT(VariableRefArrayT<DataType> var);
122 ARCANE_CORE_EXPORT ~MachineShMemWinVariableArrayT() override;
123
124 public:
125
126 /*!
127 * \brief Method allowing retrieval of a view on the array of another
128 * subdomain on the node.
129 *
130 * Equivalent to "var.asArray()" but for another subdomain.
131 *
132 * Non-collective call.
133 *
134 * \param rank The rank of the subdomain.
135 * \return A view.
136 */
137 ARCANE_CORE_EXPORT Span<DataType> view(Int32 rank) const;
138
139 /*!
140 * \brief Method allowing updating this object after a
141 * resizing of the variable.
142 *
143 * Collective call.
144 */
145 ARCANE_CORE_EXPORT void updateVariable();
146
147 private:
148
150};
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158/*!
159 * \brief Class allowing access to the shared elements of the variable
160 * in shared memory.
161 *
162 * It is necessary that this variable be allocated in shared memory with
163 * the property "IVariable::PInShMem".
164 *
165 * This class works for mesh scalar variables.
166 *
167 * If the mesh changes while an object of this type is used, it is
168 * necessary to call the \a updateVariable() method.
169 */
170template <class ItemType, class DataType>
173{
174
175 public:
176
177 /*!
178 * \brief Constructor.
179 * \param var Variable having the property "IVariable::PInShMem".
180 */
182
183 ARCANE_CORE_EXPORT ~MachineShMemWinMeshVariableScalarT() override;
184
185 public:
186
187 /*!
188 * \brief Method allowing retrieval of a view on the variable of another
189 * subdomain on the node.
190 *
191 * Equivalent to "var.asArray()" but for another subdomain.
192 *
193 * \warning Attention: To access the elements of the view, it is
194 * necessary to use the local_ids of the other subdomain!
195 * Do not use the local_ids of our subdomain!
196 *
197 * Non-collective call.
198 *
199 * \param rank The rank of the subdomain.
200 * \return A view.
201 */
202 ARCANE_CORE_EXPORT Span<DataType> view(Int32 rank) const;
203
204 /*!
205 * \brief Method allowing retrieval of an element of the variable from another
206 * subdomain.
207 *
208 * \warning Attention: The local_id corresponds to the local_id of the subdomain
209 * \a rank! Absolutely do not use a local_id from our
210 * subdomain to access the elements of the view!
211 *
212 * \note If multiple iterations are necessary for the same rank, it is
213 * preferable to retrieve a view via \a segmentView(Int32 rank).
214 *
215 * Non-collective call.
216 *
217 * \param rank The rank of the subdomain of the targeted variable.
218 * \param notlocal_id The local_id of the subdomain \a rank.
219 * \return The item element.
220 */
221 ARCANE_CORE_EXPORT DataType operator()(Int32 rank, Int32 notlocal_id);
222
223 /*!
224 * \brief Method allowing updating this object after a change
225 * in the mesh.
226 *
227 * Collective call.
228 */
229 ARCANE_CORE_EXPORT void updateVariable();
230
231 private:
232
234};
235
236/*---------------------------------------------------------------------------*/
237/*---------------------------------------------------------------------------*/
238
239/*---------------------------------------------------------------------------*/
240/*---------------------------------------------------------------------------*/
241
242/*!
243 * \brief Class allowing access to the shared elements of the variable
244 * in shared memory.
245 *
246 * It is necessary that this variable be allocated in shared memory with
247 * the property "IVariable::PInShMem".
248 *
249 * This class works for 2D array variables without support.
250 *
251 * If the size of the variable changes while an object of this type is used,
252 * it is necessary to call the \a updateVariable() method.
253 */
254template <class DataType>
256{
257 public:
258
259 /*!
260 * \brief Constructor.
261 * \param var Variable having the property "IVariable::PInShMem".
262 */
263 ARCANE_CORE_EXPORT explicit MachineShMemWinVariableArray2T(VariableRefArray2T<DataType> var);
264
265 ARCANE_CORE_EXPORT ~MachineShMemWinVariableArray2T();
266
267 public:
268
269 /*!
270 * \brief Method allowing retrieval of ranks that possess a segment
271 * in the window.
272 *
273 * Non-collective call.
274 *
275 * \return A view containing the rank IDs.
276 */
277 ARCANE_CORE_EXPORT ConstArrayView<Int32> machineRanks() const;
278
279 /*!
280 * \brief Method allowing waiting until all processes/threads
281 * on the node call this method to continue execution.
282 */
283 ARCANE_CORE_EXPORT void barrier() const;
284
285 public:
286
287 /*!
288 * \brief Method allowing retrieval of a view on the array of another
289 * subdomain on the node.
290 *
291 * Non-collective call.
292 *
293 * \param rank The rank of the subdomain.
294 * \return A 2D view.
295 */
296 ARCANE_CORE_EXPORT Span2<DataType> view(Int32 rank) const;
297
298 /*!
299 * \brief Method allowing updating this object after a
300 * resizing of the variable.
301 *
302 * Collective call.
303 */
304 ARCANE_CORE_EXPORT void updateVariable();
305
306 private:
307
310};
311
312/*---------------------------------------------------------------------------*/
313/*---------------------------------------------------------------------------*/
314
315/*---------------------------------------------------------------------------*/
316/*---------------------------------------------------------------------------*/
317
318/*!
319 * \brief Class allowing access to the shared elements of the variable
320 * in shared memory.
321 *
322 * It is necessary that this variable be allocated in shared memory with
323 * the property "IVariable::PInShMem".
324 *
325 * This class works for mesh array variables.
326 *
327 * If the mesh and/or the variable size changes when an object of this
328 * type is used, it is necessary to call the \a updateVariable() method.
329 */
330template <class ItemType, class DataType>
332{
333
334 public:
335
336 /*!
337 * \brief Constructor.
338 * \param var Variable having the property "IVariable::PInShMem".
339 */
341
342 ARCANE_CORE_EXPORT ~MachineShMemWinMeshVariableArrayT();
343
344 public:
345
346 /*!
347 * \brief Method to get the ranks that possess a segment
348 * in the window.
349 *
350 * Non-collective call.
351 *
352 * \return A view containing the rank IDs.
353 */
354 ARCANE_CORE_EXPORT ConstArrayView<Int32> machineRanks() const;
355
356 /*!
357 * \brief Method to wait until all processes/threads
358 * on the node call this method to continue execution.
359 */
360 ARCANE_CORE_EXPORT void barrier() const;
361
362 public:
363
364 /*!
365 * \brief Method to get a view of the variable from another
366 * subdomain on the node.
367 *
368 * Equivalent to "var.asArray()" but from another subdomain.
369 * The first index corresponds to the local_id, the second index is the
370 * position of the element in the item array.
371 *
372 * \warning Attention: to access the elements of the view, it is
373 * necessary to use the local_ids of the other subdomain!
374 * Do not use the local_ids of our subdomain!
375 *
376 * Non-collective call.
377 *
378 * \param rank The subdomain rank.
379 * \return A 2D view.
380 */
381 ARCANE_CORE_EXPORT Span2<DataType> view(Int32 rank) const;
382
383 /*!
384 * \brief Method to get the array of an item from another
385 * subdomain.
386 *
387 * \warning Attention: the local_id corresponds to the local_id of the subdomain
388 * \a rank! Absolutely do not use a local_id from our
389 * subdomain to access the elements of the view!
390 *
391 * \note If multiple iterations are necessary for the same rank, it is
392 * preferable to retrieve a view via \a segmentView(Int32 rank).
393 *
394 * Non-collective call.
395 *
396 * \param rank The rank of the targeted variable's subdomain.
397 * \param notlocal_id The local_id of the subdomain \a rank.
398 * \return The item array.
399 */
400 ARCANE_CORE_EXPORT Span<DataType> operator()(Int32 rank, Int32 notlocal_id);
401
402 /*!
403 * \brief Method to update this object after a change
404 * in the mesh and/or after a resizing of the variable.
405 *
406 * Collective call.
407 */
408 ARCANE_CORE_EXPORT void updateVariable();
409
410 private:
411
414 Int32 m_nb_elem_dim2{};
415};
416
417/*---------------------------------------------------------------------------*/
418/*---------------------------------------------------------------------------*/
419
420/*---------------------------------------------------------------------------*/
421/*---------------------------------------------------------------------------*/
422
423/*!
424 * \brief Class allowing access to shared elements of the variable
425 * in shared memory.
426 *
427 * This class cannot be used directly. It is necessary
428 * to use one of the following classes:
429 * - \a MachineShMemWinMeshMDVariableT for scalar mesh variables
430 * with a maximum dimension of 3,
431 * - \a MachineShMemWinMeshVectorMDVariableT for vector mesh variables
432 * with a maximum dimension of 2,
433 * - \a MachineShMemWinMeshMatrixMDVariableT for matrix mesh variables
434 * with a maximum dimension of 1.
435 */
436template <class ItemType, class DataType, class Extents>
438{
439
440 protected:
441
442 /*!
443 * \brief Constructor.
444 * \param var Variable having the property "IVariable::PInShMem".
445 */
447
448 public:
449
450 ARCANE_CORE_EXPORT virtual ~MachineShMemWinMDVariableT();
451
452 public:
453
454 /*!
455 * \brief Method to get the ranks that possess a segment
456 * in the window.
457 *
458 * Non-collective call.
459 *
460 * \return A view containing the rank IDs.
461 */
462 ARCANE_CORE_EXPORT ConstArrayView<Int32> machineRanks() const;
463
464 /*!
465 * \brief Method to wait until all processes/threads
466 * on the node call this method to continue execution.
467 */
468 ARCANE_CORE_EXPORT void barrier() const;
469
470 public:
471
472 /*!
473 * \brief Method to get a view of the variable from another
474 * subdomain on the node.
475 *
476 * The first index corresponds to the local_id, the other indices are the
477 * position of the element in the item array.
478 *
479 * \warning Attention: to access the elements of the view, it is
480 * necessary to use the local_ids of the other subdomain!
481 * Do not use the local_ids of our subdomain!
482 *
483 * Non-collective call.
484 *
485 * \param rank The subdomain rank.
486 * \return A view.
487 */
488 ARCANE_CORE_EXPORT MDSpan<DataType, typename MDDimType<Extents::rank() + 1>::DimType> view(Int32 rank) const;
489
490 /*!
491 * \brief Method to get the multi-dimensional array of an
492 * item from another subdomain.
493 *
494 * \warning Attention: the local_id corresponds to the local_id of the subdomain
495 * \a rank! Absolutely do not use a local_id from our
496 * subdomain to access the elements of the view!
497 *
498 * \note If multiple iterations are necessary for the same rank, it is
499 * preferable to retrieve a view via \a view(Int32 rank).
500 *
501 * Non-collective call.
502 *
503 * \param rank The rank of the targeted variable's subdomain.
504 * \param notlocal_id The local_id of the subdomain \a rank.
505 * \return The MD array of the item.
506 */
507 ARCANE_CORE_EXPORT MDSpan<DataType, Extents> operator()(Int32 rank, Int32 notlocal_id);
508
509 /*!
510 * \brief Method to update this object after a change
511 * in the mesh and/or after a resizing of the variable.
512 *
513 * Collective call.
514 */
515 ARCANE_CORE_EXPORT void updateVariable();
516
517 private:
518
521 Int32 m_nb_elem_dim2{};
522 std::array<Int32, Extents::rank()> m_shape_dim2{};
523};
524
525/*---------------------------------------------------------------------------*/
526/*---------------------------------------------------------------------------*/
527
528/*---------------------------------------------------------------------------*/
529/*---------------------------------------------------------------------------*/
530
531/*!
532 * \brief Class allowing access to shared elements of the variable
533 * in shared memory.
534 *
535 * It is necessary that this variable be allocated in shared memory with
536 * the property "IVariable::PInShMem".
537 *
538 * This class works for scalar mesh variables
539 * with a maximum dimension of 3.
540 *
541 * If the mesh and/or the variable size changes when an object of this
542 * type is used, it is necessary to call the \a updateVariable() method.
543 */
544template <class ItemType, class DataType, class Extents>
546: public MachineShMemWinMDVariableT<ItemType, DataType, Extents>
547{
548
549 public:
550
551 /*!
552 * \brief Constructor.
553 * \param var Variable having the property "IVariable::PInShMem".
554 */
556 : MachineShMemWinMDVariableT<ItemType, DataType, Extents>(var.underlyingVariable())
557 {}
558
559 ~MachineShMemWinMeshMDVariableT() override = default;
560};
561
562/*---------------------------------------------------------------------------*/
563/*---------------------------------------------------------------------------*/
564
565/*---------------------------------------------------------------------------*/
566/*---------------------------------------------------------------------------*/
567
568/*!
569 * \brief Class allowing access to shared elements of the variable
570 * in shared memory.
571 *
572 * It is necessary that this variable be allocated in shared memory with
573 * the property "IVariable::PInShMem".
574 *
575 * This class works for vector mesh variables
576 * with a maximum dimension of 2.
577 *
578 * If the mesh and/or the variable size changes when an object of this
579 * type is used, it is necessary to call the \a updateVariable() method.
580 */
581template <class ItemType, class DataType, class Extents>
583: public MachineShMemWinMDVariableT<ItemType, DataType, typename Extents::template AddedFirstExtentsType<DynExtent>>
584{
585 using AddedFirstExtentsType = Extents::template AddedFirstExtentsType<DynExtent>;
586
587 public:
588
589 /*!
590 * \brief Constructor.
591 * \param var Variable having the property "IVariable::PInShMem".
592 */
593 template <Int32 Size>
595 : MachineShMemWinMDVariableT<ItemType, DataType, AddedFirstExtentsType>(var.underlyingVariable())
596 {}
597
598 ~MachineShMemWinMeshVectorMDVariableT() override = default;
599};
600
601/*---------------------------------------------------------------------------*/
602/*---------------------------------------------------------------------------*/
603
604/*---------------------------------------------------------------------------*/
605/*---------------------------------------------------------------------------*/
606
607/*!
608 * \brief Class allowing access to shared elements of the variable
609 * in shared memory.
610 *
611 * It is necessary that this variable be allocated in shared memory with
612 * the property "IVariable::PInShMem".
613 *
614 * This class works for matrix mesh variables
615 * with a maximum dimension of 1.
616 *
617 * If the mesh and/or the variable size changes when an object of this
618 * type is used, it is necessary to call the \a updateVariable() method.
619 */
620template <class ItemType, class DataType, class Extents>
622: public MachineShMemWinMDVariableT<ItemType, DataType, typename Extents::template AddedFirstLastExtentsType<DynExtent, DynExtent>>
623{
624 using AddedFirstLastExtentsType = Extents::template AddedFirstLastExtentsType<DynExtent, DynExtent>;
625
626 public:
627
628 /*!
629 * \brief Constructor.
630 * \param var Variable having the property "IVariable::PInShMem".
631 */
632 template <Int32 Row, Int32 Column>
634 : MachineShMemWinMDVariableT<ItemType, DataType, AddedFirstLastExtentsType>(var.underlyingVariable())
635 {}
636
637 ~MachineShMemWinMeshMatrixMDVariableT() override = default;
638};
639
640/*---------------------------------------------------------------------------*/
641/*---------------------------------------------------------------------------*/
642
643} // End namespace Arcane
644
645/*---------------------------------------------------------------------------*/
646/*---------------------------------------------------------------------------*/
647
648#endif
Declarations of Arcane's general types.
Constant view of an array of type T.
Interface of a variable.
Definition IVariable.h:40
Base class for multi-dimensional views.
MachineShMemWinMDVariableT(MeshVariableArrayRefT< ItemType, DataType > var)
Constructor.
MDSpan< DataType, Extents > operator()(Int32 rank, Int32 notlocal_id)
Method to get the multi-dimensional array of an item from another subdomain.
ConstArrayView< Int32 > machineRanks() const
Method to get the ranks that possess a segment in the window.
MDSpan< DataType, typename MDDimType< Extents::rank()+1 >::DimType > view(Int32 rank) const
Method to get a view of the variable from another subdomain on the node.
void updateVariable()
Method to update this object after a change in the mesh and/or after a resizing of the variable.
void barrier() const
Method to wait until all processes/threads on the node call this method to continue execution.
Class allowing access to shared elements of the variable in shared memory.
MachineShMemWinMeshMDVariableT(MeshMDVariableRefT< ItemType, DataType, Extents > var)
Constructor.
Class allowing access to shared elements of the variable in shared memory.
MachineShMemWinMeshMatrixMDVariableT(MeshMatrixMDVariableRefT< ItemType, DataType, Row, Column, Extents > var)
Constructor.
void updateVariable()
Method to update this object after a change in the mesh and/or after a resizing of the variable.
Span2< DataType > view(Int32 rank) const
Method to get a view of the variable from another subdomain on the node.
void barrier() const
Method to wait until all processes/threads on the node call this method to continue execution.
Span< DataType > operator()(Int32 rank, Int32 notlocal_id)
Method to get the array of an item from another subdomain.
MachineShMemWinMeshVariableArrayT(MeshVariableArrayRefT< ItemType, DataType > var)
Constructor.
ConstArrayView< Int32 > machineRanks() const
Method to get the ranks that possess a segment in the window.
void updateVariable()
Method allowing updating this object after a change in the mesh.
DataType operator()(Int32 rank, Int32 notlocal_id)
Method allowing retrieval of an element of the variable from another subdomain.
Span< DataType > view(Int32 rank) const
Method allowing retrieval of a view on the variable of another subdomain on the node.
MachineShMemWinMeshVariableScalarT(MeshVariableScalarRefT< ItemType, DataType > var)
Constructor.
Class allowing access to shared elements of the variable in shared memory.
MachineShMemWinMeshVectorMDVariableT(MeshVectorMDVariableRefT< ItemType, DataType, Size, Extents > var)
Constructor.
ConstArrayView< Int32 > machineRanks() const
Method allowing retrieval of ranks that possess a segment in the window.
Span2< DataType > view(Int32 rank) const
Method allowing retrieval of a view on the array of another subdomain on the node.
MachineShMemWinVariableArray2T(VariableRefArray2T< DataType > var)
Constructor.
void barrier() const
Method allowing waiting until all processes/threads on the node call this method to continue executio...
void updateVariable()
Method allowing updating this object after a resizing of the variable.
MachineShMemWinVariableArrayT(VariableRefArrayT< DataType > var)
Constructor.
Span< DataType > view(Int32 rank) const
Method allowing retrieval of a view on the array of another subdomain on the node.
void updateVariable()
Method allowing updating this object after a resizing of the variable.
void barrier() const
Method allowing waiting until all processes/threads on the node call this method to continue executio...
ConstArrayView< Int32 > machineRanks() const
Method allowing retrieval of ranks that possess a segment in the window.
MachineShMemWinVariableCommon(IVariable *var)
Constructor.
Class managing a multi-dimensional variable on a mesh entity.
Class managing a multi-dimensional 'NumMatrix' type variable on a mesh entity.
Array variable on a mesh entity type.
Scalar variable on a mesh entity type.
Class managing a multi-dimensional 'NumVector' type variable on a mesh entity.
Reference to an instance.
View for a 2D array whose size is an 'Int64'.
Definition Span2.h:324
View of an array of elements of type T.
Definition Span.h:635
Two-dimensional array variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Signed integer type of 32 bits.