14#include "arcane/materials/AllCellToAllEnvCellConverter.h"
16#include "arcane/utils/NumArray.h"
18#include "arcane/core/IItemFamily.h"
20#include "arcane/core/ItemGroup.h"
21#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
23#include "arcane/materials/internal/AllCellToAllEnvCellContainer.h"
25#include "arcane/accelerator/Reduce.h"
27#include "arcane/accelerator/NumArrayViews.h"
47 m_mem_pool.setDebugName(
"AllCellToAllEnvCellMemPool");
48 m_envcell_container.setDebugName(
"AllCellToAllEnvCellCells");
72 Int32 m_current_max_nb_env = 0;
79Int32 AllCellToAllEnvCellContainer::Impl::
80computeMaxNbEnvPerCell()
87 Int32 nb_item = local_ids.size();
88 auto select_func = [=] ARCCORE_HOST_DEVICE(
Int32 i) ->
Int32 {
89 CellLocalId lid(local_ids[i]);
90 AllEnvCell all_env_cell = allenvcell_converter[lid];
93 reducer.applyMaxWithIndex(nb_item, select_func);
94 Int32 max_nb_env = reducer.reducedValue();
101void AllCellToAllEnvCellContainer::Impl::
113 AllEnvCell all_env_cell = all_env_cell_converter[cid];
114 Integer offset = cid * max_nb_env;
117 for (
Int32 x = 0; x < max_nb_env; ++x)
118 mem_pool[offset + x] = ComponentItemLocalId();
122 mem_pool[offset + i] = ComponentItemLocalId(ev._varIndex());
125 allcell_allenvcell[cid] = Span<ComponentItemLocalId>(mem_pool.
ptrAt(offset), nb_env);
128 allcell_allenvcell[cid] = {};
136void AllCellToAllEnvCellContainer::Impl::
139 IMeshMaterialMng* mm = m_material_mng;
140 RunQueue queue = mm->_internalApi()->runQueue();
141 m_size = mm->mesh()->cellFamily()->maxLocalId() + 1;
143 m_envcell_container.resize(m_size);
144 m_all_cell_to_all_env_cell.m_allcell_allenvcell_ptr = m_envcell_container.to1DSpan();
148 m_envcell_container.fill(Span<ComponentItemLocalId>(), &queue);
152 Int32 pool_size = m_current_max_nb_env * m_size;
153 m_mem_pool.resize(pool_size);
154 m_mem_pool.fill(ComponentItemLocalId(), &queue);
156 Span<ComponentItemLocalId> mem_pool_view(m_mem_pool.to1DSpan());
157 CellToAllEnvCellConverter all_env_cell_converter(mm);
159 auto mem_pool =
viewOut(command, m_mem_pool);
160 auto allcell_allenvcell =
viewOut(command, m_envcell_container);
161 const Int32 max_nb_env = m_current_max_nb_env;
164 AllEnvCell all_env_cell = all_env_cell_converter[CellLocalId(cid)];
165 Integer nb_env(all_env_cell.nbEnvironment());
168 Integer offset(cid * max_nb_env);
170 EnvCell ev = *ienvcell;
171 mem_pool[offset + i] = ComponentItemLocalId(ev._varIndex());
174 allcell_allenvcell[cid] = Span<ComponentItemLocalId>(mem_pool_view.ptrAt(offset), nb_env);
182void AllCellToAllEnvCellContainer::Impl::
186 if (m_size != m_material_mng->mesh()->allCells().itemFamily()->maxLocalId() + 1) {
194 if (current_max_nb_env != m_current_max_nb_env) {
196 m_current_max_nb_env = current_max_nb_env;
198 Int32 pool_size = CheckedConvert::multiply(m_current_max_nb_env, m_size);
199 m_mem_pool.resize(pool_size);
202 updateValues(m_material_mng, m_mem_pool.to1DSpan(), m_all_cell_to_all_env_cell.m_allcell_allenvcell_ptr, m_current_max_nb_env);
208void AllCellToAllEnvCellContainer::Impl::
211 m_envcell_container.resize(0);
212 m_all_cell_to_all_env_cell.m_allcell_allenvcell_ptr = {};
213 m_mem_pool.resize(0);
214 m_material_mng =
nullptr;
216 m_current_max_nb_env = 0;
225AllCellToAllEnvCellContainer::
226AllCellToAllEnvCellContainer(IMeshMaterialMng* mm)
234AllCellToAllEnvCellContainer::
235~AllCellToAllEnvCellContainer()
243void AllCellToAllEnvCellContainer::
255 return m_p->computeMaxNbEnvPerCell();
273 m_p->bruteForceUpdate();
291CellToAllEnvCellAccessor::
296 m_cell_allenvcell = c->view();
Types and macros to manage enumerations of entities on accelerators.
#define RUNCOMMAND_ENUMERATE(ItemTypeName, iter_name, item_group,...)
Macro to iterate over an accelerator on a group of entities.
Generic accelerator reduction algorithm.
Execution queue for an accelerator.
virtual CellGroup allCells()=0
Group of all cells.
Int32ConstArrayView itemsLocalId() const
List of local IDs of the entities in this group.
ItemGroupImpl * internal() const
Returns the group implementation.
Connectivity table of 'Cell' to its 'AllEnvCell' intended for use on accelerator.
Int32 computeMaxNbEnvPerCell() const
Method to provide the maximum number of environments present on a cell at time t.
void initialize()
Alternative creation function. It is necessary to wait until the data related to the materials is fin...
Connectivity table from 'Cell' to its 'AllEnvCell' intended for use on accelerator.
Arcane cell with material and environment information.
__host__ __device__ CellEnvCellEnumerator subEnvItems() const
Enumerator over the environment cells of this cell.
__host__ __device__ Int32 nbEnvironment() const
Number of environments present in the cell.
Conversion of 'Cell' to 'AllEnvCell'.
Arcane cell of an environment.
virtual RunQueue & runQueue() const =0
Default run queue.
virtual AllCellToAllEnvCellContainer * getAllCellToAllEnvCellContainer() const =0
Returns the "connectivity" table CellLocalId -> AllEnvCell intended to be used in a RUNCOMMAND_ENUMER...
Interface for the material and environment manager of a mesh.
virtual IMesh * mesh()=0
Associated mesh.
virtual IMeshMaterialMngInternal * _internalApi() const =0
Internal API for Arcane.
Multi-dimensional arrays for numerical types accessible on accelerators.
constexpr __host__ __device__ pointer ptrAt(SizeType index) const
Address of the index-th element.
View of an array of elements of type T.
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
Always enables tracing in Arcane parts concerning materials.
MatItemVariableScalarOutViewT< Cell, DataType > viewOut(CellMaterialVariableScalarRef< DataType > &var)
Write view.
Int32 Integer
Type representing an integer.
ExtentsV< Int32, DynExtent > MDDim1
Constant for a rank 1 dynamic array.
std::int32_t Int32
Signed integer type of 32 bits.