Chris@16: // Copyright (C) 2005-2006 Douglas Gregor . Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // Message Passing Interface 1.1 -- Section 4.7. Gather-to-all Chris@16: #ifndef BOOST_MPI_ALL_GATHER_HPP Chris@16: #define BOOST_MPI_ALL_GATHER_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // all_gather falls back to gather+broadcast in some cases Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace mpi { Chris@16: Chris@16: namespace detail { Chris@16: // We're all-gathering for a type that has an associated MPI Chris@16: // datatype, so we'll use MPI_Gather to do all of the work. Chris@16: template Chris@16: void Chris@16: all_gather_impl(const communicator& comm, const T* in_values, int n, Chris@16: T* out_values, mpl::true_) Chris@16: { Chris@16: MPI_Datatype type = boost::mpi::get_mpi_datatype(*in_values); Chris@16: BOOST_MPI_CHECK_RESULT(MPI_Allgather, Chris@16: (const_cast(in_values), n, type, Chris@16: out_values, n, type, comm)); Chris@16: } Chris@16: Chris@16: // We're all-gathering for a type that has no associated MPI Chris@16: // type. So, we'll do a manual gather followed by a broadcast. Chris@16: template Chris@16: void Chris@16: all_gather_impl(const communicator& comm, const T* in_values, int n, Chris@16: T* out_values, mpl::false_) Chris@16: { Chris@16: gather(comm, in_values, n, out_values, 0); Chris@16: broadcast(comm, out_values, comm.size() * n, 0); Chris@16: } Chris@16: } // end namespace detail Chris@16: Chris@16: template Chris@16: inline void Chris@16: all_gather(const communicator& comm, const T& in_value, T* out_values) Chris@16: { Chris@16: detail::all_gather_impl(comm, &in_value, 1, out_values, is_mpi_datatype()); Chris@16: } Chris@16: Chris@16: template Chris@16: void Chris@16: all_gather(const communicator& comm, const T& in_value, Chris@16: std::vector& out_values) Chris@16: { Chris@16: out_values.resize(comm.size()); Chris@16: ::boost::mpi::all_gather(comm, &in_value, 1, &out_values[0]); Chris@16: } Chris@16: Chris@16: template Chris@16: inline void Chris@16: all_gather(const communicator& comm, const T* in_values, int n, T* out_values) Chris@16: { Chris@16: detail::all_gather_impl(comm, in_values, n, out_values, is_mpi_datatype()); Chris@16: } Chris@16: Chris@16: template Chris@16: void Chris@16: all_gather(const communicator& comm, const T* in_values, int n, Chris@16: std::vector& out_values) Chris@16: { Chris@16: out_values.resize(comm.size() * n); Chris@16: ::boost::mpi::all_gather(comm, in_values, n, &out_values[0]); Chris@16: } Chris@16: Chris@16: } } // end namespace boost::mpi Chris@16: Chris@16: #endif // BOOST_MPI_ALL_GATHER_HPP