From 85bb58d75be9a3129e3132df7386e002ffc86525 Mon Sep 17 00:00:00 2001 From: "K. Noel Belcourt" Date: Thu, 21 Jul 2016 21:48:02 -0600 Subject: [PATCH] Add send and recv overloads for std::vector. --- include/boost/mpi/communicator.hpp | 70 ++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/include/boost/mpi/communicator.hpp b/include/boost/mpi/communicator.hpp index 46f7375..af616a3 100644 --- a/include/boost/mpi/communicator.hpp +++ b/include/boost/mpi/communicator.hpp @@ -272,6 +272,15 @@ class BOOST_MPI_DECL communicator template void send(int dest, int tag, const T& value) const; + template + void send(int dest, int tag, const std::vector& value) const; + + template + void send_vector(int dest, int tag, const std::vector& value, mpl::true_) const; + + template + void send_vector(int dest, int tag, const std::vector& value, mpl::false_) const; + /** * @brief Send the skeleton of an object. * @@ -384,6 +393,17 @@ class BOOST_MPI_DECL communicator template status recv(int source, int tag, T& value) const; + template + status recv(int source, int tag, std::vector& value) const; + + template + status recv_vector(int source, int tag, std::vector& value + , mpl::true_) const; + + template + status recv_vector(int source, int tag, std::vector& value + , mpl::false_) const; + /** * @brief Receive a skeleton from a remote process. * @@ -1187,6 +1207,30 @@ communicator::array_send_impl(int dest, int tag, const T* values, int n, send(dest, tag, oa); } +template +void communicator::send_vector(int dest, int tag, const std::vector& value + , mpl::true_ true_type) const +{ + // send the vector size + typename std::vector::size_type size = value.size(); + send(dest, tag, size); + // send the data + this->array_send_impl(dest, tag, value.data(), size, true_type); +} + +template +void communicator::send_vector(int dest, int tag, const std::vector& value + , mpl::false_ false_type) const +{ + this->send_impl(dest, tag, value, false_type); +} + +template +void communicator::send(int dest, int tag, const std::vector& value) const +{ + send_vector(dest, tag, value, is_mpi_datatype()); +} + // Array send must send the elements directly template void communicator::send(int dest, int tag, const T* values, int n) const @@ -1269,6 +1313,32 @@ communicator::array_recv_impl(int source, int tag, T* values, int n, return stat; } +template +status communicator::recv_vector(int source, int tag, std::vector& value + , mpl::true_ true_type) const +{ + // receive the vector size + typename std::vector::size_type size = 0; + recv(source, tag, size); + // size the vector + value.resize(size); + // receive the data + return this->array_recv_impl(source, tag, value.data(), size, true_type); +} + +template +status communicator::recv_vector(int source, int tag, std::vector& value + , mpl::false_ false_type) const +{ + return this->recv_impl(source, tag, value, false_type); +} + +template +status communicator::recv(int source, int tag, std::vector& value) const +{ + return recv_vector(source, tag, value, is_mpi_datatype()); +} + // Array receive must receive the elements directly into a buffer. template status communicator::recv(int source, int tag, T* values, int n) const