14#include "arcane/materials/internal/ConstituentItemVectorImpl.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/FatalErrorException.h"
19#include "arcane/core/materials/IMeshMaterialMng.h"
21#include "arcane/core/materials/internal/IMeshComponentInternal.h"
22#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
24#include "arcane/accelerator/core/RunQueue.h"
25#include "arcane/accelerator/RunCommandLoop.h"
26#include "arcane/accelerator/Reduce.h"
27#include "arcane/accelerator/Partitioner.h"
39ConstituentItemVectorImpl::
41: m_material_mng(component->materialMng())
42, m_component(component)
49 if (component->isMaterial())
50 level = LEVEL_MATERIAL;
51 else if (component->isEnvironment())
52 level = LEVEL_ENVIRONMENT;
55 m_component_shared_info = m_material_mng->_internalApi()->componentItemSharedInfo(level);
56 m_constituent_list = std::make_unique<ConstituentItemLocalIdList>(m_component_shared_info, String());
57 m_part_data->setRecomputeFunctor(&m_recompute_part_data_functor);
63ConstituentItemVectorImpl::
64ConstituentItemVectorImpl(
const ComponentItemVectorView& rhs)
65: ConstituentItemVectorImpl(rhs.component())
67 RunQueue& queue = m_material_mng->_internalApi()->runQueue();
68 m_constituent_list->copy(rhs._constituentItemListView());
69 m_matvar_indexes.copy(rhs._matvarIndexes());
70 m_items_local_id.copy(rhs._internalLocalIds());
71 m_part_data->_setFromMatVarIndexes(rhs._matvarIndexes(), queue);
87 explicit SetItemHelper(
bool use_new_impl)
88 : m_use_new_impl(use_new_impl)
93 template <
typename ConstituentGetterLambda>
94 void setItems(ConstituentItemVectorImpl* vector_impl,
95 ConstituentGetterLambda constituent_getter_lambda,
100 bool m_use_new_impl =
true;
106template <
typename ConstituentGetterLambda>
void
107ConstituentItemVectorImpl::SetItemHelper::
108setItems(ConstituentItemVectorImpl* vector_impl, ConstituentGetterLambda constituent_getter_lambda,
115 const bool is_env = vector_impl->m_component->
isEnvironment();
116 const Int32 component_id = vector_impl->m_component->
id();
118 const Int32 nb_pure = vector_impl->m_nb_pure;
120 Int32 pure_index = 0;
121 Int32 impure_index = nb_pure;
127 auto setter_unselected = [=] ARCCORE_HOST_DEVICE(
Int32,
Int32) {
129 auto generic_setter_lambda = [=] ARCCORE_HOST_DEVICE(
Int32 index, ComponentCell cc) {
132 item_indexes[index] = cii;
133 matvar_indexes[index] = idx;
138 if (m_use_new_impl) {
140 auto select_pure = [=] ARCCORE_HOST_DEVICE(
Int32 index) {
141 ComponentCell cc = constituent_getter_lambda(index);
147 auto select_impure = [=] ARCCORE_HOST_DEVICE(Int32 index) {
148 ComponentCell cc = constituent_getter_lambda(index);
151 return (cc._varIndex().arrayIndex() != 0);
153 auto setter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
154 ComponentCell cc = constituent_getter_lambda(index);
156 generic_setter_lambda(output_index, cc);
158 auto setter_pure = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
159 setter_lambda(index, output_index);
161 auto setter_impure = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
162 setter_lambda(index, output_index + nb_pure);
165 generic_partitioner.applyWithIndex(nb_id, setter_pure, setter_impure, setter_unselected,
166 select_pure, select_impure, A_FUNCINFO);
174 AllEnvCell all_env_cell = *iallenvcell;
175 for (EnvCell ec : all_env_cell.subEnvItems()) {
176 if (ec.componentId() == component_id) {
177 MatVarIndex idx = ec._varIndex();
178 ConstituentItemIndex cii = ec._constituentItemIndex();
179 Int32& base_index = (idx.arrayIndex() == 0) ? pure_index : impure_index;
180 item_indexes[base_index] = cii;
181 matvar_indexes[base_index] = idx;
182 items_local_id[base_index] = all_env_cell.globalCellId();
191 AllEnvCell all_env_cell = *iallenvcell;
192 for (EnvCell env_cell : all_env_cell.subEnvItems()) {
193 for (MatCell mc : env_cell.subMatItems()) {
194 if (mc.componentId() == component_id) {
195 MatVarIndex idx = mc._varIndex();
196 ConstituentItemIndex cii = mc._constituentItemIndex();
197 Int32& base_index = (idx.arrayIndex() == 0) ? pure_index : impure_index;
198 item_indexes[base_index] = cii;
199 matvar_indexes[base_index] = idx;
200 items_local_id[base_index] = all_env_cell.globalCellId();
219void ConstituentItemVectorImpl::
222 const bool do_new_impl = m_material_mng->_internalApi()->isUseAcceleratorForConstituentItemVector();
225 RunQueue queue = m_material_mng->_internalApi()->runQueue(exec_policy);
228 _computeNbPureAndImpure(local_ids, queue);
232 const Int32 nb_pure = m_nb_pure;
233 const Int32 nb_impure = m_nb_impure;
234 const Int32 total_nb_pure_and_impure = nb_pure + nb_impure;
241 m_constituent_list->resize(total_nb_pure_and_impure);
246 m_matvar_indexes.resize(total_nb_pure_and_impure);
247 m_items_local_id.resize(total_nb_pure_and_impure);
249 const bool is_env = m_component->isEnvironment();
251 const Int32 component_id = m_component->id();
254 auto env_component_getter_lambda = [=] ARCCORE_HOST_DEVICE(
Int32 index) -> ComponentCell {
255 AllEnvCell all_env_cell = all_env_cell_view[index];
257 if (ec.componentId() == component_id)
264 auto mat_component_getter_lambda = [=] ARCCORE_HOST_DEVICE(
Int32 index) -> ComponentCell {
265 AllEnvCell all_env_cell = all_env_cell_view[index];
267 for (
MatCell mc : ec.subMatItems())
268 if (mc.componentId() == component_id)
277 helper.setItems(
this, env_component_getter_lambda, local_ids, queue);
279 helper.setItems(
this, mat_component_getter_lambda, local_ids, queue);
283 const bool do_lazy_evaluation =
true;
284 if (do_lazy_evaluation)
285 m_part_data->setNeedRecompute();
287 _recomputePartData();
293void ConstituentItemVectorImpl::
299 const Int32 component_id = m_component->id();
309 for (
EnvCell ec : all_env_cell.subEnvItems()) {
310 if (ec.componentId() == component_id) {
315 nb_impure.combine(1);
323 for (EnvCell env_cell : all_env_cell.subEnvItems()) {
324 for (MatCell mc : env_cell.subMatItems()) {
325 if (mc.componentId() == component_id) {
326 MatVarIndex idx = mc._varIndex();
327 if (idx.arrayIndex() == 0)
330 nb_impure.combine(1);
337 m_nb_pure = nb_pure.reducedValue();
338 m_nb_impure = nb_impure.reducedValue();
347void ConstituentItemVectorImpl::
353 const Int32 component_id = m_component->id();
363 if (ec.componentId() == component_id) {
377 for (
MatCell mc : env_cell.subMatItems()) {
378 if (mc.componentId() == component_id) {
391 m_nb_impure = nb_impure;
397void ConstituentItemVectorImpl::
401 auto mvi_pure_view = m_matvar_indexes.subView(0, m_nb_pure);
402 auto mvi_impure_view = m_matvar_indexes.subView(m_nb_pure, m_nb_impure);
403 m_part_data->_setFromMatVarIndexes(mvi_pure_view, mvi_impure_view);
412 return { m_component, m_matvar_indexes,
413 m_constituent_list->view(), m_items_local_id };
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Types and macros to manage enumerations of materials and media on accelerators.
#define RUNCOMMAND_MAT_ENUMERATE(ConstituentItemNameType, iter_name, env_or_mat_container,...)
Macro for iterating over a material or an environment.
Generic algorithm for partitioning a list.
Class to perform a 'sum' reduction.
Execution queue for an accelerator.
SmallSpan< const T > smallSpan() const
Immutable view of this array.
View over a list of cells with environment information.
Arcane cell with material and environment information.
__host__ __device__ CellEnvCellEnumerator subEnvItems() const
Enumerator over the environment cells of this cell.
View over a vector of entities of a component.
Index of a constituent entity in the list of constituent entities.
Helper for positioning vector entities.
Implementation of ComponentItemVector.
void _computeNbPureAndImpureLegacy(SmallSpan< const Int32 > local_ids)
Calculates the number of pure and impure cells without the accelerator API.
__host__ __device__ CellLocalId globalCellId() const
localId() of the global cell
__host__ __device__ bool null() const
Indicates if it is the null cell.
__host__ __device__ ConstituentItemIndex _constituentItemIndex() const
__host__ __device__ MatVarIndex _varIndex() const
Arcane cell of an environment.
Interface of a component (material or environment) of a mesh.
virtual Int32 id() const =0
Component identifier.
virtual bool isEnvironment() const =0
True if the component is an environment.
virtual AllEnvCellVectorView view(const CellGroup &cells)=0
View of environment cells corresponding to the group cells.
Represents a material in a multi-material cell.
Represents an index on material and environment variables.
constexpr __host__ __device__ Int32 arrayIndex() const
Returns the index of the value array in the list of variables.
Data of a part (pure or partial) of a constituent.
View of an array of elements of type T.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
eExecutionPolicy
Execution policy for a Runner.
Always enables tracing in Arcane parts concerning materials.
std::int32_t Int32
Signed integer type of 32 bits.