14#include "arcane/utils/NotImplementedException.h"
15#include "arcane/utils/ITraceMng.h"
16#include "arcane/utils/FunctorUtils.h"
17#include "arcane/utils/ArgumentException.h"
18#include "arcane/utils/OStringStream.h"
20#include "arcane/utils/ValueConvert.h"
21#include "arcane/utils/ArraySimdPadder.h"
23#include "arcane/core/IMesh.h"
24#include "arcane/core/IItemFamily.h"
25#include "arcane/core/ItemPrinter.h"
26#include "arcane/core/VariableBuildInfo.h"
27#include "arcane/core/internal/ItemGroupImplInternal.h"
28#include "arcane/core/materials/internal/IMeshMaterialVariableInternal.h"
30#include "arcane/materials/IMeshMaterialVariable.h"
31#include "arcane/materials/CellToAllEnvCellConverter.h"
33#include "arcane/materials/internal/MeshMaterialMng.h"
34#include "arcane/materials/internal/AllEnvData.h"
35#include "arcane/materials/internal/MaterialModifierOperation.h"
36#include "arcane/materials/internal/ConstituentConnectivityList.h"
37#include "arcane/materials/internal/ComponentItemListBuilder.h"
38#include "arcane/materials/internal/AllCellToAllEnvCellContainer.h"
40#include "arcane/accelerator/Scan.h"
75AllEnvData(MeshMaterialMng* mmg)
78, m_item_internal_data(mmg)
82 m_component_connectivity_list =
new ConstituentConnectivityList(m_material_mng);
83 m_component_connectivity_list_ref = m_component_connectivity_list->toSourceReference();
86 m_verbose_debug_level = v.value();
96endCreate(
bool is_continue)
98 m_item_internal_data.endCreate();
99 m_component_connectivity_list->endCreate(is_continue);
106_isFullVerbose()
const
108 return (m_verbose_debug_level > 1 || traceMng()->verbosityLevel() >= 5);
115_computeNbEnvAndNbMatPerCell()
117 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
121 for (MeshEnvironment* env : true_environments) {
122 env->computeNbMatPerCell();
130_computeAndResizeEnvItemsInternal()
134 IMesh* mesh = m_material_mng->mesh();
135 const IItemFamily* cell_family = mesh->cellFamily();
136 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
138 Integer nb_env = true_environments.size();
141 info(4) <<
"NB_ENV = " << nb_env;
142 for (
const MeshEnvironment* env : true_environments) {
144 Integer env_nb_cell = cells.size();
145 info(4) <<
"EnvName=" << cells.name() <<
" nb_env_cell=" << env_nb_cell <<
" nb_mat_cell=" << env->totalNbCellMat();
146 total_env_cell += env_nb_cell;
147 total_mat_cell += env->totalNbCellMat();
151 Int32 max_local_id = cell_family->maxLocalId();
152 info(4) <<
"RESIZE TotalEnvCell=" << total_env_cell
153 <<
" TotalMatCell=" << total_mat_cell
154 <<
" MaxLocalId=" << max_local_id;
159 m_item_internal_data.resizeComponentItemInternals(max_local_id, total_env_cell);
162 Int32 computed_nb_mat = 0;
163 Int32 computed_nb_env = 0;
164 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
165 ConstArrayView<Int16> cells_nb_mat = m_component_connectivity_list->cellsNbMaterial();
166 ENUMERATE_ (Cell, icell, cell_family->allItems()) {
167 Int32 lid = icell.itemLocalId();
168 computed_nb_env += cells_nb_env[lid];
169 computed_nb_mat += cells_nb_mat[lid];
171 Int32 computed_size = computed_nb_mat + computed_nb_env;
172 Int32 storage_size = total_mat_cell + total_env_cell;
173 info(4) <<
"storage_size=" << storage_size <<
" computed=" << computed_size
174 <<
" max_local_id=" << max_local_id <<
" internal_nb_mat=" << total_mat_cell <<
" internal_nb_env=" << total_env_cell
175 <<
" computed_nb_mat=" << computed_nb_mat <<
" computed_nb_env=" << computed_nb_env;
176 if (storage_size != computed_size)
177 ARCANE_FATAL(
"BAD STORAGE SIZE internal={0} connectivity={1}", storage_size, computed_size);
187_rebuildIncrementalConnectivitiesFromGroups()
189 RunQueue queue(
makeQueue(m_material_mng->runner()));
190 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
191 auto clist = m_component_connectivity_list;
192 clist->removeAllConnectivities();
193 for (MeshEnvironment* env : true_environments) {
194 clist->addCellsToEnvironment(env->componentId(), env->cells().view().localIds(), queue);
195 for (MeshMaterial* mat : env->trueMaterials())
196 clist->addCellsToMaterial(mat->componentId(), mat->cells().view().localIds(), queue);
204_rebuildMaterialsAndEnvironmentsFromGroups()
206 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
207 const bool is_full_verbose = _isFullVerbose();
208 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
209 for (
const MeshEnvironment* env : true_environments) {
210 MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
211 ComponentItemListBuilderOld list_builder(var_indexer, 0);
213 Integer var_nb_cell = cells.size();
214 info(4) <<
"ENV_INDEXER (V2) i=" << var_indexer->index() <<
" NB_CELL=" << var_nb_cell <<
" name=" << cells.name()
215 <<
" index=" << var_indexer->index();
217 info(5) <<
"ENV_INDEXER (V2) name=" << cells.name() <<
" cells=" << cells.view().localIds();
220 if (cells_nb_env[icell.itemLocalId()] > 1)
221 list_builder.addPartialItem(icell.itemLocalId());
224 list_builder.addPureItem(icell.itemLocalId());
227 info() <<
"MAT_NB_MULTIPLE_CELL (V2) mat=" << var_indexer->name()
228 <<
" nb_in_global=" << list_builder.pureMatVarIndexes().size()
229 <<
" (ids=" << list_builder.pureMatVarIndexes() <<
")"
230 <<
" nb_in_multiple=" << list_builder.partialMatVarIndexes().size()
231 <<
" (ids=" << list_builder.partialLocalIds() <<
")";
232 var_indexer->endUpdate(list_builder);
235 for (MeshEnvironment* env : true_environments)
236 env->computeItemListForMaterials(*m_component_connectivity_list);
243_computeInfosForAllEnvCells1(RecomputeConstituentCellInfos& work_info)
245 IMesh* mesh = m_material_mng->mesh();
246 IItemFamily* cell_family = mesh->cellFamily();
247 CellGroup all_cells = cell_family->allItems();
248 const Int32 nb_cell = all_cells.
size();
249 const Int32 max_local_id = cell_family->maxLocalId();
251 SmallSpan<const Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
259 bool do_old = (max_local_id != nb_cell);
263 Int32 lid = icell.itemLocalId();
264 Int32 nb_env = cells_nb_env[lid];
265 work_info.env_cell_indexes[lid] = env_cell_index;
266 env_cell_index += nb_env;
272 Accelerator::GenericScanner scanner(work_info.m_queue);
273 SmallSpan<Int32> env_cell_indexes_view(work_info.env_cell_indexes);
274 Accelerator::ScannerSumOperator<Int32> op;
275 scanner.applyExclusive(0, cells_nb_env, env_cell_indexes_view, op, A_FUNCINFO);
283_computeInfosForAllEnvCells2(RecomputeConstituentCellInfos& work_info)
287 SmallSpan<const Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
290 ComponentItemSharedInfo* all_env_shared_info = m_item_internal_data.allEnvSharedInfo();
292 SmallSpan<Int32> env_cell_indexes_view(work_info.env_cell_indexes);
296 Int16 n = cells_nb_env[lid];
297 matimpl::ConstituentItemBase ref_ii(all_env_shared_info, ConstituentItemIndex(lid));
298 ref_ii._setSuperAndGlobalItem({}, cell_id);
299 ref_ii._setVariableIndex(MatVarIndex(0, lid));
300 ref_ii._setNbSubItem(n);
302 ref_ii._setFirstSubItem(ConstituentItemIndex(env_cell_indexes_view[lid]));
312_computeInfosForEnvCells(RecomputeConstituentCellInfos& work_info)
314 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
315 RunQueue queue(m_material_mng->runQueue());
317 IMesh* mesh = m_material_mng->mesh();
318 IItemFamily* cell_family = mesh->cellFamily();
319 const Int32 max_local_id = cell_family->maxLocalId();
321 for (MeshEnvironment* env : true_environments) {
322 const Int16 env_id = env->componentId();
323 const MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
326 env->resizeItemsInternal(var_indexer->nbItem());
328 info(4) <<
"COMPUTE (V2) env_cells env=" << env->
name() <<
" nb_cell=" << cells.size()
329 <<
" index=" << var_indexer->index()
330 <<
" max_multiple_index=" << var_indexer->maxIndexInMultipleArray();
332 SmallSpan<const MatVarIndex> matvar_indexes(var_indexer->matvarIndexes());
336 const bool is_mono_mat = env->isMonoMaterial();
338 work_info.cells_nb_material.resize(max_local_id);
340 SmallSpan<Int16> cells_nb_mat_view = work_info.cells_nb_material.view();
343 m_component_connectivity_list->fillCellsNbMaterial(local_ids, env_id, cells_nb_mat_view, queue);
346 SmallSpan<Int32> current_pos_view(work_info.env_cell_indexes);
347 const Int32 nb_id = matvar_indexes.size();
348 ComponentItemSharedInfo* env_shared_info = m_item_internal_data.envSharedInfo();
350 Span<Int32> env_cells_local_id = cells._internalApi()->itemsLocalId();
351 SmallSpan<ConstituentItemIndex> env_id_list = env->componentData()->m_constituent_local_id_list.mutableLocalIds();
355 MatVarIndex mvi = matvar_indexes[z];
357 Int32 lid = local_ids[z];
358 Int32 pos = current_pos_view[lid];
359 ++current_pos_view[lid];
360 Int16 nb_mat = (is_mono_mat) ? 1 : cells_nb_mat_view[z];
362 ConstituentItemIndex cii_pos(pos);
363 matimpl::ConstituentItemBase ref_ii(env_shared_info, cii_pos);
364 ConstituentItemIndex cii_lid(lid);
365 env_id_list[z] = cii_pos;
367 ref_ii._setSuperAndGlobalItem(cii_lid, ItemLocalId(lid));
368 ref_ii._setNbSubItem(nb_mat);
369 ref_ii._setVariableIndex(mvi);
370 ref_ii._setComponent(env_id);
373 ArraySimdPadder::applySimdPaddingView(env_cells_local_id);
375 cells._internalApi()->notifySimdPaddingDone();
380 Accelerator::RunQueuePool& queue_pool = m_material_mng->_internalApi()->asyncRunQueuePool();
381 for (MeshEnvironment* env : true_environments) {
382 env->computeMaterialIndexes(&m_item_internal_data, queue_pool[env->id()]);
384 queue_pool.barrier();
395_checkLocalIdsCoherency()
const
397 for (MeshEnvironment* env : m_material_mng->trueEnvironments()) {
401 ComponentCell cc = *icitem;
403 Int32 direct_lid = indexer_local_ids[index];
404 if (matvar_lid != direct_lid)
405 ARCANE_FATAL(
"Incoherent localId() matvar_lid={0} direct_lid={1} index={2}",
406 matvar_lid, direct_lid, index);
431forceRecompute(
bool compute_all)
433 m_material_mng->incrementTimestamp();
435 ConstArrayView<MeshMaterialVariableIndexer*> vars_idx = m_material_mng->_internalApi()->variablesIndexer();
436 Integer nb_var = vars_idx.size();
437 Int64 mesh_timestamp = m_material_mng->mesh()->timestamp();
438 info(4) <<
"ForceRecompute NB_VAR_IDX=" << nb_var <<
" compute_all?=" << compute_all
439 <<
" mesh_timestamp=" << mesh_timestamp <<
" current_mesh_timestamp=" << m_current_mesh_timestamp;
442 bool has_mesh_changed = m_current_mesh_timestamp != mesh_timestamp;
443 m_current_mesh_timestamp = mesh_timestamp;
445 const bool is_verbose_debug = m_verbose_debug_level > 0;
449 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
452 _rebuildIncrementalConnectivitiesFromGroups();
456 if (compute_all || has_mesh_changed)
457 _computeNbEnvAndNbMatPerCell();
459 _computeAndResizeEnvItemsInternal();
461 bool is_full_verbose = _isFullVerbose();
464 _rebuildMaterialsAndEnvironmentsFromGroups();
466 for (
const MeshEnvironment* env : true_environments) {
467 const MeshMaterialVariableIndexer* var_indexer = env->variableIndexer();
469 Integer var_nb_cell = cells.size();
470 info(4) <<
"FINAL_INDEXER i=" << var_indexer->index() <<
" NB_CELL=" << var_nb_cell <<
" name=" << cells.name()
471 <<
" index=" << var_indexer->index();
472 if (is_full_verbose) {
474 info(5) <<
"FINAL_INDEXER (V2) name=" << cells.name() <<
" cells=" << my_array;
475 info(4) <<
"FINAL_MAT_NB_MULTIPLE_CELL (V2) mat=" << var_indexer->name()
476 <<
" ids=" << var_indexer->matvarIndexes();
480 RunQueue& queue(m_material_mng->runQueue());
483 RecomputeConstituentCellInfos work_info(queue);
484 _computeInfosForAllEnvCells1(work_info);
485 _computeInfosForAllEnvCells2(work_info);
486 _computeInfosForEnvCells(work_info);
489 if (is_verbose_debug) {
490 _printAllEnvCells(m_material_mng->mesh()->allCells().view());
491 for (IMeshMaterial* material : m_material_mng->materials()) {
493 MatCell pmc = *imatcell;
494 info() <<
"CELL IN MAT vindex=" << pmc._varIndex();
500 for (MeshEnvironment* env : true_environments) {
501 env->componentData()->_rebuildPartData(queue);
502 for (MeshMaterial* mat : env->trueMaterials())
503 mat->componentData()->_rebuildPartData(queue);
508 m_material_mng->checkValid();
510 m_material_mng->syncVariablesReferences(compute_all);
512 if (is_verbose_debug) {
514 m_material_mng->dumpInfos2(ostr());
515 info() << ostr.str();
521 _checkLocalIdsCoherency();
524 if (m_material_mng->isCellToAllEnvCellForRunCommand()) {
525 auto* all_cell_to_all_env_cell(m_material_mng->_internalApi()->getAllCellToAllEnvCellContainer());
526 if (all_cell_to_all_env_cell)
527 all_cell_to_all_env_cell->bruteForceUpdate();
529 m_material_mng->_internalApi()->createAllCellToAllEnvCell();
537recomputeIncremental()
539 forceRecompute(
false);
541 _checkConnectivityCoherency();
550 ConstArrayView<Int16> cells_nb_env = m_component_connectivity_list->cellsNbEnvironment();
552 AllEnvCell all_env_cell = *iallenvcell;
553 Integer cell_nb_env = all_env_cell.nbEnvironment();
554 Cell cell = all_env_cell.globalCell();
555 info() <<
"CELL2 uid=" << ItemPrinter(cell)
556 <<
" nb_env=" << cells_nb_env[cell.localId()]
557 <<
" direct_nb_env=" << cell_nb_env;
558 for (Integer z = 0; z < cell_nb_env; ++z) {
559 EnvCell ec = all_env_cell.cell(z);
560 Integer cell_nb_mat = ec.nbMaterial();
561 info() <<
"CELL3 nb_mat=" << cell_nb_mat <<
" env_id=" << ec.environmentId();
562 for (Integer k = 0; k < cell_nb_mat; ++k) {
563 MatCell mc = ec.cell(k);
564 info() <<
"CELL4 mat_item=" << mc._varIndex() <<
" mat_id=" << mc.materialId();
574_checkConnectivityCoherency()
576 info() <<
"AllEnvData: checkCoherency()";
577 ConstArrayView<Int16> nb_mat_v2 = m_component_connectivity_list->cellsNbMaterial();
578 ConstArrayView<MeshEnvironment*> true_environments(m_material_mng->trueEnvironments());
580 ItemGroup all_cells = m_material_mng->mesh()->allCells();
586 Int32 ref_nb_mat = 0;
587 for (MeshEnvironment* env : true_environments) {
588 Int16 env_id = env->componentId();
589 ref_nb_mat += m_component_connectivity_list->cellNbMaterial(icell, env_id);
591 Int32 current_nb_mat = nb_mat_v2[icell.itemLocalId()];
592 if (ref_nb_mat != current_nb_mat) {
595 error() <<
"Invalid values for nb_material cell=" << icell->uniqueId()
596 <<
" ref=" << ref_nb_mat <<
" current=" << current_nb_mat;
601 ARCANE_FATAL(
"Invalid values for component connectivity nb_error={0}", nb_error);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions de gestion mémoire et des allocateurs.
Types et macros pour gérer les énumérations des entités sur les accélérateurs.
#define RUNCOMMAND_ENUMERATE(ItemTypeName, iter_name, item_group,...)
Macro pour itérer sur accélérateur sur un groupe d'entités.
Types et macros pour gérer les boucles sur les accélérateurs.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
Boucle sur accélérateur avec arguments supplémentaires pour les réductions.
File d'exécution pour un accélérateur.
MemoryAllocationOptions allocationOptions() const
Options d'allocation associée à cette file.
virtual CellGroup allCells()=0
Groupe de toutes les mailles.
const String & name() const
Nom du groupe.
Integer size() const
Nombre d'éléments du groupe.
IMesh * mesh() const
Maillage auquel appartient ce groupe (0 pour le group nul)
constexpr Int32 localId() const
Identifiant local de l'entité dans le sous-domaine du processeur.
Cell globalCell() const
Maille globale.
Classe d'accès aux traces.
Vecteur 1D de données avec sémantique par valeur (style STL).
ItemGroupT< Cell > CellGroup
Groupe de mailles.
ItemVectorViewT< Cell > CellVectorView
Vue sur un vecteur de mailles.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
RunQueue makeQueue(const Runner &runner)
Créé une file associée à runner.
Active toujours les traces dans les parties Arcane concernant les matériaux.
Int32 checkResizeArrayWithCapacity(Array< DataType > &array, Int64 new_size, bool force_resize)
Redimensionne un tableau en ajoutant une réserve de mémoire.
bool arcaneIsCheck()
Vrai si on est en mode vérification.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Int32 Integer
Type représentant un entier.