14#include "arcane/materials/internal/AcceleratorMeshMaterialSynchronizerImpl.h"
16#include "arcane/core/VariableTypes.h"
17#include "arcane/core/IParallelMng.h"
18#include "arcane/core/ItemPrinter.h"
19#include "arcane/core/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::
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->runner().isInitialized()) {
45 Arcane::Runner default_runner(Arcane::Accelerator::eExecutionPolicy::Sequential);
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); },
155 if (!to_add[imat].empty()) {
162 modifier.addCells(materials[imat], to_add[imat]);
166 to_remove[imat] = m_idx_selecter.syncSelectIf(m_queue, [=] ARCCORE_HOST_DEVICE(Int32 cid) ->
bool {
167 if (cells_info.isOwn(cid))
169 CellLocalId c{ cid };
170 AllEnvCell allenvcell{ cell_converter[c] };
171 bool was_here =
false;
174 MatCell mc = *imatcell;
175 Integer mat_index = mc.materialId();
177 if (mat_index == imat) {
184 return !_hasBit(out_after_presence[c][imat / 8], imat); },
187 if (!to_remove[imat].empty()) {
194 modifier.removeCells(materials[imat], to_remove[imat]);
Execution queue for an accelerator.
void setAsync(bool v)
Sets the instance's asynchronous state.
void barrier() const
Blocks until all commands associated with the queue are finished.
View of the generic information of an entity family.
Interface for the material and environment manager of a mesh.
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
auto viewInOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Read/write view for scalar material variables.
Always enables tracing in Arcane parts concerning materials.
Int32 Integer
Type representing an integer.