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);
58bool AcceleratorMeshMaterialSynchronizerImpl::
59synchronizeMaterialsInCells()
77 if (!
mesh->parallelMng()->isParallel())
80 auto* internal_pm =
mesh->parallelMng()->_internalApi();
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;
100 m_idx_selecter.resize(
mesh->allCells().size());
102 command << RUNCOMMAND_ENUMERATE_CELL_ALLENVCELL(cell2allenvcell, cid,
mesh->ownCells())
106 for (
Integer dim2 = 0; dim2 < dim2_size; dim2++) {
107 out_mat_presence[cid][dim2] = 0;
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;
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 };
139 bool was_here =
false;
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 };
171 bool was_here =
false;
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]);
Construction of a subset of indices from a criterion.
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.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
View of the generic information of an entity family.
constexpr __host__ __device__ bool isOwn(Int32 local_id) const
Indicates if the entity with local ID local_id belongs to the subdomain.
Arcane cell with material and environment information.
Encapsulation class to access the equivalent connectivity cell -> allenvcell. Intended to be used wit...
Conversion of 'Cell' to 'AllEnvCell'.
Interface for the material and environment manager of a mesh.
Represents a material in a multi-material cell.
__host__ __device__ Int32 materialId() const
Material identifier.
Object allowing modification of materials or media.
void addCells(IMeshMaterial *mat, SmallSpan< const Int32 > ids)
Adds the cells with local indices ids to the material mat.
void removeCells(IMeshMaterial *mat, SmallSpan< const Int32 > ids)
Removes the cells with local indices ids from the material mat.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
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.
std::int32_t Int32
Signed integer type of 32 bits.