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