From: benjamin Date: Sat, 27 Jan 2018 21:25:55 +0000 (+0100) Subject: Move implementation of MPI::all_gather() X-Git-Tag: v9.0.0-rc1~504^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eca60276b90ec1ae018c48e201addbf8010ee164;p=dealii.git Move implementation of MPI::all_gather() --- diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 9b59aa1b3d..0f6502153f 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -551,6 +551,55 @@ namespace Utilities mpi_communicator, ArrayView(minima, N)); } + template + std::vector all_gather(const MPI_Comm &comm, + const T &object) + { +#ifndef DEAL_II_WITH_MPI + (void)comm; + std::vector v(1, object); + return v; +#else + const auto n_procs = dealii::Utilities::MPI::n_mpi_processes(comm); + + std::vector buffer = Utilities::pack(object); + + int n_local_data = buffer.size(); + + // Vector to store the size of loc_data_array for every process + std::vector size_all_data(n_procs,0); + + // Exchanging the size of each buffer + MPI_Allgather(&n_local_data, 1, MPI_INT, + &(size_all_data[0]), 1, MPI_INT, + comm); + + // Now computing the the displacement, relative to recvbuf, + // at which to store the incoming buffer + std::vector rdispls(n_procs); + rdispls[0] = 0; + for (unsigned int i=1; i < n_procs; ++i) + rdispls[i] = rdispls[i-1] + size_all_data[i-1]; + + // Step 3: exchange the buffer: + std::vector received_unrolled_buffer(rdispls.back() + size_all_data.back()); + + MPI_Allgatherv(buffer.data(), n_local_data, MPI_CHAR, + received_unrolled_buffer.data(), size_all_data.data(), + rdispls.data(), MPI_CHAR, comm); + + std::vector received_objects(n_procs); + for (unsigned int i= 0; i < n_procs; ++i) + { + std::vector local_buffer(received_unrolled_buffer.begin()+rdispls[i], + received_unrolled_buffer.begin()+rdispls[i]+size_all_data[i]); + received_objects[i] = Utilities::unpack(local_buffer); + } + + return received_objects; +#endif + } + template std::vector gather(const MPI_Comm &comm, diff --git a/include/deal.II/base/mpi.templates.h b/include/deal.II/base/mpi.templates.h index 15162ed41c..b3ce6235eb 100644 --- a/include/deal.II/base/mpi.templates.h +++ b/include/deal.II/base/mpi.templates.h @@ -271,57 +271,6 @@ namespace Utilities - template - std::vector all_gather(const MPI_Comm &comm, - const T &object) - { -#ifndef DEAL_II_WITH_MPI - (void)comm; - std::vector v(1, object); - return v; -#else - const auto n_procs = dealii::Utilities::MPI::n_mpi_processes(comm); - - std::vector buffer = Utilities::pack(object); - - int n_local_data = buffer.size(); - - // Vector to store the size of loc_data_array for every process - std::vector size_all_data(n_procs,0); - - // Exchanging the size of each buffer - MPI_Allgather(&n_local_data, 1, MPI_INT, - &(size_all_data[0]), 1, MPI_INT, - comm); - - // Now computing the the displacement, relative to recvbuf, - // at which to store the incoming buffer - std::vector rdispls(n_procs); - rdispls[0] = 0; - for (unsigned int i=1; i < n_procs; ++i) - rdispls[i] = rdispls[i-1] + size_all_data[i-1]; - - // Step 3: exchange the buffer: - std::vector received_unrolled_buffer(rdispls.back() + size_all_data.back()); - - MPI_Allgatherv(buffer.data(), n_local_data, MPI_CHAR, - received_unrolled_buffer.data(), size_all_data.data(), - rdispls.data(), MPI_CHAR, comm); - - std::vector received_objects(n_procs); - for (unsigned int i= 0; i < n_procs; ++i) - { - std::vector local_buffer(received_unrolled_buffer.begin()+rdispls[i], - received_unrolled_buffer.begin()+rdispls[i]+size_all_data[i]); - received_objects[i] = Utilities::unpack(local_buffer); - } - - return received_objects; -#endif - } - - - template T sum (const T &t, const MPI_Comm &mpi_communicator) diff --git a/tests/base/mpi_all_gather_01.cc b/tests/base/mpi_all_gather_01.cc index 803fe31f20..f996b4092f 100644 --- a/tests/base/mpi_all_gather_01.cc +++ b/tests/base/mpi_all_gather_01.cc @@ -18,7 +18,7 @@ #include "../tests.h" #include -#include +#include #include int main(int argc, char *argv[]) diff --git a/tests/base/mpi_some_to_some_02.cc b/tests/base/mpi_some_to_some_02.cc index e6e7a4e440..8a442b9400 100644 --- a/tests/base/mpi_some_to_some_02.cc +++ b/tests/base/mpi_some_to_some_02.cc @@ -20,7 +20,7 @@ #include #include - +#include #include #include