Arcane  v4.1.7.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
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/* Classes de bases permettant d'exploiter l'objet MachineShMemWinVariable */
11/* pointé de la zone mémoire des variables en mémoire partagée. */
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/internal/MachineShMemWinVariableBase.h"
15
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/ITraceMng.h"
18#include "arcane/utils/ArrayShape.h"
19
20#include "arcane/core/ContigMachineShMemWin.h"
21#include "arcane/core/IMesh.h"
22#include "arcane/core/ISubDomain.h"
23#include "arcane/core/MeshHandle.h"
24#include "arcane/core/IData.h"
25#include "arcane/core/IParallelMng.h"
26#include "arcane/core/IVariable.h"
27
28#include "arcane/core/internal/MachineShMemWinMemoryAllocator.h"
29#include "arcane/core/internal/IDataInternal.h"
30#include "arcane/core/internal/IParallelMngInternal.h"
31
32#include "arccore/common/AllocatedMemoryInfo.h"
33#include "arccore/base/MemoryView.h"
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38namespace Arcane
39{
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
46: m_var(var)
47{
48 if (!(m_var->property() & IVariable::PInShMem)) {
49 ARCANE_FATAL("The variable has not PInShMem property");
50 }
51 if (m_var->meshHandle().hasMesh()) {
52 m_pm = m_var->meshHandle().mesh()->parallelMng();
53 }
54 else {
55 m_pm = m_var->subDomain()->parallelMng();
56 }
57 m_sizeof_var.resize(m_pm->commSize(), 0);
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
64machineRanks() const
65{
66 return m_pm->_internalApi()->machineRanks();
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
73barrier() const
74{
75 return m_pm->_internalApi()->machineBarrier();
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
82segmentView(Int32 rank) const
83{
84 const AllocatedMemoryInfo data(m_var->data()->_commonInternal()->numericData()->memoryView().data());
85#ifdef ARCANE_CHECK
86 if (data.baseAddress() == nullptr) {
87 ARCANE_FATAL("Variable not initialised yet. Call var.resize() method before.");
88 }
89#endif
90 return MachineShMemWinMemoryAllocator::segmentView(data, rank).subSpan(0, m_sizeof_var[rank]);
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
97updateVariable(Int64 nb_elem_dim1, Int64 sizeof_elem)
98{
99 ContigMachineShMemWin<Int64> all_size(m_pm, 1);
100
101 all_size.segmentView()[0] = nb_elem_dim1 * sizeof_elem;
102 all_size.barrier();
103 m_sizeof_var = all_size.windowConstView();
104}
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
115, m_nb_elem_dim1(m_pm->commSize(), 0)
116, m_nb_elem_dim2(m_pm->commSize(), 0)
117{}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
123updateVariable(Int64 nb_elem_dim1, Int64 nb_elem_dim2, Int64 sizeof_elem)
124{
125 ContigMachineShMemWin<Int64> all_size(m_pm, 2);
126
127 all_size.segmentView()[0] = nb_elem_dim1;
128 all_size.segmentView()[1] = nb_elem_dim2;
129
130 all_size.barrier();
131
132 Int64 sizeof_elem2 = sizeof_elem * sizeof_elem;
133
134 for (Int32 i = 0; i < m_pm->commSize(); ++i) {
135 const Int32 i2 = i * 2;
136 m_nb_elem_dim1[i] = all_size.windowConstView()[i2];
137 m_nb_elem_dim2[i] = all_size.windowConstView()[i2 + 1];
138 m_sizeof_var[i] = m_nb_elem_dim1[i] * m_nb_elem_dim2[i] * sizeof_elem2;
139 }
140}
141
142/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144
145ArrayView<Int64> MachineShMemWinVariable2DBase::
146nbElemDim1()
147{
148 return m_nb_elem_dim1;
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154ArrayView<Int64> MachineShMemWinVariable2DBase::
155nbElemDim2()
156{
157 return m_nb_elem_dim2;
158}
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
169, m_nb_elem_dim1(m_pm->commSize(), 0)
170{}
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
176updateVariable(Int64 nb_elem_dim1, Int32 nb_elem_dim2, Int64 sizeof_elem)
177{
178 ContigMachineShMemWin<Int64> all_size(m_pm, 1);
179
180 all_size.segmentView()[0] = nb_elem_dim1;
181
182 all_size.barrier();
183
184 m_nb_elem_dim1 = all_size.windowConstView();
185
186 Int64 mult = nb_elem_dim2 * sizeof_elem * sizeof_elem;
187
188 for (Integer i = 0; i < m_pm->commSize(); ++i) {
189 m_sizeof_var[i] = m_nb_elem_dim1[i] * mult;
190 }
191}
192
193/*---------------------------------------------------------------------------*/
194/*---------------------------------------------------------------------------*/
195
196ArrayView<Int64> MachineShMemWinVariableMDBase::
197nbElemDim1()
198{
199 return m_nb_elem_dim1;
200}
201
202/*---------------------------------------------------------------------------*/
203/*---------------------------------------------------------------------------*/
204
205ArrayShape MachineShMemWinVariableMDBase::
206arrayShape()
207{
208 return m_var->data()->shape();
209}
210
211/*---------------------------------------------------------------------------*/
212/*---------------------------------------------------------------------------*/
213
214} // End namespace Arcane
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Informations sur une zone mémoire allouée.
void * baseAddress() const
Adresse du début de la zone allouée.
Vue modifiable d'un tableau d'un type T.
Vue constante d'un tableau de type T.
Classe permettant de créer une fenêtre mémoire partagée entre les sous-domaines d'un même noeud....
void barrier() const
Méthode permettant d'attendre que tous les processus/threads du noeud appellent cette méthode pour co...
Span< Type > segmentView()
Méthode permettant d'obtenir une vue sur notre segment de fenêtre mémoire.
Span< const Type > windowConstView() const
Méthode permettant d'obtenir une vue constante sur toute la fenêtre mémoire.
virtual ArrayShape shape() const =0
Forme du tableau pour une donnée 1D ou 2D.
Interface d'une variable.
Definition IVariable.h:39
@ PInShMem
Indique que la variable doit être alloué en mémoire partagée.
Definition IVariable.h:158
virtual IData * data()=0
Données associées à la variable.
MachineShMemWinVariable2DBase(IVariable *var)
Constructeur.
void updateVariable(Int64 nb_elem_dim1, Int64 nb_elem_dim2, Int64 sizeof_elem)
Span< std::byte > segmentView(Int32 rank) const
Méthode permettant d'obtenir une vue sur le segment d'un autre sous-domaine du noeud.
MachineShMemWinVariableBase(IVariable *var)
Constructeur.
void barrier() const
Méthode permettant d'attendre que tous les processus/threads du noeud appellent cette méthode pour co...
ConstArrayView< Int32 > machineRanks() const
Méthode permettant d'obtenir les rangs qui possèdent un segment dans la fenêtre.
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)
Constructeur.
Vue d'un tableau d'éléments de type T.
Definition Span.h:633
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
std::int32_t Int32
Type entier signé sur 32 bits.