14#include "arcane/materials/internal/MeshMaterialVariableSynchronizer.h"
16#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/ValueConvert.h"
20#include "arcane/core/IMesh.h"
21#include "arcane/core/IVariableSynchronizer.h"
22#include "arcane/core/ItemGroup.h"
23#include "arcane/core/IParallelMng.h"
24#include "arcane/core/IItemFamily.h"
25#include "arcane/core/internal/IParallelMngInternal.h"
27#include "arcane/materials/IMeshMaterialMng.h"
28#include "arcane/materials/MatItemEnumerator.h"
29#include "arcane/materials/IMeshMaterialSynchronizeBuffer.h"
30#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
32#include "arcane/accelerator/core/RunQueue.h"
33#include "arcane/accelerator/Scan.h"
44MeshMaterialVariableSynchronizer::
46 IVariableSynchronizer* var_syncer,
48: TraceAccessor(material_mng->traceMng())
49, m_material_mng(material_mng)
50, m_variable_synchronizer(var_syncer)
54 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_MATERIALSYNCHRONIZER_ACCELERATOR_MODE",
true))
55 m_use_accelerator_mode = v.value();
68 return m_variable_synchronizer;
75sharedItems(
Int32 index)
77 return m_shared_items[index];
84ghostItems(
Int32 index)
86 return m_ghost_items[index];
95void MeshMaterialVariableSynchronizer::
107 if (view.
size() == 0)
111 if (m_use_accelerator_mode == 1)
112 use_accelerator =
true;
113 if (m_use_accelerator_mode == 0)
114 use_accelerator =
false;
128void MeshMaterialVariableSynchronizer::
136 items.
add(env_cell._varIndex());
138 for (
MatCell mat_cell : env_cell.subMatItems()) {
139 items.
add(mat_cell._varIndex());
155void MeshMaterialVariableSynchronizer::
164 indexes.
resize(nb_item + 1);
167 Accelerator::ScannerSumOperator<Int32> op;
169 auto getter = [=] ARCCORE_HOST_DEVICE(
Int32 index) ->
Int32 {
170 if (index == nb_item)
177 n += env_cell.nbSubItem();
188 auto setter = [=] ARCCORE_HOST_DEVICE(
Int32 index,
Int32 value) {
189 out_indexes[index] = value;
190 if (index == nb_item)
191 in_host_total_storage[0] = value;
193 scanner.applyWithIndexExclusive(nb_item + 1, 0, getter, setter, op);
194 Int32 total = host_total_storage[0];
204 auto [index] = iter();
206 Int32 pos = in_indexes[index];
208 out_mat_var_indexes[pos] = env_cell._varIndex();
211 for (
MatCell mat_cell : env_cell.subMatItems()) {
212 out_mat_var_indexes[pos] = mat_cell._varIndex();
219 out_mat_var_indexes[pos] =
MatVarIndex(0, view.localId(index));
227void MeshMaterialVariableSynchronizer::
230 Int64 ts = m_material_mng->timestamp();
231 if (m_timestamp != ts)
239void MeshMaterialVariableSynchronizer::
257 m_common_buffer->setNbRank(nb_rank);
259 m_shared_items.resize(nb_rank);
260 m_ghost_items.resize(nb_rank);
262 RunQueue queue = m_material_mng->_internalApi()->runQueue();
269 for (
Int32 i = 0; i < nb_rank; ++i) {
277 for (
Integer i = 0; i < nb_rank; ++i) {
285 info(4) <<
"SIZE SHARED FOR rank=" << ranks[i] <<
" n=" << items.
size();
294 info(4) <<
"SIZE GHOST FOR rank=" << ranks[i] <<
" n=" << items.
size();
302void MeshMaterialVariableSynchronizer::
305 IParallelMng* pm = m_variable_synchronizer->parallelMng();
307 m_buffer_memory_ressource = eMemoryRessource::Device;
308 info() <<
"MeshMaterialVariableSynchronizer: Using device memory for buffer";
310 m_common_buffer = impl::makeOneBufferMeshMaterialSynchronizeBufferRef(m_buffer_memory_ressource);
Memory and allocator management functions.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
1D loop on accelerator with additional arguments.
Integer size() const
Number of elements in the vector.
Exclusive or inclusive scan algorithms on accelerators.
Execution queue for an accelerator.
MemoryAllocationOptions allocationOptions() const
Allocation options associated with this queue.
bool isAcceleratorPolicy() const
Indicates if the instance is associated with an accelerator.
Base class for 1D data vectors.
void resize(Int64 s)
Changes the number of elements in the array to s.
void clear()
Removes the elements from the array.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface of an entity family.
virtual ItemGroup allItems() const =0
Group of all entities.
virtual ItemVectorView view(Int32ConstArrayView local_ids)=0
View on the entities.
virtual bool isAcceleratorAware() const =0
Indicates if the implementation handles accelerators.
Interface of the parallelism manager for a subdomain.
virtual IParallelMngInternal * _internalApi()=0
Internal Arcane API.
virtual bool isParallel() const =0
Returns true if the execution is parallel.
Interface of a variable synchronization service.
virtual Int32ConstArrayView ghostItems(Int32 index)=0
List of local IDs of ghost entities with a subdomain.
virtual Int32ConstArrayView communicatingRanks()=0
Ranks of subdomains with which communication occurs.
virtual const ItemGroup & itemGroup()=0
Entity group used for synchronization.
virtual IParallelMng * parallelMng()=0
Associated parallel manager.
virtual Int32ConstArrayView sharedItems(Int32 index)=0
List of local IDs of entities shared with a subdomain.
IItemFamily * itemFamily() const
Entity family to which this group belongs (0 for the null group).
View over a list of cells with environment information.
constexpr __host__ __device__ Integer size() const
Number of elements.
Arcane cell with material and environment information.
__host__ __device__ CellEnvCellEnumerator subEnvItems() const
Enumerator over the environment cells of this cell.
Arcane cell of an environment.
Interface for the material and environment manager of a mesh.
Represents a material in a multi-material cell.
Represents an index on material and environment variables.
void _fillCellsAccelerator(Array< MatVarIndex > &items, AllEnvCellVectorView view, RunQueue &queue)
Fills items with the list of all MatVarIndex from the cells of view.
void _fillCells(Array< MatVarIndex > &items, AllEnvCellVectorView view, RunQueue &queue)
Fills items with the list of all MatVarIndex from the cells of view.
void recompute() override
Recalculates synchronization information.
void _fillCellsSequential(Array< MatVarIndex > &items, AllEnvCellVectorView view)
Fills items with the list of all MatVarIndex from the cells of view.
Options to configure allocations.
Multi-dimensional arrays for numerical types accessible on accelerators.
View of an array of elements of type T.
View of an array of elements of type T.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
ItemVectorViewT< Cell > CellVectorView
View over a vector of cells.
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
Always enables tracing in Arcane parts concerning materials.
MatVarSpace
Definition space for a material variable.
@ MaterialAndEnvironment
Variable having values on environments and materials.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
std::int32_t Int32
Signed integer type of 32 bits.