// Copyright (C) 2005, 2006 Douglas Gregor. // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // Message Passing Interface 1.1 -- Section 4.5. Gatherv #ifndef BOOST_MPI_ALLGATHERV_HPP #define BOOST_MPI_ALLGATHERV_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace mpi { namespace detail { // We're all-gathering for a type that has an associated MPI // datatype, so we'll use MPI_Gather to do all of the work. template void all_gatherv_impl(const communicator& comm, const T* in_values, T* out_values, int const* sizes, int const* displs, mpl::true_) { // Make displacements if not provided scoped_array new_offsets_mem(make_offsets(comm, sizes, displs, -1)); if (new_offsets_mem) displs = new_offsets_mem.get(); MPI_Datatype type = get_mpi_datatype(*in_values); BOOST_MPI_CHECK_RESULT(MPI_Allgatherv, (const_cast(in_values), sizes[comm.rank()], type, out_values, const_cast(sizes), const_cast(displs), type, comm)); } // We're all-gathering for a type that does not have an // associated MPI datatype, so we'll need to serialize // it. template void all_gatherv_impl(const communicator& comm, const T* in_values, T* out_values, int const* sizes, int const* displs, mpl::false_ isnt_mpi_type) { // convert displacement to offsets to skip scoped_array skipped(make_skipped_slots(comm, sizes, displs)); all_gather_impl(comm, in_values, sizes[comm.rank()], out_values, sizes, skipped.get(), isnt_mpi_type); } } // end namespace detail template void all_gatherv(const communicator& comm, const T& in_value, T* out_values, const std::vector& sizes) { using detail::c_data; assert(sizes.size() == comm.size()); assert(sizes[comm.rank()] == 1); detail::all_gatherv_impl(comm, &in_value, out_values, c_data(sizes), 0, is_mpi_datatype()); } template void all_gatherv(const communicator& comm, const T* in_values, T* out_values, const std::vector& sizes) { using detail::c_data; assert(int(sizes.size()) == comm.size()); detail::all_gatherv_impl(comm, in_values, out_values, c_data(sizes), 0, is_mpi_datatype()); } template void all_gatherv(const communicator& comm, std::vector const& in_values, std::vector& out_values, const std::vector& sizes) { using detail::c_data; assert(int(sizes.size()) == comm.size()); assert(int(in_values.size()) == sizes[comm.rank()]); out_values.resize(std::accumulate(sizes.begin(), sizes.end(), 0)); ::boost::mpi::all_gatherv(comm, c_data(in_values), c_data(out_values), sizes); } template void all_gatherv(const communicator& comm, const T& in_value, T* out_values, const std::vector& sizes, const std::vector& displs) { using detail::c_data; assert(sizes.size() == comm.size()); assert(displs.size() == comm.size()); detail::all_gatherv_impl(comm, &in_value, 1, out_values, c_data(sizes), c_data(displs), is_mpi_datatype()); } template void all_gatherv(const communicator& comm, const T* in_values, T* out_values, const std::vector& sizes, const std::vector& displs) { using detail::c_data; assert(sizes.size() == comm.size()); assert(displs.size() == comm.size()); detail::all_gatherv_impl(comm, in_values, out_values, c_data(sizes), c_data(displs), is_mpi_datatype()); } template void all_gatherv(const communicator& comm, std::vector const& in_values, std::vector& out_values, const std::vector& sizes, const std::vector& displs) { using detail::c_data; assert(sizes.size() == comm.size()); assert(displs.size() == comm.size()); assert(in_values.size() == sizes[comm.rank()]); out_values.resize(std::accumulate(sizes.begin(), sizes.end(), 0)); ::boost::mpi::all_gatherv(comm, c_data(in_values), c_data(out_values), sizes, displs); } } } // end namespace boost::mpi #endif // BOOST_MPI_ALL_GATHERV_HPP