Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
DataSynchronizeBuffer.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* DataSynchronizeBuffer.h (C) 2000-2025 */
9/* */
10/* Implementation of a generic buffer for data synchronization. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_IMPL_DATASYNCHRONIZEBUFFER_H
14#define ARCANE_IMPL_DATASYNCHRONIZEBUFFER_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/MemoryView.h"
19#include "arcane/utils/Array.h"
20#include "arcane/utils/Array2.h"
21#include "arcane/utils/SmallArray.h"
22#include "arcane/utils/TraceAccessor.h"
23
24#include "arcane/impl/IDataSynchronizeBuffer.h"
25#include "arcane/utils/FixedArray.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29namespace Arcane
30{
31class IBufferCopier;
35class MemoryBuffer;
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
52class ARCANE_IMPL_EXPORT DataSynchronizeBufferBase
54{
59 {
60 public:
61
64
66 void setGlobalBuffer(MutableMemoryView v);
67
69 MutableMemoryView localBuffer(Int32 rank_index) const;
70
72 MutableMemoryView dataLocalBuffer(Int32 rank_index, Int32 data_index) const;
73
75 Int64 displacement(Int32 rank_index) const;
76
78 Int64 localBufferSize(Int32 rank_index) const;
79
81 Int64 totalSize() const { return m_total_size; }
82
84 ConstArrayView<Int32> localIds(Int32 index) const;
85
86 void checkValid() const
87 {
88 ARCANE_CHECK_POINTER(m_buffer_info);
89 }
90
91 void initialize(ConstArrayView<Int32> datatype_sizes, const DataSynchronizeBufferInfoList* buffer_info);
92
93 private:
94
109 const DataSynchronizeBufferInfoList* m_buffer_info = nullptr;
110 };
111
112 public:
113
114 Int32 nbRank() const final { return m_nb_rank; }
115 Int32 targetRank(Int32 index) const final;
116 bool hasGlobalBuffer() const final { return true; }
117
118 MutableMemoryView receiveBuffer(Int32 index) final { return m_ghost_buffer_info.localBuffer(index); }
119 MutableMemoryView sendBuffer(Int32 index) final { return m_share_buffer_info.localBuffer(index); }
120
121 Int64 receiveDisplacement(Int32 index) const final { return m_ghost_buffer_info.displacement(index); }
122 Int64 sendDisplacement(Int32 index) const final { return m_share_buffer_info.displacement(index); }
123
125 MutableMemoryView globalSendBuffer() final { return m_share_buffer_info.globalBuffer(); }
126
127 Int64 totalReceiveSize() const final { return m_ghost_buffer_info.totalSize(); }
128 Int64 totalSendSize() const final { return m_share_buffer_info.totalSize(); }
129
130 void barrier() final;
131
132 public:
133
135
136 public:
137
139 bool isCompareSynchronizedValues() const { return m_is_compare_sync_values; }
140
141 void setSynchronizeBuffer(Ref<MemoryBuffer> v)
142 {
143 m_memory = v;
144 }
145
157 virtual void prepareSynchronize(bool is_compare_sync) = 0;
158
159 protected:
160
161 void _allocateBuffers();
163 void _compute(ConstArrayView<Int32> datatype_sizes);
164
165 protected:
166
167 DataSynchronizeInfo* m_sync_info = nullptr;
174
175 protected:
176
177 Int32 m_nb_rank = 0;
178 bool m_is_compare_sync_values = false;
179
182
183 Ref<IBufferCopier> m_buffer_copier;
184};
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
192class ARCANE_IMPL_EXPORT SingleDataSynchronizeBuffer
193: public TraceAccessor
194, public DataSynchronizeBufferBase
195{
196 public:
197
198 SingleDataSynchronizeBuffer(ITraceMng* tm, DataSynchronizeInfo* sync_info, Ref<IBufferCopier> copier)
199 : TraceAccessor(tm)
200 , DataSynchronizeBufferBase(sync_info, copier)
201 {}
202
203 public:
204
205 void copyReceiveAsync(Int32 index) final;
206 void copySendAsync(Int32 index) final;
207
208 public:
209
210 void setDataView(MutableMemoryView v)
211 {
212 m_data_view = v;
214 }
217 void prepareSynchronize(bool is_compare_sync) override;
218
222 DataSynchronizeResult finalizeSynchronize();
223
224 private:
225
230};
231
232/*---------------------------------------------------------------------------*/
233/*---------------------------------------------------------------------------*/
234
238class ARCANE_IMPL_EXPORT MultiDataSynchronizeBuffer
239: public TraceAccessor
240, public DataSynchronizeBufferBase
241{
242
243 public:
244
245 MultiDataSynchronizeBuffer(ITraceMng* tm, DataSynchronizeInfo* sync_info,
246 Ref<IBufferCopier> copier)
247 : TraceAccessor(tm)
248 , DataSynchronizeBufferBase(sync_info, copier)
249 {}
250
251 public:
252
253 void copyReceiveAsync(Int32 rank_index) final;
254 void copySendAsync(Int32 rank_index) final;
255
256 public:
257
258 void setNbData(Int32 nb_data)
259 {
260 m_data_views.resize(nb_data);
261 m_datatype_sizes.resize(nb_data);
262 }
263 void setDataView(Int32 index, MutableMemoryView v)
264 {
265 m_data_views[index] = v;
266 m_datatype_sizes[index] = v.datatypeSize();
267 }
268
269 void prepareSynchronize(bool is_compare_sync) override;
270
271 private:
272
277};
278
279/*---------------------------------------------------------------------------*/
280/*---------------------------------------------------------------------------*/
281
282} // namespace Arcane
283
284/*---------------------------------------------------------------------------*/
285/*---------------------------------------------------------------------------*/
286
287#endif
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
Constant view of an array of type T.
Buffer for one synchronization element (send, receive, or comparison).
Int64 totalSize() const
Total size in bytes of the global buffer.
Int64 m_total_size
Total size (in bytes) of the buffer.
SmallArray< Int64 > m_local_buffer_size
Size (in bytes) of each local buffer.
MutableMemoryView m_memory_view
View onto the memory area of the buffer.
ConstArrayView< Int32 > m_datatype_sizes
Size (in bytes) of the type of each data item.
UniqueArray2< Int64 > m_displacements
Offset (in bytes) in globalBuffer() for each data item.
MutableMemoryView globalBuffer() const
Global buffer.
Base class for the IDataSynchronizeBuffer implementation.
Int64 receiveDisplacement(Int32 index) const final
Displacement (in bytes) from the start of receiveBuffer() for the index-th rank.
void _allocateBuffers()
Calculates and allocates the buffers necessary for sends and receives for 1D variable synchronization...
bool isCompareSynchronizedValues() const
Indicates whether values are compared before/after synchronization.
BufferInfo m_compare_sync_buffer_info
Buffer for testing if synchronization modified the values of ghost cells.
Int32 nbRank() const final
Number of ranks.
Int64 sendDisplacement(Int32 index) const final
Displacement (in bytes) from the start of sendBuffer() for the index-th rank.
BufferInfo m_share_buffer_info
Buffer for all data of shared entities used for sending.
MutableMemoryView globalReceiveBuffer() final
Receive buffer.
Int64 totalSendSize() const final
Total size to send in bytes.
MutableMemoryView globalSendBuffer() final
Send buffer.
MutableMemoryView receiveBuffer(Int32 index) final
Receive buffer for the index-th rank.
virtual void prepareSynchronize(bool is_compare_sync)=0
Prepares the synchronization.
Int64 totalReceiveSize() const final
Total size to receive in bytes.
void _compute(ConstArrayView< Int32 > datatype_sizes)
Computes the information for the synchronization.
BufferInfo m_ghost_buffer_info
Buffer for all data of ghost entities used for reception.
Ref< MemoryBuffer > m_memory
Buffer containing the concatenated data for sending and receiving.
MutableMemoryView sendBuffer(Int32 index) final
Send buffer for the index-th rank.
bool hasGlobalBuffer() const final
Indicates if the buffers are global.
Information for sending (share) or receiving (ghost) messages.
Information necessary to synchronize entities across a group.
Information about the result of a synchronization.
Interface for copying elements between two regions with indexing.
Generic buffer for data synchronization.
Management of a memory buffer.
SmallArray< Int32 > m_datatype_sizes
Array containing the sizes of the data types.
void prepareSynchronize(bool is_compare_sync) override
void copyReceiveAsync(Int32 rank_index) final
Copies into the data from the receive buffer of the index-th rank.
SmallArray< MutableMemoryView > m_data_views
View onto the data variables.
void copySendAsync(Int32 rank_index) final
Copies the data of the index-th rank into the send buffer.
Mutable view on a contiguous memory region containing fixed-size elements.
constexpr Int32 datatypeSize() const
Size of the associated data type (1 by default).
Reference to an instance.
MutableMemoryView m_data_view
View onto the data variable.
FixedArray< Int32, 1 > m_datatype_sizes
Array containing the sizes of the data types.
void copyReceiveAsync(Int32 index) final
Copies into the data from the receive buffer of the index-th rank.
void copySendAsync(Int32 index) final
Copies the data of the index-th rank into the send buffer.
MutableMemoryView dataView()
Memory area containing the values of the data to be synchronized.
1D data array with pre-allocated stack buffer.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
2D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
std::int32_t Int32
Signed integer type of 32 bits.