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