14#include "arcane/utils/FatalErrorException.h"
15#include "arcane/utils/NotSupportedException.h"
16#include "arcane/utils/CheckedConvert.h"
17#include "arcane/utils/MemoryView.h"
19#include "arcane/parallel/mpi/MpiParallelMng.h"
20#include "arcane/parallel/mpi/MpiTimeInterval.h"
21#include "arcane/parallel/mpi/IVariableSynchronizerMpiCommunicator.h"
22#include "arcane/parallel/IStat.h"
24#include "arcane/impl/IDataSynchronizeBuffer.h"
25#include "arcane/impl/IDataSynchronizeImplementation.h"
26#include "arcane/impl/DataSynchronizeInfo.h"
28#include "arccore/message_passing_mpi/internal/MpiAdapter.h"
50class MpiNeighborVariableSynchronizerDispatcher
56 explicit MpiNeighborVariableSynchronizerDispatcher(
Factory* f);
60 void compute()
override;
83 : m_mpi_parallel_mng(mpi_pm)
84 , m_synchronizer_communicator(synchronizer_communicator)
89 auto* x =
new MpiNeighborVariableSynchronizerDispatcher(
this);
103arcaneCreateMpiNeighborVariableSynchronizerFactory(
MpiParallelMng* mpi_pm,
113MpiNeighborVariableSynchronizerDispatcher::
114MpiNeighborVariableSynchronizerDispatcher(Factory* f)
115: m_mpi_parallel_mng(f->m_mpi_parallel_mng)
116, m_synchronizer_communicator(f->m_synchronizer_communicator)
123void MpiNeighborVariableSynchronizerDispatcher::
124beginSynchronize(IDataSynchronizeBuffer* buf)
132 double send_copy_time = 0.0;
134 MpiTimeInterval tit(&send_copy_time);
139 Int64 total_share_size = buf->totalSendSize();
140 m_mpi_parallel_mng->stat()->add(
"SyncSendCopy", send_copy_time, total_share_size);
146void MpiNeighborVariableSynchronizerDispatcher::
147endSynchronize(IDataSynchronizeBuffer* buf)
149 const Int32 nb_message = buf->nbRank();
151 auto* sync_communicator = m_synchronizer_communicator.get();
154 MPI_Comm communicator = sync_communicator->communicator();
155 if (communicator == MPI_COMM_NULL)
158 MpiParallelMng* pm = m_mpi_parallel_mng;
159 const MPI_Datatype mpi_dt = MP::Mpi::MpiBuiltIn::datatype(
Byte());
161 double copy_time = 0.0;
162 double wait_time = 0.0;
164 if (!buf->hasGlobalBuffer())
165 ARCANE_THROW(NotSupportedException,
"Can not use MPI_Neighbor_alltoallv when hasGlobalBufer() is false");
167 for (
Integer i = 0; i < nb_message; ++i) {
168 Int32 nb_send = CheckedConvert::toInt32(buf->sendBuffer(i).bytes().size());
169 Int32 nb_receive = CheckedConvert::toInt32(buf->receiveBuffer(i).bytes().size());
170 Int32 send_displacement = CheckedConvert::toInt32(buf->sendDisplacement(i));
171 Int32 receive_displacement = CheckedConvert::toInt32(buf->receiveDisplacement(i));
173 m_mpi_send_counts[i] = nb_send;
174 m_mpi_receive_counts[i] = nb_receive;
175 m_mpi_send_displacements[i] = send_displacement;
176 m_mpi_receive_displacements[i] = receive_displacement;
180 MpiTimeInterval tit(&wait_time);
181 auto send_buf = buf->globalSendBuffer();
182 auto receive_buf = buf->globalReceiveBuffer();
183 MPI_Neighbor_alltoallv(send_buf.data(), m_mpi_send_counts.data(), m_mpi_send_displacements.data(), mpi_dt,
184 receive_buf.data(), m_mpi_receive_counts.data(), m_mpi_receive_displacements.data(), mpi_dt,
190 MpiTimeInterval tit(©_time);
191 buf->copyAllReceive();
194 Int64 total_ghost_size = buf->totalReceiveSize();
195 Int64 total_share_size = buf->totalSendSize();
196 Int64 total_size = total_ghost_size + total_share_size;
197 pm->stat()->add(
"SyncCopy", copy_time, total_ghost_size);
198 pm->stat()->add(
"SyncWait", wait_time, total_size);
204void MpiNeighborVariableSynchronizerDispatcher::
207 DataSynchronizeInfo* sync_info = _syncInfo();
210 auto* sync_communicator = m_synchronizer_communicator.get();
213 const Int32 nb_message = sync_info->size();
218 Int32 size = nb_message;
222 m_mpi_send_counts.resize(size);
223 m_mpi_receive_counts.resize(size);
224 m_mpi_send_displacements.resize(size);
225 m_mpi_receive_displacements.resize(size);
227 m_mpi_send_counts.fill(0);
228 m_mpi_receive_counts.fill(0);
229 m_mpi_send_displacements.fill(0);
230 m_mpi_receive_displacements.fill(0);
#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_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Generic buffer for data synchronization.
Interface for a generic dispatcher factory.
Parallelism manager using MPI.
Reference to an instance.
1D 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.
Int32 Integer
Type representing an integer.
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.