annotate DEPENDENCIES/generic/include/boost/mpi/collectives/all_gather.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (C) 2005-2006 Douglas Gregor <doug.gregor -at- gmail.com>.
Chris@16 2
Chris@16 3 // Use, modification and distribution is subject to the Boost Software
Chris@16 4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 5 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6
Chris@16 7 // Message Passing Interface 1.1 -- Section 4.7. Gather-to-all
Chris@16 8 #ifndef BOOST_MPI_ALL_GATHER_HPP
Chris@16 9 #define BOOST_MPI_ALL_GATHER_HPP
Chris@16 10
Chris@16 11 #include <boost/mpi/exception.hpp>
Chris@16 12 #include <boost/mpi/datatype.hpp>
Chris@16 13 #include <vector>
Chris@16 14 #include <boost/serialization/vector.hpp>
Chris@16 15
Chris@16 16 // all_gather falls back to gather+broadcast in some cases
Chris@16 17 #include <boost/mpi/collectives/broadcast.hpp>
Chris@16 18 #include <boost/mpi/collectives/gather.hpp>
Chris@16 19
Chris@16 20 namespace boost { namespace mpi {
Chris@16 21
Chris@16 22 namespace detail {
Chris@16 23 // We're all-gathering for a type that has an associated MPI
Chris@16 24 // datatype, so we'll use MPI_Gather to do all of the work.
Chris@16 25 template<typename T>
Chris@16 26 void
Chris@16 27 all_gather_impl(const communicator& comm, const T* in_values, int n,
Chris@16 28 T* out_values, mpl::true_)
Chris@16 29 {
Chris@16 30 MPI_Datatype type = boost::mpi::get_mpi_datatype<T>(*in_values);
Chris@16 31 BOOST_MPI_CHECK_RESULT(MPI_Allgather,
Chris@16 32 (const_cast<T*>(in_values), n, type,
Chris@16 33 out_values, n, type, comm));
Chris@16 34 }
Chris@16 35
Chris@16 36 // We're all-gathering for a type that has no associated MPI
Chris@16 37 // type. So, we'll do a manual gather followed by a broadcast.
Chris@16 38 template<typename T>
Chris@16 39 void
Chris@16 40 all_gather_impl(const communicator& comm, const T* in_values, int n,
Chris@16 41 T* out_values, mpl::false_)
Chris@16 42 {
Chris@16 43 gather(comm, in_values, n, out_values, 0);
Chris@16 44 broadcast(comm, out_values, comm.size() * n, 0);
Chris@16 45 }
Chris@16 46 } // end namespace detail
Chris@16 47
Chris@16 48 template<typename T>
Chris@16 49 inline void
Chris@16 50 all_gather(const communicator& comm, const T& in_value, T* out_values)
Chris@16 51 {
Chris@16 52 detail::all_gather_impl(comm, &in_value, 1, out_values, is_mpi_datatype<T>());
Chris@16 53 }
Chris@16 54
Chris@16 55 template<typename T>
Chris@16 56 void
Chris@16 57 all_gather(const communicator& comm, const T& in_value,
Chris@16 58 std::vector<T>& out_values)
Chris@16 59 {
Chris@16 60 out_values.resize(comm.size());
Chris@16 61 ::boost::mpi::all_gather(comm, &in_value, 1, &out_values[0]);
Chris@16 62 }
Chris@16 63
Chris@16 64 template<typename T>
Chris@16 65 inline void
Chris@16 66 all_gather(const communicator& comm, const T* in_values, int n, T* out_values)
Chris@16 67 {
Chris@16 68 detail::all_gather_impl(comm, in_values, n, out_values, is_mpi_datatype<T>());
Chris@16 69 }
Chris@16 70
Chris@16 71 template<typename T>
Chris@16 72 void
Chris@16 73 all_gather(const communicator& comm, const T* in_values, int n,
Chris@16 74 std::vector<T>& out_values)
Chris@16 75 {
Chris@16 76 out_values.resize(comm.size() * n);
Chris@16 77 ::boost::mpi::all_gather(comm, in_values, n, &out_values[0]);
Chris@16 78 }
Chris@16 79
Chris@16 80 } } // end namespace boost::mpi
Chris@16 81
Chris@16 82 #endif // BOOST_MPI_ALL_GATHER_HPP