Commit 0bb6e116 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#772 Wrappers/Mpi: introduce an AllReduce() that avoids allocation of a new vector.

parent 587ed9cf
......@@ -194,6 +194,25 @@ namespace HappyHeart
std::vector<bool> AllReduce(const std::vector<bool>& sent_data, MpiNS::Op mpi_operation) const;
/*!
* \brief The actual implementation of the Allreduce() method.
*
* This implementation will be used for the generic case as well as the very specific case
* of booleans, which are handled by a hand-made container.
*
*
* \tparam ContainerT Either std::vector<T> or BoolArray expected (underlying type obtained through ContainerT::value_type).
*
* \param[in] sent_data Data sent by the current processor.
* \param[in] mpi_operation The MPI operation used during the reduction.
* \param[out] gathered_data gathered by the current processor.
*/
template<class ContainerT>
void AllReduce(const ContainerT& sent_data,
ContainerT& gathered_data,
MpiNS::Op mpi_operation) const;
//! Reduce operation, which target is the root processor.
template<typename T>
std::vector<T> ReduceOnRootProcessor(const std::vector<T>& sent_data, MpiNS::Op mpi_operation) const;
......@@ -258,23 +277,6 @@ namespace HappyHeart
ContainerT& gathered_data) const;
/*!
* \brief The actual implementation of the Allreduce() method.
*
* This implementation will be used for the generic case as well as the very specific case
* of booleans, which are handled by a hand-made container.
*
*
* \tparam ContainerT Either std::vector<T> or BoolArray expected (underlying type obtained through ContainerT::value_type).
*
* \param[in] sent_data Data sent by the current processor.
* \param[in] mpi_operation The MPI operation used during the reduction.
* \param[out] gathered_data gathered by the current processor.
*/
template<class ContainerT>
void AllReduceImpl(const ContainerT& sent_data,
ContainerT& gathered_data,
MpiNS::Op mpi_operation) const;
/*!
......
......@@ -26,8 +26,8 @@ namespace HappyHeart
static_assert(!std::is_same<bool, T>::value,
"Specialization method should have been called!");
std::vector<T> ret;
AllReduceImpl(sent_data, ret, mpi_operation);
std::vector<T> ret(sent_data.size());
AllReduce(sent_data, ret, mpi_operation);
return ret;
}
......@@ -142,12 +142,12 @@ namespace HappyHeart
template<class ContainerT>
void Mpi::AllReduceImpl(const ContainerT& sent_data,
ContainerT& gathered_data,
MpiNS::Op mpi_operation) const
void Mpi::AllReduce(const ContainerT& sent_data,
ContainerT& gathered_data,
MpiNS::Op mpi_operation) const
{
const auto size = sent_data.size();
gathered_data.resize(size);
assert(gathered_data.size() == size);
using value_type = typename ContainerT::value_type;
const auto& mpi_datatype = Private::Mpi::MpiDatatype<value_type>::Type();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment