14#include "arcane/materials/IMeshMaterialSynchronizeBuffer.h"
16#include "arcane/utils/UniqueArray.h"
17#include "arcane/utils/PlatformUtils.h"
29class MultiBufferMeshMaterialSynchronizeBuffer
37 : m_send_buffer(allocator)
38 , m_receive_buffer(allocator)
46 m_send_buffer.clear();
47 m_receive_buffer.clear();
49 Int32 m_send_size = 0;
50 Int32 m_receive_size = 0;
57 explicit MultiBufferMeshMaterialSynchronizeBuffer(
IMemoryAllocator* allocator)
58 : m_default_buffer_info(allocator)
66 m_buffer_infos.resize(nb_rank, m_default_buffer_info);
67 for (
auto& x : m_buffer_infos)
72 return m_buffer_infos[index].m_send_buffer;
76 m_buffer_infos[index].m_send_size = new_size;
80 return m_buffer_infos[index].m_receive_buffer;
84 m_buffer_infos[index].m_receive_size = new_size;
89 for (
auto& x : m_buffer_infos) {
90 x.m_send_buffer.resize(x.m_send_size);
91 x.m_receive_buffer.resize(x.m_receive_size);
92 m_total_size += x.m_send_size + x.m_receive_size;
100 Int64 m_total_size = 0;
101 BufferInfo m_default_buffer_info;
108class OneBufferMeshMaterialSynchronizeBuffer
125 return full_buffer.
subspan(m_send_index, m_send_size);
129 return full_buffer.
subspan(m_receive_index, m_receive_size);
132 Int32 m_send_size = 0;
133 Int32 m_receive_size = 0;
134 Int64 m_send_index = 0;
135 Int64 m_receive_index = 0;
140 explicit OneBufferMeshMaterialSynchronizeBuffer(
IMemoryAllocator* allocator)
141 : m_buffer(allocator)
150 m_buffer_infos.resize(nb_rank);
151 for (
auto& x : m_buffer_infos)
156 return m_buffer_infos[index].sendBuffer(m_buffer);
160 m_buffer_infos[index].m_send_size = new_size;
164 return m_buffer_infos[index].receiveBuffer(m_buffer);
168 m_buffer_infos[index].m_receive_size = new_size;
172 Int64 total_send_size = 0;
173 Int64 total_receive_size = 0;
174 for (
auto& x : m_buffer_infos) {
175 total_send_size += x.m_send_size;
176 total_receive_size += x.m_receive_size;
178 m_buffer.resize(total_send_size + total_receive_size);
179 Int64 send_index = 0;
180 Int64 receive_index = total_send_size;
181 for (
auto& x : m_buffer_infos) {
182 x.m_send_index = send_index;
183 x.m_receive_index = receive_index;
184 send_index += x.m_send_size;
185 receive_index += x.m_receive_size;
203 makeMultiBufferMeshMaterialSynchronizeBufferRef(
eMemoryRessource memory_ressource)
210 extern "C++" ARCANE_MATERIALS_EXPORT Ref<IMeshMaterialSynchronizeBuffer>
211 makeMultiBufferMeshMaterialSynchronizeBufferRef()
213 return makeMultiBufferMeshMaterialSynchronizeBufferRef(eMemoryRessource::Host);
217 makeOneBufferMeshMaterialSynchronizeBufferRef(
eMemoryRessource memory_ressource)
220 auto* v =
new OneBufferMeshMaterialSynchronizeBuffer(a);
Memory and allocator management functions.
Interface for a memory allocator.
Interface for buffers for material variable synchronization.
void allocate() override
Allocates memory for the buffers.
void setReceiveBufferSize(Int32 index, Int32 new_size) override
Sets the number of elements for the i-th receive buffer.
Span< Byte > sendBuffer(Int32 index) override
Send buffer for the i-th buffer.
Int32 nbRank() const override
Number of ranks.
void setNbRank(Int32 nb_rank) override
Sets the number of ranks. This invalidates the send and receive buffers.
Int64 totalSize() const override
Total size allocated for the buffers.
void setSendBufferSize(Int32 index, Int32 new_size) override
Sets the number of elements for the i-th send buffer.
Span< Byte > receiveBuffer(Int32 index) override
Send buffer for the i-th buffer.
Span< Byte > receiveBuffer(Int32 index) override
Send buffer for the i-th buffer.
Int64 totalSize() const override
Total size allocated for the buffers.
void allocate() override
Allocates memory for the buffers.
Span< Byte > sendBuffer(Int32 index) override
Send buffer for the i-th buffer.
void setReceiveBufferSize(Int32 index, Int32 new_size) override
Sets the number of elements for the i-th receive buffer.
void setNbRank(Int32 nb_rank) override
Sets the number of ranks. This invalidates the send and receive buffers.
Int32 nbRank() const override
Number of ranks.
void setSendBufferSize(Int32 index, Int32 new_size) override
Sets the number of elements for the i-th send buffer.
Reference to an instance.
View of an array of elements of type T.
constexpr __host__ __device__ Span< T, DynExtent > subspan(Int64 abegin, Int64 asize) const
Sub-view starting from element abegin and containing asize elements.
1D data vector with value semantics (STL style).
Always enables tracing in Arcane parts concerning materials.
class ARCANE_MATERIALS_EXPORT(64) SimdMatVarIndex
SIMD indexer on a component.
IMemoryAllocator * getAllocator(eMemoryResource mem_resource)
Default allocator for the resource mem_resource.
std::int64_t Int64
Signed integer type of 64 bits.
Arcane::eMemoryResource eMemoryRessource
Typedef for the historical Arcane version (with 2's').
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.