Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ComponentItemInternalData.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* ComponentItemInternalData.cc (C) 2000-2025 */
9/* */
10/* Gestion des listes de 'ComponentItemInternal'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/materials/internal/ComponentItemInternalData.h"
15
17
18#include "arcane/core/IItemFamily.h"
20#include "arcane/core/internal/IItemFamilyInternal.h"
21
22#include "arcane/materials/internal/MeshMaterialMng.h"
23
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane::Materials
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36MemoryAllocationOptions ComponentItemInternalData::Storage::
37_allocInfo(const MemoryAllocationOptions& alloc_info, const String& base_name, const String& name)
38{
39 MemoryAllocationOptions opts(alloc_info);
40 opts.setArrayName(base_name + name);
41 return opts;
42}
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
47ComponentItemInternalData::Storage::
48Storage(const MemoryAllocationOptions& alloc_info, const String& base_name)
49: m_first_sub_constituent_item_id_list(_allocInfo(alloc_info, base_name, "FirtSubComponentIdList"))
50, m_super_component_item_local_id_list(_allocInfo(alloc_info, base_name, "SuperComponentIdList"))
51, m_component_id_list(_allocInfo(alloc_info, base_name, "ComponentIdList"))
52, m_nb_sub_constituent_item_list(_allocInfo(alloc_info, base_name, "NbSubConstituentItemList"))
53, m_global_item_local_id_list(_allocInfo(alloc_info, base_name, "GlobalItemLocalIdList"))
54, m_var_index_list(_allocInfo(alloc_info, base_name, "VarIndexList"))
55{
56}
57
58/*---------------------------------------------------------------------------*/
59/*---------------------------------------------------------------------------*/
60
61void ComponentItemInternalData::Storage::
62resize(Int32 new_size, ComponentItemSharedInfo* shared_info, RunQueue& queue)
63{
64 // On dimensionne au nombre d'éléments + 1.
65 // On décale de 1 la vue pour qu'elle puisse être indexée avec l'entité
66 // nulle (d'indice (-1)).
67 Int32 true_size = new_size + 1;
68 m_size = new_size;
69
70 const bool force_resize = false;
71 MemoryUtils::checkResizeArrayWithCapacity(m_first_sub_constituent_item_id_list, true_size, force_resize);
72 MemoryUtils::checkResizeArrayWithCapacity(m_super_component_item_local_id_list, true_size, force_resize);
73 MemoryUtils::checkResizeArrayWithCapacity(m_component_id_list, true_size, force_resize);
74 MemoryUtils::checkResizeArrayWithCapacity(m_nb_sub_constituent_item_list, true_size, force_resize);
75 MemoryUtils::checkResizeArrayWithCapacity(m_global_item_local_id_list, true_size, force_resize);
76 MemoryUtils::checkResizeArrayWithCapacity(m_var_index_list, true_size, force_resize);
77
78 auto first_sub_constituent_item_id_list = m_first_sub_constituent_item_id_list.smallSpan();
79 auto super_component_item_local_id_list = m_super_component_item_local_id_list.smallSpan();
80 auto component_id_list = m_component_id_list.smallSpan();
81 auto nb_sub_constituent_item_list = m_nb_sub_constituent_item_list.smallSpan();
82 auto global_item_local_id_list = m_global_item_local_id_list.smallSpan();
83 auto var_index_list = m_var_index_list.smallSpan();
84
85 // Met à jour les pointeurs.
86 // On le fait sur l'accélérateur pour éviter des recopies avec le CPU.
87 {
88 auto command = makeCommand(queue);
89 command << RUNCOMMAND_SINGLE()
90 {
91 shared_info->m_storage_size = new_size;
92 first_sub_constituent_item_id_list[0] = {};
93 component_id_list[0] = -1;
94 nb_sub_constituent_item_list[0] = 0;
95 global_item_local_id_list[0] = NULL_ITEM_LOCAL_ID;
96 var_index_list[0].reset();
97
98 shared_info->m_first_sub_constituent_item_id_data = first_sub_constituent_item_id_list.data() + 1;
99 shared_info->m_super_component_item_local_id_data = super_component_item_local_id_list.data() + 1;
100 shared_info->m_component_id_data = component_id_list.data() + 1;
101
102 shared_info->m_nb_sub_constituent_item_data = nb_sub_constituent_item_list.data() + 1;
103 shared_info->m_global_item_local_id_data = global_item_local_id_list.data() + 1;
104 shared_info->m_var_index_data = var_index_list.data() + 1;
105 };
106 }
107}
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
115ComponentItemInternalData::
116ComponentItemInternalData(MeshMaterialMng* mmg)
117: TraceAccessor(mmg->traceMng())
118, m_material_mng(mmg)
119, m_shared_infos(MemoryUtils::getAllocatorForMostlyReadOnlyData())
120, m_all_env_storage(_allocOptions(), "AllEnvStorage")
121, m_env_storage(_allocOptions(), "EnvStorage")
122, m_mat_storage(_allocOptions(), "MatStorage")
123{
124 // Initialise l'instance nulle. Ce n'est pas grave si on le fait plusieurs fois
125 // car la valeur ne change pas.
126 ComponentItemSharedInfo::_setNullInstance();
127
128 // Il y a une instance pour les MatCell, les EnvCell et les AllEnvCell
129 // Il ne faut ensuite plus modifier ce tableau car on conserve des pointeurs
130 // vers les éléments de ce tableau.
131 m_shared_infos.resize(3);
132 m_shared_infos.setDebugName("ComponentItemInternalDataSharedInfo");
133}
134
135/*---------------------------------------------------------------------------*/
136/*---------------------------------------------------------------------------*/
137
138MemoryAllocationOptions ComponentItemInternalData::
139_allocOptions()
140{
141 return MemoryAllocationOptions(platform::getDefaultDataAllocator());
142}
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
146
147void ComponentItemInternalData::
148endCreate()
149{
150 _initSharedInfos();
151}
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
158void ComponentItemInternalData::
159_resetItemsInternal()
160{
161 if (!arcaneIsCheck())
162 return;
163
164 RunQueue queue(m_material_mng->runQueue());
165
166 {
167 ComponentItemSharedInfo* all_env_shared_info = allEnvSharedInfo();
168 ComponentItemSharedInfo* env_shared_info = envSharedInfo();
169 ComponentItemSharedInfo* mat_shared_info = matSharedInfo();
170 const Int32 all_env_size = m_all_env_storage.size();
171 const Int32 env_size = m_env_storage.size();
172 const Int32 mat_size = m_mat_storage.size();
173 Int32 max_size = math::max(all_env_size, env_size, mat_size);
174
175 auto command = makeCommand(queue);
176 command << RUNCOMMAND_LOOP1(iter, max_size)
177 {
178 auto [i] = iter();
180 if (i < all_env_size)
181 all_env_shared_info->_reset(cii);
182 if (i < env_size)
183 env_shared_info->_reset(cii);
184 if (i < mat_size)
185 mat_shared_info->_reset(cii);
186 };
187 }
188}
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193void ComponentItemInternalData::
194resizeComponentItemInternals(Int32 max_local_id, Int32 total_nb_env_cell)
195{
196 RunQueue& queue(m_material_mng->runQueue());
197
198 auto environments = m_material_mng->trueEnvironments();
199 const Int32 nb_env = environments.size();
200 NumArray<ComponentItemInternalRange, MDDim1> host_mats_range(nb_env);
201
202 // Calcule le nombre total de ComponentItemInternal dont on a besoin
203 Int32 total_nb_mat_cell = 0;
204 for (const MeshEnvironment* env : m_material_mng->trueEnvironments())
205 total_nb_mat_cell += env->totalNbCellMat();
206
207 // Maintenant récupère les vues sur chaque partie du conteneur
208 {
209 m_all_env_items_internal_range.setRange(0, max_local_id);
210 m_env_items_internal_range.setRange(0, total_nb_env_cell);
211 Int32 index_in_container = 0;
212 for (MeshEnvironment* env : m_material_mng->trueEnvironments()) {
213 Int32 nb_cell_mat = env->totalNbCellMat();
215 mat_range.setRange(index_in_container, nb_cell_mat);
216 env->setMatInternalDataRange(mat_range);
217 index_in_container += nb_cell_mat;
218 }
219 }
220
221 info(4) << "ResizeStorage max_local_id=" << max_local_id
222 << " total_nb_env_cell=" << total_nb_env_cell
223 << " total_nb_mat_cell=" << total_nb_mat_cell;
224 {
225 RunQueue::ScopedAsync sc(&queue);
226 m_all_env_storage.resize(max_local_id, allEnvSharedInfo(), queue);
227 m_env_storage.resize(total_nb_env_cell, envSharedInfo(), queue);
228 m_mat_storage.resize(total_nb_mat_cell, matSharedInfo(), queue);
229 }
230
232}
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
236
237void ComponentItemInternalData::
238_initSharedInfos()
239{
240 IItemFamily* family = m_material_mng->mesh()->cellFamily();
241 ItemSharedInfo* item_shared_info = family->_internalApi()->commonItemSharedInfo();
242
243 // NOTE : les champs 'm_components' sont des vues et donc il
244 // ne faut pas que conteneurs associés de \a m_materials_mng soient modifiées.
245 // Normalement ce n'est pas le cas, car la liste des constituants est fixe.
246 ComponentItemSharedInfo* info_mat = sharedInfo(LEVEL_MATERIAL);
247 ComponentItemSharedInfo* info_env = sharedInfo(LEVEL_ENVIRONMENT);
248 ComponentItemSharedInfo* info_all_env = sharedInfo(LEVEL_ALLENVIRONMENT);
249
250 info_mat->m_level = LEVEL_MATERIAL;
251 info_mat->m_item_shared_info = item_shared_info;
252 info_mat->m_components = m_material_mng->materialsAsComponents();
253 info_mat->m_super_component_item_shared_info = info_env;
254
255 info_env->m_level = LEVEL_ENVIRONMENT;
256 info_env->m_item_shared_info = item_shared_info;
257 info_env->m_components = m_material_mng->environmentsAsComponents();
258 info_env->m_super_component_item_shared_info = info_all_env;
259 info_env->m_sub_component_item_shared_info = info_mat;
260
261 info_all_env->m_level = LEVEL_ALLENVIRONMENT;
262 info_all_env->m_item_shared_info = item_shared_info;
263 info_all_env->m_components = ConstArrayView<IMeshComponent*>();
264 info_all_env->m_sub_component_item_shared_info = info_env;
265 info() << "EndCreate ComponentItemInternalData nb_mat=" << info_mat->m_components.size()
266 << " nb_env=" << info_env->m_components.size();
267 info() << "EndCreate ComponentItemInternalData mat_shared_info=" << info_mat
268 << " env_shared_info=" << info_env;
269}
270
271/*---------------------------------------------------------------------------*/
272/*---------------------------------------------------------------------------*/
273
274} // End namespace Arcane::Materials
275
276/*---------------------------------------------------------------------------*/
277/*---------------------------------------------------------------------------*/
Fonctions mathématiques diverses.
Types et macros pour gérer les boucles sur les accélérateurs.
#define RUNCOMMAND_SINGLE(...)
Boucle sur accélérateur pour exécution avec un seul thread.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
Boucle sur accélérateur avec arguments supplémentaires pour les réductions.
Fonctions de gestion mémoire et des allocateurs.
Permet de modifier l'asynchronisme de la file pendant la durée de vie de l'instance.
File d'exécution pour un accélérateur.
Vue constante d'un tableau de type T.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
virtual ItemSharedInfo * commonItemSharedInfo()=0
Instance de ItemSharedInfo pour les entités de la famille.
Interface d'une famille d'entités.
Definition IItemFamily.h:84
virtual IMesh * mesh() const =0
Maillage associé
virtual IItemFamilyInternal * _internalApi()=0
API interne à Arcane.
virtual IItemFamily * cellFamily()=0
Retourne la famille des mailles.
Structure interne partagée d'une entité de maillage.
void _resetItemsInternal()
Réinitialise les ComponentItemInternal associés aux EnvCell et AllEnvCell.
Interval des identifiants des constituants dans la liste des ComponentItemInternal.
Index d'une entité constituant dans la liste des entités constituants.
Tableaux multi-dimensionnels pour les types numériques accessibles sur accélérateurs.
TraceMessage info() const
Flot pour un message d'information.
T max(const T &a, const T &b, const T &c)
Retourne le maximum de trois éléments.
Definition MathUtils.h:392
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
Active toujours les traces dans les parties Arcane concernant les matériaux.
ARCCORE_COMMON_EXPORT MemoryAllocationOptions getAllocatorForMostlyReadOnlyData()
Allocateur par défaut pour les données essentiellement en lecture.
bool arcaneIsCheck()
Vrai si on est en mode vérification.
Definition Misc.cc:68
std::int32_t Int32
Type entier signé sur 32 bits.