14#include "arcane/materials/internal/AcceleratorMeshMaterialSynchronizerImpl.h"
16#include "arcane/VariableTypes.h"
17#include "arcane/IParallelMng.h"
18#include "arcane/ItemPrinter.h"
19#include "arcane/IMesh.h"
21#include "arcane/materials/CellToAllEnvCellConverter.h"
22#include "arcane/materials/MatItemEnumerator.h"
23#include "arcane/materials/MeshMaterialModifier.h"
25#include "arcane/core/ItemGenericInfoListView.h"
26#include "arcane/core/internal/IParallelMngInternal.h"
36AcceleratorMeshMaterialSynchronizerImpl::
37AcceleratorMeshMaterialSynchronizerImpl(IMeshMaterialMng* material_mng)
38: TraceAccessor(material_mng->traceMng())
39, m_material_mng(material_mng)
40, m_mat_presence(VariableBuildInfo(material_mng->mesh(),
"ArcaneMaterialSyncPresence"))
42 IMesh* mesh = m_material_mng->mesh();
43 auto* internal_pm = mesh->parallelMng()->_internalApi();
44 if (internal_pm->defaultRunner() ==
nullptr) {
46 internal_pm->setDefaultRunner(default_runner);
49 m_idx_selecter = Arcane::Accelerator::IndexSelecter(m_queue);
58bool AcceleratorMeshMaterialSynchronizerImpl::
59synchronizeMaterialsInCells()
76 IMesh* mesh = m_material_mng->mesh();
77 if (!mesh->parallelMng()->isParallel())
80 auto* internal_pm = mesh->parallelMng()->_internalApi();
82 ConstArrayView<IMeshMaterial*> materials = m_material_mng->materials();
83 Integer nb_mat = materials.size();
85 if ((nb_mat % 8) != 0)
87 m_mat_presence.resize(dim2_size);
89 info(4) <<
"Resize presence variable nb_mat=" << nb_mat <<
" dim2=" << dim2_size;
90 CellToAllEnvCellConverter cell_converter = m_material_mng->cellToAllEnvCellConverter();
98 CellToAllEnvCellAccessor cell2allenvcell(m_material_mng);
100 m_idx_selecter.resize(mesh->allCells().size());
102 command << RUNCOMMAND_ENUMERATE_CELL_ALLENVCELL(cell2allenvcell, cid, mesh->ownCells())
104 AllEnvCell allenvcell{ cell_converter[cid] };
106 for (Integer dim2 = 0; dim2 < dim2_size; dim2++) {
107 out_mat_presence[cid][dim2] = 0;
112 MatCell mc = *imatcell;
113 Integer mat_index = mc.materialId();
114 _setBit(out_mat_presence[cid][mat_index / 8], mat_index);
119 bool has_changed =
false;
122 m_mat_presence.synchronize();
124 auto out_after_presence = out_mat_presence;
127 UniqueArray<ConstArrayView<Int32>> to_add(nb_mat);
128 UniqueArray<ConstArrayView<Int32>> to_remove(nb_mat);
130 MeshMaterialModifier modifier(m_material_mng);
132 for (Integer imat = 0; imat < nb_mat; ++imat) {
134 to_add[imat] = m_idx_selecter.syncSelectIf(m_queue, [=] ARCCORE_HOST_DEVICE(Int32 cid) ->
bool {
135 if (cells_info.isOwn(cid))
137 CellLocalId c{ cid };
138 AllEnvCell allenvcell{ cell_converter[c] };
139 bool was_here =
false;
142 MatCell mc = *imatcell;
143 Integer mat_index = mc.materialId();
145 if (mat_index == imat) {
152 return _hasBit(out_after_presence[c][imat / 8], imat);
156 if (!to_add[imat].empty()) {
163 modifier.addCells(materials[imat], to_add[imat]);
167 to_remove[imat] = m_idx_selecter.syncSelectIf(m_queue, [=] ARCCORE_HOST_DEVICE(Int32 cid) ->
bool {
168 if (cells_info.isOwn(cid))
170 CellLocalId c{ cid };
171 AllEnvCell allenvcell{ cell_converter[c] };
172 bool was_here =
false;
175 MatCell mc = *imatcell;
176 Integer mat_index = mc.materialId();
178 if (mat_index == imat) {
185 return !_hasBit(out_after_presence[c][imat / 8], imat);
189 if (!to_remove[imat].empty()) {
196 modifier.removeCells(materials[imat], to_remove[imat]);
File d'exécution pour un accélérateur.
void setAsync(bool v)
Positionne l'asynchronisme de l'instance.
void barrier() const
Bloque tant que toutes les commandes associées à la file ne sont pas terminées.
Gestionnaire d'exécution pour accélérateur.
Vue sur les informations génériques d'une famille d'entités.
auto viewInOut(RunCommand &cmd, CellMaterialVariableScalarRef< DataType > &var)
Vue en lecture/écriture pour les variables materiaux scalaire.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
@ Sequential
Politique d'exécution séquentielle.
Active toujours les traces dans les parties Arcane concernant les matériaux.
Int32 Integer
Type représentant un entier.