14#include "arcane/utils/Array.h"
15#include "arcane/utils/ITraceMng.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/ArgumentException.h"
18#include "arcane/utils/FatalErrorException.h"
19#include "arcane/utils/CheckedConvert.h"
21#include "arcane/core/IParallelMng.h"
22#include "arcane/core/Timer.h"
23#include "arcane/core/ISerializer.h"
24#include "arcane/core/internal/SerializeMessage.h"
26#include "arcane/impl/TransferValuesParallelOperation.h"
28#include "arccore/message_passing/PointToPointSerializerMng.h"
37using namespace Arccore::MessagePassing;
42TransferValuesParallelOperation::
51TransferValuesParallelOperation::
52~TransferValuesParallelOperation()
62 return m_parallel_mng;
68void TransferValuesParallelOperation::
77void TransferValuesParallelOperation::
80 m_send32_values.add(send_values);
81 m_recv32_values.add(recv_values);
87void TransferValuesParallelOperation::
90 m_send64_values.add(send_values);
91 m_recv64_values.add(recv_values);
97void TransferValuesParallelOperation::
100 m_send_real_values.add(send_values);
101 m_recv_real_values.add(recv_values);
107template <
typename U>
void TransferValuesParallelOperation::
115 for (
Integer z = 0, zs = arrays.size(); z < zs; ++z) {
117 for (
Integer zz = 0; zz < nb; ++zz)
118 tmp_values[zz] = v[z_indexes[zz]];
126template <
typename U>
void TransferValuesParallelOperation::
131 for (
Integer z = 0, zs = arrays.size(); z < zs; ++z) {
133 for (
Integer zz = 0; zz < nb; ++zz)
134 arrays[z].
add(tmp_values[zz]);
141void TransferValuesParallelOperation::
144 String func_name =
"TransfertValuesParallelOperation::transferValues()";
155 Int32 nb_send = m_ranks.size();
157 Int64 nb_send_int32 = m_send32_values.size();
158 Int64 nb_send_int64 = m_send64_values.size();
159 Int64 nb_send_real = m_send_real_values.size();
161 if (nb_send_int32 != m_recv32_values.size())
162 throw ArgumentException(func_name,
"Int32 send_array and Int32 recv_array do not have the same size");
163 if (nb_send_int64 != m_recv64_values.size())
164 throw ArgumentException(func_name,
"Int64 send_array and Int64 recv_array do not have the same size");
165 if (nb_send_real != m_recv_real_values.size())
166 throw ArgumentException(func_name,
"Real send_array and Real recv_array do not have the same size");
168 for (
Int64 i = 0; i < nb_send_int32; ++i) {
169 if (m_send32_values[i].size() != nb_send)
170 throw ArgumentException(func_name,
"Int32 array and ranks do not have the same size");
172 for (
Int64 i = 0; i < nb_send_int64; ++i) {
173 if (m_send64_values[i].size() != nb_send)
174 throw ArgumentException(func_name,
"Int64 array and ranks do not have the same size");
176 for (
Int64 i = 0; i < nb_send_real; ++i) {
177 if (m_send_real_values[i].size() != nb_send)
178 throw ArgumentException(func_name,
"Real array and ranks do not have the same size");
181 typedef std::map<Int32, SharedArray<Int32>> SubDomainIndexMap;
182 SubDomainIndexMap sub_domain_list;
184 for (
Integer i = 0; i < nb_send; ++i) {
185 Int32 sd = m_ranks[i];
186 if (sd == NULL_SUB_DOMAIN_ID)
192 for (
Integer i = 0; i < nb_send; ++i) {
193 Int32 sd = m_ranks[i];
199 for (SubDomainIndexMap::const_iterator b = sub_domain_list.begin();
200 b != sub_domain_list.end(); ++b) {
202 Int64 n = b->second.size();
203 sub_domain_nb_to_send.
add(my_rank);
204 sub_domain_nb_to_send.
add(sd);
205 sub_domain_nb_to_send.
add(n);
213 for (
Int64 i = 0, n = total_sub_domain_nb_to_send.
size(); i < n; i += 3) {
214 Int32 rank_send = CheckedConvert::toInt32(total_sub_domain_nb_to_send[i]);
215 Int32 rank_recv = CheckedConvert::toInt32(total_sub_domain_nb_to_send[i + 1]);
217 if (rank_send == rank_recv)
219 if (rank_recv == my_rank) {
221 trace->
info() <<
" ADD RECV MESSAGE recv=" << rank_recv <<
" send=" << rank_send;
223 else if (rank_send == my_rank) {
224 trace->
info() <<
" ADD SEND MESSAGE recv=" << rank_recv <<
" send=" << rank_send;
228 s->
setMode(ISerializer::ModeReserve);
231 trace->
info() <<
" ADD SIZE int32=" << nb * nb_send_int32
232 <<
" int64=" << nb * nb_send_int64
233 <<
" real=" << nb * nb_send_real;
234 s->reserveInteger(1);
235 for (
Integer k = 0; k < nb; ++k) {
244 _putArray(s, z_indexes, m_send32_values, tmp_values_int32);
245 _putArray(s, z_indexes, m_send64_values, tmp_values_int64);
246 _putArray(s, z_indexes, m_send_real_values, tmp_values_real);
252 trace->
info() <<
" GET RECV MESSAGE recv=" << sm->destination();
256 trace->
info() <<
" GET SIZE nb=" << nb;
258 _getArray(s, nb, m_recv32_values, tmp_values_int32);
259 _getArray(s, nb, m_recv64_values, tmp_values_int64);
260 _getArray(s, nb, m_recv_real_values, tmp_values_real);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Integer size() const
Number of elements in the vector.
Exception when an argument is invalid.
Base class for 1D data vectors.
void resize(Int64 s)
Changes the number of elements in the array to s.
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 the parallelism manager for a subdomain.
virtual ITraceMng * traceMng() const =0
Trace manager.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual ITimeStats * timeStats() const =0
Associated statistics manager (can be null).
virtual void allGatherVariable(ConstArrayView< char > send_buf, Array< char > &recv_buf)=0
Performs an all-gather operation across all processors.
virtual IMessagePassingMng * messagePassingMng() const =0
Associated Arccore message passing manager.
virtual bool isParallel() const =0
Returns true if the execution is parallel.
virtual Integer getInteger()=0
Retrieve a size.
@ ModePut
The serializer expects reserve().
@ ModeGet
The serializer expects get().
virtual void allocateBuffer()=0
Allocates the serializer memory.
virtual void putInteger(Integer value)=0
Add the integer value.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
virtual void setMode(eMode new_mode)=0
Sets the current mode.
virtual TraceMessage info()=0
Stream for an information message.
Interface for a serialization message between IMessagePassingMng.
Point-to-point communications using 'ISerializer'.
Integer waitMessages(eWaitType wt, std::function< void(ISerializeMessage *)> functor)
Waits for the messages to finish execution.
Ref< ISerializeMessage > addSendMessage(MessageRank receiver_rank)
Creates a sending serialization message.
Ref< ISerializeMessage > addReceiveMessage(MessageRank sender_rank)
Creates a receiving serialization message.
Exception when a function is not implemented.
1D vector of data with reference semantics.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
View of an array of elements of type T.
Unicode character string.
Positions the phase of the currently executing action.
1D data vector with value semantics (STL style).
void add(ArrayView< T > lhs, ConstArrayView< T > copy_array)
Adds the array copy_array to the instance.
-- 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.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
@ Real
8-bit integer data type
@ Int32
32-bit integer data type
@ Int64
64-bit integer data type
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
ConstArrayView< Integer > IntegerConstArrayView
C equivalent of a 1D array of integers.
std::int32_t Int32
Signed integer type of 32 bits.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.