14#include "arcane/impl/internal/IDataSynchronizeDispatcher.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/MemoryView.h"
19#include "arcane/utils/ValueConvert.h"
20#include "arcane/utils/ITraceMng.h"
21#include "arcane/utils/internal/MemoryBuffer.h"
23#include "arcane/core/ParallelMngUtils.h"
24#include "arcane/core/IParallelExchanger.h"
25#include "arcane/core/ISerializeMessage.h"
26#include "arcane/core/ISerializer.h"
27#include "arcane/core/IParallelMng.h"
28#include "arcane/core/IData.h"
29#include "arcane/core/internal/IDataInternal.h"
31#include "arcane/impl/DataSynchronizeInfo.h"
32#include "arcane/impl/internal/DataSynchronizeBuffer.h"
46 void* data = bytes.data();
47 Int32 size = bytes.smallView().size();
48 return { size,
reinterpret_cast<Byte*
>(data) };
58class DataSynchronizeDispatcherBase
63 ~DataSynchronizeDispatcherBase();
68 Runner* m_runner =
nullptr;
80DataSynchronizeDispatcherBase::
82: m_parallel_mng(bi.parallelMng())
83, m_sync_info(bi.synchronizeInfo())
84, m_synchronize_implementation(bi.synchronizeImplementation())
91DataSynchronizeDispatcherBase::
92~DataSynchronizeDispatcherBase()
106 m_synchronize_implementation->compute();
118class ARCANE_IMPL_EXPORT DataSynchronizeDispatcher
120,
public DataSynchronizeDispatcherBase
128 : DataSynchronizeDispatcherBase(bi)
144 bool m_is_in_sync =
false;
145 bool m_is_empty_sync =
false;
162 ARCANE_FATAL(
"_beginSynchronize() has already been called");
165 m_is_empty_sync = (mem_view.
bytes().size() == 0);
170 m_synchronize_implementation->beginSynchronize(&
m_sync_buffer);
180 ARCANE_FATAL(
"No pending synchronize(). You need to call beginSynchronize() before");
182 if (!m_is_empty_sync) {
183 m_synchronize_implementation->endSynchronize(&
m_sync_buffer);
186 m_is_in_sync =
false;
211class ARCANE_IMPL_EXPORT DataSynchronizeMultiDispatcher
217 : m_parallel_mng(bi.parallelMng())
218 , m_sync_info(bi.synchronizeInfo())
235void DataSynchronizeMultiDispatcher::
236synchronize(ConstArrayView<IVariable*> vars)
239 Integer nb_rank = m_sync_info->size();
241 for (
Integer i = 0; i < nb_rank; ++i) {
242 Int32 rank = m_sync_info->targetRank(i);
243 exchanger->addSender(rank);
244 recv_ranks[i] = rank;
246 exchanger->initializeCommunicationsMessages(recv_ranks);
247 for (
Integer i = 0; i < nb_rank; ++i) {
248 ISerializeMessage* msg = exchanger->messageToSend(i);
249 ISerializer* sbuf = msg->serializer();
251 sbuf->setMode(ISerializer::ModeReserve);
252 for (IVariable* var : vars) {
253 var->serialize(sbuf, share_ids,
nullptr);
255 sbuf->allocateBuffer();
257 for (IVariable* var : vars) {
258 var->serialize(sbuf, share_ids,
nullptr);
261 exchanger->processExchange();
262 for (
Integer i = 0; i < nb_rank; ++i) {
263 ISerializeMessage* msg = exchanger->messageToReceive(i);
264 ISerializer* sbuf = msg->serializer();
267 for (IVariable* var : vars) {
268 var->serialize(sbuf, ghost_ids,
nullptr);
284class ARCANE_IMPL_EXPORT DataSynchronizeMultiDispatcherV2
285:
public DataSynchronizeDispatcherBase
291 : DataSynchronizeDispatcherBase(bi)
292 , m_sync_buffer(bi.parallelMng()->
traceMng(), m_sync_info.get(), bi.bufferCopier())
308void DataSynchronizeMultiDispatcherV2::
309synchronize(ConstArrayView<IVariable*> vars)
311 const Int32 nb_var = vars.size();
312 m_sync_buffer.setNbData(nb_var);
317 for (IVariable* var : vars) {
318 INumericDataInternal* numapi = var->data()->_commonInternal()->numericData();
320 ARCANE_FATAL(
"Variable '{0}' can not be synchronized because it is not a numeric data", var->name());
321 MutableMemoryView mem_view = numapi->memoryView();
322 m_sync_buffer.setDataView(index, mem_view);
328 bool is_compare_sync =
false;
329 m_sync_buffer.prepareSynchronize(is_compare_sync);
331 m_synchronize_implementation->beginSynchronize(&m_sync_buffer);
332 m_synchronize_implementation->endSynchronize(&m_sync_buffer);
346class SimpleDataSynchronizeImplementation
352 explicit SimpleDataSynchronizeImplementation(
Factory* f);
356 void compute()
override {}
380 auto* x =
new SimpleDataSynchronizeImplementation(
this);
392SimpleDataSynchronizeImplementation::
393SimpleDataSynchronizeImplementation(
Factory* f)
394: m_parallel_mng(f->m_parallel_mng)
402arcaneCreateSimpleVariableSynchronizerFactory(
IParallelMng* pm)
411void SimpleDataSynchronizeImplementation::
412beginSynchronize(IDataSynchronizeBuffer* vs_buf)
415 IParallelMng* pm = m_parallel_mng;
417 const bool use_blocking_send =
false;
418 Int32 nb_message = vs_buf->nbRank();
425 for (
Integer i = 0; i < nb_message; ++i) {
426 Int32 target_rank = vs_buf->targetRank(i);
427 auto buf = _toLegacySmallView(vs_buf->receiveBuffer(i));
429 Parallel::Request rval = pm->recv(buf, target_rank,
false);
430 m_all_requests.add(rval);
434 vs_buf->copyAllSend();
437 for (
Integer i = 0; i < nb_message; ++i) {
438 Int32 target_rank = vs_buf->targetRank(i);
439 auto buf = _toLegacySmallView(vs_buf->sendBuffer(i));
446 Parallel::Request rval = pm->send(buf, target_rank, use_blocking_send);
447 if (!use_blocking_send)
448 m_all_requests.add(rval);
456void SimpleDataSynchronizeImplementation::
457endSynchronize(IDataSynchronizeBuffer* vs_buf)
459 IParallelMng* pm = m_parallel_mng;
467 m_all_requests.clear();
470 vs_buf->copyAllReceive();
479IDataSynchronizeMultiDispatcher* IDataSynchronizeMultiDispatcher::
480create(
const DataSynchronizeDispatcherBuildInfo& bi)
486 return new DataSynchronizeMultiDispatcher(bi);
487 return new DataSynchronizeMultiDispatcherV2(bi);
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to define methods managing counters of references.
Execution manager for accelerator.
Modifiable view of an array of type T.
Constant view of an array of type T.
static std::optional< Int32 > tryParseFromEnvironment(StringView s, bool throw_if_invalid)
void _compute()
Notifies the implementation that the synchronization information has changed.
Info to build a DataSynchronizeDispatcher.
Manages synchronization for a data item.
DataSynchronizeResult endSynchronize() override
Ends the synchronization.
void setSynchronizeBuffer(Ref< MemoryBuffer > buffer) override
Positions the synchronization buffer.
void compute() override
Recalculates the necessary information after an update to the DataSynchronizeInfo.
SingleDataSynchronizeBuffer m_sync_buffer
Manages send and receive buffers for synchronization.
void beginSynchronize(INumericDataInternal *data, bool is_compare_sync) override
Starts the execution for synchronization for the data data.
void compute() override
Recalculates the necessary information after an update to the DataSynchronizeInfo.
void setSynchronizeBuffer(Ref< MemoryBuffer > buffer) override
Positions the synchronization buffer.
void compute() override
Recalculates the necessary information after an update to the DataSynchronizeInfo.
void setSynchronizeBuffer(Ref< MemoryBuffer >) override
Positions the synchronization buffer.
Information about the result of a synchronization.
Generic buffer for data synchronization.
Interface to manage the synchronization of a data item.
Interface for a generic dispatcher factory.
Interface for synchronizing a list of variables.
Interface for an 'IData' of a numeric type.
virtual MutableMemoryView memoryView()=0
Memory view of the data.
Interface of the parallelism manager for a subdomain.
virtual ITraceMng * traceMng() const =0
Trace manager.
virtual void waitAllRequests(ArrayView< Request > rvalues)=0
Blocks while waiting for the rvalues requests to complete.
@ ModePut
The serializer expects reserve().
@ ModeGet
The serializer expects get().
IDataSynchronizeBuffer implementation for multiple data items.
Mutable view on a contiguous memory region containing fixed-size elements.
constexpr SpanType bytes() const
View in byte form.
Reference to an instance.
Thread-safe implementation of a reference counter.
IDataSynchronizeBuffer implementation for a single data item.
View of an array of elements of type T.
1D data vector with value semantics (STL style).
Ref< IParallelExchanger > createExchangerRef(IParallelMng *pm)
Returns an interface to transfer messages between ranks.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
unsigned char Byte
Type of a byte.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.