diff options
Diffstat (limited to 'boost/mpi')
-rw-r--r-- | boost/mpi/communicator.hpp | 74 | ||||
-rw-r--r-- | boost/mpi/datatype.hpp | 13 |
2 files changed, 87 insertions, 0 deletions
diff --git a/boost/mpi/communicator.hpp b/boost/mpi/communicator.hpp index 46f7375d6f..a491086ad5 100644 --- a/boost/mpi/communicator.hpp +++ b/boost/mpi/communicator.hpp @@ -1,4 +1,5 @@ // Copyright (C) 2005, 2006 Douglas Gregor <doug.gregor -at- gmail.com>. +// Copyright (C) 2016 K. Noel Belcourt <kbelco -at- sandia.gov>. // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -23,6 +24,7 @@ #include <utility> #include <iterator> #include <stdexcept> // for std::range_error +#include <vector> // For (de-)serializing sends and receives #include <boost/mpi/packed_oarchive.hpp> @@ -272,6 +274,17 @@ class BOOST_MPI_DECL communicator template<typename T> void send(int dest, int tag, const T& value) const; + template<typename T, typename A> + void send(int dest, int tag, const std::vector<T,A>& value) const; + + template<typename T, typename A> + void send_vector(int dest, int tag, const std::vector<T,A>& value, + mpl::true_) const; + + template<typename T, typename A> + void send_vector(int dest, int tag, const std::vector<T,A>& value, + mpl::false_) const; + /** * @brief Send the skeleton of an object. * @@ -384,6 +397,17 @@ class BOOST_MPI_DECL communicator template<typename T> status recv(int source, int tag, T& value) const; + template<typename T, typename A> + status recv(int source, int tag, std::vector<T,A>& value) const; + + template<typename T, typename A> + status recv_vector(int source, int tag, std::vector<T,A>& value, + mpl::true_) const; + + template<typename T, typename A> + status recv_vector(int source, int tag, std::vector<T,A>& value, + mpl::false_) const; + /** * @brief Receive a skeleton from a remote process. * @@ -1187,6 +1211,30 @@ communicator::array_send_impl(int dest, int tag, const T* values, int n, send(dest, tag, oa); } +template<typename T, typename A> +void communicator::send_vector(int dest, int tag, + const std::vector<T,A>& value, mpl::true_ true_type) const +{ + // send the vector size + typename std::vector<T,A>::size_type size = value.size(); + send(dest, tag, size); + // send the data + this->array_send_impl(dest, tag, value.data(), size, true_type); +} + +template<typename T, typename A> +void communicator::send_vector(int dest, int tag, + const std::vector<T,A>& value, mpl::false_ false_type) const +{ + this->send_impl(dest, tag, value, false_type); +} + +template<typename T, typename A> +void communicator::send(int dest, int tag, const std::vector<T,A>& value) const +{ + send_vector(dest, tag, value, is_mpi_datatype<T>()); +} + // Array send must send the elements directly template<typename T> void communicator::send(int dest, int tag, const T* values, int n) const @@ -1269,6 +1317,32 @@ communicator::array_recv_impl(int source, int tag, T* values, int n, return stat; } +template<typename T, typename A> +status communicator::recv_vector(int source, int tag, + std::vector<T,A>& value, mpl::true_ true_type) const +{ + // receive the vector size + typename std::vector<T,A>::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<typename T, typename A> +status communicator::recv_vector(int source, int tag, + std::vector<T,A>& value, mpl::false_ false_type) const +{ + return this->recv_impl(source, tag, value, false_type); +} + +template<typename T, typename A> +status communicator::recv(int source, int tag, std::vector<T,A>& value) const +{ + return recv_vector(source, tag, value, is_mpi_datatype<T>()); +} + // Array receive must receive the elements directly into a buffer. template<typename T> status communicator::recv(int source, int tag, T* values, int n) const diff --git a/boost/mpi/datatype.hpp b/boost/mpi/datatype.hpp index c26dfdfc3b..1f069977d0 100644 --- a/boost/mpi/datatype.hpp +++ b/boost/mpi/datatype.hpp @@ -30,6 +30,10 @@ #include <boost/serialization/item_version_type.hpp> #include <utility> // for std::pair +#if defined(__cplusplus) && (201103L <= __cplusplus) +#include <array> +#endif + namespace boost { namespace mpi { /** @@ -265,6 +269,15 @@ struct is_mpi_datatype<std::pair<T,U> > { }; +/// specialization of is_mpi_datatype for arrays +#if defined(__cplusplus) && (201103L <= __cplusplus) +template<class T, std::size_t N> +struct is_mpi_datatype<std::array<T, N> > + : public is_mpi_datatype<T> +{ +}; +#endif + // Define wchar_t specialization of is_mpi_datatype, if possible. #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && \ (defined(MPI_WCHAR) || (defined(MPI_VERSION) && MPI_VERSION >= 2)) |