Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MachineShMemWinVariableBase.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/* MachineShMemWinVariableBase.cc (C) 2000-2026 */
9/* */
10/* Base classes allowing the exploitation of the MachineShMemWinVariable */
11/* object pointed to the memory area of variables in shared memory. */
12/*---------------------------------------------------------------------------*/
13/*---------------------------------------------------------------------------*/
14
15#include "arcane/core/internal/MachineShMemWinVariableBase.h"
16
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/ITraceMng.h"
19#include "arcane/utils/ArrayShape.h"
20
21#include "arcane/core/ContigMachineShMemWin.h"
22#include "arcane/core/IMesh.h"
23#include "arcane/core/ISubDomain.h"
24#include "arcane/core/MeshHandle.h"
25#include "arcane/core/IData.h"
26#include "arcane/core/IParallelMng.h"
27#include "arcane/core/IVariable.h"
28
29#include "arcane/core/internal/MachineShMemWinMemoryAllocator.h"
30#include "arcane/core/internal/IDataInternal.h"
31#include "arcane/core/internal/IParallelMngInternal.h"
32
33#include "arccore/common/AllocatedMemoryInfo.h"
34#include "arccore/base/MemoryView.h"
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39namespace Arcane
40{
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
47: m_var(var)
48{
49 if (!(m_var->property() & IVariable::PInShMem)) {
50 ARCANE_FATAL("The variable has not PInShMem property");
51 }
52 if (m_var->meshHandle().hasMesh()) {
53 m_pm = m_var->meshHandle().mesh()->parallelMng();
54 }
55 else {
56 m_pm = m_var->subDomain()->parallelMng();
57 }
58 m_machine_ranks = m_pm->_internalApi()->machineRanks();
59 m_sizeof_var.reserve(m_machine_ranks.size());
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
66machineRanks() const
67{
68 return m_machine_ranks;
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
75barrier() const
76{
77 return m_pm->_internalApi()->machineBarrier();
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
84segmentView(Int32 rank) const
85{
86 const AllocatedMemoryInfo data(m_var->data()->_commonInternal()->numericData()->memoryView().data());
87#ifdef ARCANE_CHECK
88 if (data.baseAddress() == nullptr) {
89 ARCANE_FATAL("Variable not initialised yet. Call var.resize() method before.");
90 }
91#endif
92 return MachineShMemWinMemoryAllocator::segmentView(data, rank).subSpan(0, m_sizeof_var.at(rank));
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
99updateVariable(Int64 nb_elem_dim1, Int64 sizeof_elem)
100{
101 ContigMachineShMemWin<Int64> all_size(m_pm, 1);
102
103 all_size.segmentView()[0] = nb_elem_dim1 * sizeof_elem;
104 all_size.barrier();
105
106 for (Int32 machine_rank = 0; const Int64 size : all_size.windowConstView()) {
107 m_sizeof_var[m_machine_ranks[machine_rank]] = size;
108 machine_rank++;
109 }
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
121{
122 m_nb_elem_dim1.reserve(m_machine_ranks.size());
123 m_nb_elem_dim2.reserve(m_machine_ranks.size());
124}
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
130updateVariable(Int64 nb_elem_dim1, Int64 nb_elem_dim2, Int64 sizeof_elem)
131{
132 ContigMachineShMemWin<Int64> all_nb_elem(m_pm, 2);
133
134 all_nb_elem.segmentView()[0] = nb_elem_dim1;
135 all_nb_elem.segmentView()[1] = nb_elem_dim2;
136
137 all_nb_elem.barrier();
138
139 Int64 sizeof_elem2 = sizeof_elem * sizeof_elem;
140
141 for (Int32 machine_rank = 0; const Int32 world_rank : m_machine_ranks) {
142 const Int32 pos = machine_rank * 2;
143 const Int64 nb_elem_dim1_i = all_nb_elem.windowConstView()[pos];
144 const Int64 nb_elem_dim2_i = all_nb_elem.windowConstView()[pos + 1];
145
146 m_nb_elem_dim1[world_rank] = nb_elem_dim1_i;
147 m_nb_elem_dim2[world_rank] = nb_elem_dim2_i;
148 m_sizeof_var[world_rank] = nb_elem_dim1_i * nb_elem_dim2_i * sizeof_elem2;
149 machine_rank++;
150 }
151}
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
162{
163 m_nb_elem_dim1.reserve(m_machine_ranks.size());
164}
165
166/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
168
170updateVariable(Int64 nb_elem_dim1, Int32 nb_elem_dim2, Int64 sizeof_elem)
171{
172 ContigMachineShMemWin<Int64> all_nb_elem(m_pm, 1);
173
174 all_nb_elem.segmentView()[0] = nb_elem_dim1;
175
176 all_nb_elem.barrier();
177
178 Int64 mult = nb_elem_dim2 * sizeof_elem * sizeof_elem;
179
180 for (Int32 machine_rank = 0; const auto nb_elem : all_nb_elem.windowConstView()) {
181 const Int32 world_rank = m_machine_ranks[machine_rank];
182 m_nb_elem_dim1[world_rank] = nb_elem;
183 m_sizeof_var[world_rank] = nb_elem * mult;
184 machine_rank++;
185 }
186}
187
188/*---------------------------------------------------------------------------*/
189/*---------------------------------------------------------------------------*/
190
191ArrayShape MachineShMemWinVariableMDBase::
192arrayShape() const
193{
194 return m_var->data()->shape();
195}
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
200} // End namespace Arcane
201
202/*---------------------------------------------------------------------------*/
203/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Information about an allocated memory region.
void * baseAddress() const
Address of the start of the allocated region.
Array shape.
Definition ArrayShape.h:42
Constant view of an array of type T.
Class allowing the creation of a shared memory window between the subdomains of the same node....
void barrier() const
Method allowing waiting until all processes/threads of the node call this method to continue executio...
Span< Type > segmentView()
Method allowing retrieval of a view on our window segment memory.
Span< const Type > windowConstView() const
Method allowing retrieval of a constant view on the entire window memory.
virtual ArrayShape shape() const =0
Array shape for a 1D or 2D data item.
Interface of a variable.
Definition IVariable.h:40
@ PInShMem
Indicates that the variable must be allocated in shared memory.
Definition IVariable.h:156
virtual IData * data()=0
Data associated with the variable.
MachineShMemWinVariable2DBase(IVariable *var)
Constructor.
void updateVariable(Int64 nb_elem_dim1, Int64 nb_elem_dim2, Int64 sizeof_elem)
Span< std::byte > segmentView(Int32 rank) const
Method allowing retrieval of a view on the segment of another sub-domain of the node.
MachineShMemWinVariableBase(IVariable *var)
Constructor.
void barrier() const
Method allowing waiting until all processes/threads of the node call this method to continue executio...
ConstArrayView< Int32 > machineRanks() const
Method allowing retrieval of the ranks that possess a segment in the window.
void updateVariable(Int64 nb_elem_dim1, Int64 sizeof_elem)
void updateVariable(Int64 nb_elem_dim1, Int32 nb_elem_dim2, Int64 sizeof_elem)
MachineShMemWinVariableMDBase(IVariable *var)
Constructor.
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.
std::int32_t Int32
Signed integer type of 32 bits.