Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MachineShMemWinVariable.cc
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.cc (C) 2000-2026 */
9/* */
10/* Classes enabling the use of the MachineShMemWinVariable object pointed */
11/* to by the shared memory variable area. */
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/MachineShMemWinVariable.h"
15
16#include "arcane/utils/NumericTypes.h"
17#include "arcane/utils/MDSpan.h"
18
19#include "arcane/core/VariableRefArray.h"
20#include "arcane/core/VariableRefArray2.h"
21#include "arcane/core/MeshVariable.h"
22#include "arcane/core/IVariable.h"
23#include "arcane/core/MeshVariableScalarRef.h"
24#include "arcane/core/internal/MachineShMemWinVariableBase.h"
25
26#include "arccore/base/Span2.h"
27#include "arccore/base/MDIndex.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
40: m_base(makeRef(new MachineShMemWinVariableBase(var)))
41{}
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46MachineShMemWinVariableCommon::
47~MachineShMemWinVariableCommon() = default;
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
53machineRanks() const
54{
55 return m_base->machineRanks();
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
62barrier() const
63{
64 m_base->barrier();
65}
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73template <class DataType>
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85template <class DataType>
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92template <class DataType>
94view(Int32 rank) const
95{
96 return asSpan<DataType>(m_base->segmentView(rank));
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102template <class DataType>
105{
106 m_base->updateVariable(m_vart.asArray().size(), sizeof(DataType));
107}
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
115template <class ItemType, class DataType>
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127template <class ItemType, class DataType>
130
131/*---------------------------------------------------------------------------*/
132/*---------------------------------------------------------------------------*/
133
134template <class ItemType, class DataType>
136view(Int32 rank) const
137{
138 return asSpan<DataType>(m_base->segmentView(rank));
139}
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144template <class ItemType, class DataType>
146operator()(Int32 rank, Int32 notlocal_id)
147{
148 return this->view(rank)[notlocal_id];
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154template <class ItemType, class DataType>
157{
158 m_base->updateVariable(m_vart.asArray().size(), sizeof(DataType));
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167template <class DataType>
170: m_base(makeRef(new MachineShMemWinVariable2DBase(var.variable())))
171, m_vart(var)
172{
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179template <class DataType>
182
183/*---------------------------------------------------------------------------*/
184/*---------------------------------------------------------------------------*/
185
186template <class DataType>
188machineRanks() const
189{
190 return m_base->machineRanks();
191}
192
193/*---------------------------------------------------------------------------*/
194/*---------------------------------------------------------------------------*/
195
196template <class DataType>
198barrier() const
199{
200 m_base->barrier();
201}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
206template <class DataType>
208view(Int32 rank) const
209{
210 Span<DataType> span1 = asSpan<DataType>(m_base->segmentView(rank));
211 return { span1.data(), m_base->nbElemDim1(rank), m_base->nbElemDim2(rank) };
212}
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
216
217template <class DataType>
220{
221 Int64 size_dim1 = m_vart.dim1Size();
222 Int64 size_dim2 = m_vart.dim2Size();
223
224 m_base->updateVariable(size_dim1, size_dim2, sizeof(DataType));
225}
226
227/*---------------------------------------------------------------------------*/
228/*---------------------------------------------------------------------------*/
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
233template <class ItemType, class DataType>
236: m_base(makeRef(new MachineShMemWinVariableMDBase(var.variable())))
237, m_vart(var)
238{
240}
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
245template <class ItemType, class DataType>
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252template <class ItemType, class DataType>
258
259/*---------------------------------------------------------------------------*/
260/*---------------------------------------------------------------------------*/
261
262template <class ItemType, class DataType>
264barrier() const
265{
266 m_base->barrier();
267}
268
269/*---------------------------------------------------------------------------*/
270/*---------------------------------------------------------------------------*/
271
272template <class ItemType, class DataType>
274view(Int32 rank) const
275{
276 Span<DataType> span1 = asSpan<DataType>(m_base->segmentView(rank));
277 return { span1.data(), m_base->nbElemDim1(rank), m_nb_elem_dim2 };
278}
279
280/*---------------------------------------------------------------------------*/
281/*---------------------------------------------------------------------------*/
282
283template <class ItemType, class DataType>
285operator()(Int32 rank, Int32 notlocal_id)
286{
287 Span<DataType> span1 = asSpan<DataType>(m_base->segmentView(rank));
288 Span2<DataType> span2(span1.data(), m_base->nbElemDim1(rank), m_nb_elem_dim2);
289
290 return span2[notlocal_id];
291}
292
293/*---------------------------------------------------------------------------*/
294/*---------------------------------------------------------------------------*/
295
296template <class ItemType, class DataType>
299{
300 Int64 size_dim1 = m_vart.asArray().dim1Size();
301 m_nb_elem_dim2 = m_vart.asArray().dim2Size();
302
303 m_base->updateVariable(size_dim1, m_nb_elem_dim2, sizeof(DataType));
304}
305
306/*---------------------------------------------------------------------------*/
307/*---------------------------------------------------------------------------*/
308
309/*---------------------------------------------------------------------------*/
310/*---------------------------------------------------------------------------*/
311
312template <class ItemType, class DataType, class Extents>
315: m_base(makeRef(new MachineShMemWinVariableMDBase(var.variable())))
316, m_vart(var)
317{
319}
320
321/*---------------------------------------------------------------------------*/
322/*---------------------------------------------------------------------------*/
323
324template <class ItemType, class DataType, class Extents>
327
328/*---------------------------------------------------------------------------*/
329/*---------------------------------------------------------------------------*/
330
331template <class ItemType, class DataType, class Extents>
337
338/*---------------------------------------------------------------------------*/
339/*---------------------------------------------------------------------------*/
340
341template <class ItemType, class DataType, class Extents>
343barrier() const
344{
345 m_base->barrier();
346}
347
348/*---------------------------------------------------------------------------*/
349/*---------------------------------------------------------------------------*/
350
351template <class ItemType, class DataType, class Extents>
352MDSpan<DataType, typename MDDimType<Extents::rank() + 1>::DimType> MachineShMemWinMDVariableT<ItemType, DataType, Extents>::
353view(Int32 rank) const
354{
355 Span<DataType> span1 = asSpan<DataType>(m_base->segmentView(rank));
356
357 if constexpr (Extents::rank() == 1) {
358 std::array<Int32, 2> nb_elem_mdim{ static_cast<Int32>(m_base->nbElemDim1(rank)), m_shape_dim2[0] };
359 MDSpan<DataType, MDDim2> mdspan(span1.data(), MDIndex<2>(nb_elem_mdim));
360 return mdspan;
361 }
362 else if constexpr (Extents::rank() == 2) {
363 std::array<Int32, 3> nb_elem_mdim{ static_cast<Int32>(m_base->nbElemDim1(rank)), m_shape_dim2[0], m_shape_dim2[1] };
364 MDSpan<DataType, MDDim3> mdspan(span1.data(), MDIndex<3>(nb_elem_mdim));
365 return mdspan;
366 }
367 else if constexpr (Extents::rank() == 3) {
368 std::array<Int32, 4> nb_elem_mdim{ static_cast<Int32>(m_base->nbElemDim1(rank)), m_shape_dim2[0], m_shape_dim2[1], m_shape_dim2[2] };
369 MDSpan<DataType, MDDim4> mdspan(span1.data(), MDIndex<4>(nb_elem_mdim));
370 return mdspan;
371 }
372 ARCANE_FATAL("Unexpected dimension");
373}
374
375/*---------------------------------------------------------------------------*/
376/*---------------------------------------------------------------------------*/
377
378template <class ItemType, class DataType, class Extents>
380operator()(Int32 rank, Int32 notlocal_id)
381{
382 Span<DataType> span1 = asSpan<DataType>(m_base->segmentView(rank));
383 Span2<DataType> span2(span1.data(), m_base->nbElemDim1(rank), m_nb_elem_dim2);
384 MDSpan<DataType, Extents> mdspan(span2[notlocal_id].data(), MDIndex<Extents::rank()>(m_shape_dim2));
385
386 return mdspan;
387}
388
389/*---------------------------------------------------------------------------*/
390/*---------------------------------------------------------------------------*/
391
392template <class ItemType, class DataType, class Extents>
395{
396 Int64 nb_elem_dim1 = m_vart.asArray().dim1Size();
397 Int32 nb_elem_dim2 = m_vart.asArray().dim2Size();
398
399 m_base->updateVariable(nb_elem_dim1, nb_elem_dim2, sizeof(DataType));
400
401 SmallSpan<Int32> shape_dim2_view(m_shape_dim2.data(), Extents::rank());
402 shape_dim2_view.copy(m_base->arrayShape().dimensions());
403
404 m_nb_elem_dim2 = nb_elem_dim2;
405}
406
407/*---------------------------------------------------------------------------*/
408/*---------------------------------------------------------------------------*/
409
410/*---------------------------------------------------------------------------*/
411/*---------------------------------------------------------------------------*/
412
413// Macro to instantiate a template class for all numeric data types, all items.
414#define ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM1(class_name, item) \
415 template class ARCANE_TEMPLATE_EXPORT class_name<item, Real>; \
416 template class ARCANE_TEMPLATE_EXPORT class_name<item, Real3>; \
417 template class ARCANE_TEMPLATE_EXPORT class_name<item, Real3x3>; \
418 template class ARCANE_TEMPLATE_EXPORT class_name<item, Real2>; \
419 template class ARCANE_TEMPLATE_EXPORT class_name<item, Real2x2>; \
420 template class ARCANE_TEMPLATE_EXPORT class_name<item, Int8>; \
421 template class ARCANE_TEMPLATE_EXPORT class_name<item, Int16>; \
422 template class ARCANE_TEMPLATE_EXPORT class_name<item, Int32>; \
423 template class ARCANE_TEMPLATE_EXPORT class_name<item, Int64>;
424
425#define ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM(class_name) \
426 ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM1(class_name, Node) \
427 ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM1(class_name, Face) \
428 ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM1(class_name, Cell) \
429 ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM1(class_name, Particle) \
430 ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM1(class_name, DoF)
431
432/*---------------------------------------------------------------------------*/
433/*---------------------------------------------------------------------------*/
434
435ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE(MachineShMemWinVariableArrayT);
436
437template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Real>;
438template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Real3>;
439template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Real3x3>;
440template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Real2>;
441template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Real2x2>;
442template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Int16>;
443template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Int32>;
444template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Int64>;
445template class ARCANE_TEMPLATE_EXPORT MachineShMemWinVariableArray2T<Byte>;
447ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM(MachineShMemWinMeshVariableScalarT);
448ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE_WITH_ITEM(MachineShMemWinMeshVariableArrayT);
449
450template class ARCANE_TEMPLATE_EXPORT MachineShMemWinMDVariableT<Cell, Real, MDDim1>;
451template class ARCANE_TEMPLATE_EXPORT MachineShMemWinMDVariableT<Cell, Real, MDDim2>;
452template class ARCANE_TEMPLATE_EXPORT MachineShMemWinMDVariableT<Cell, Real, MDDim3>;
453
454// Explicit instantiation to check compilation
458
461
463
464/*---------------------------------------------------------------------------*/
465/*---------------------------------------------------------------------------*/
466
467} // End namespace Arcane
469/*---------------------------------------------------------------------------*/
470/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Types and functions associated with the classes Span2Impl, Small2Span and Span2.
Constant view of an array of type T.
Interface of a variable.
Definition IVariable.h:40
Base class for multi-dimensional views.
Class allowing access to shared elements of the variable in shared memory.
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.
Class allowing access to shared elements of the variable in shared memory.
Class allowing access to the shared elements of the variable in shared memory.
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.
Class allowing access to the shared elements of the variable in shared memory.
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.
Class allowing access to the shared elements of the variable in shared memory.
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.
Class allowing access to the shared elements of the variable in shared memory.
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.
Array variable on a mesh entity type.
Scalar variable on a mesh entity type.
View of an array of elements of type T.
Definition Span.h:805
View for a 2D array whose size is an 'Int64'.
Definition Span2.h:324
__host__ __device__ void copy(const U &copy_array)
Copies the array copy_array into the instance.
Definition Span.h:477
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
Definition Span.h:539
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::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
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.