From e5edf08459cbd9ea24310dd8a5b7f4e71ebdc729 Mon Sep 17 00:00:00 2001 From: benjamin Date: Sun, 28 Jan 2018 11:38:09 +0100 Subject: [PATCH] move implemetation of MPI::some_to_some --- include/deal.II/base/mpi.h | 79 +++++++++++++++++++++++++++ include/deal.II/base/mpi.templates.h | 81 ---------------------------- tests/base/mpi_some_to_some_01.cc | 2 +- tests/base/mpi_some_to_some_02.cc | 2 +- 4 files changed, 81 insertions(+), 83 deletions(-) diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 50a5842d27..8abb223e19 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -551,6 +551,85 @@ namespace Utilities mpi_communicator, ArrayView(minima, N)); } + template + std::map + some_to_some(const MPI_Comm &comm, + const std::map &objects_to_send) + { +#ifndef DEAL_II_WITH_MPI + (void)comm; + Assert(objects_to_send.size() == 0, ExcMessage("Cannot send to more than one processor.")); + Assert(objects_to_send.find(0) != objects_to_send.end() || objects_to_send.size() == 0, + ExcMessage("Can only send to myself or to nobody.")); + return objects_to_send; +#else + + std::vector send_to(objects_to_send.size()); + { + unsigned int i=0; + for (const auto &m: objects_to_send) + send_to[i++] = m.first; + } + AssertDimension(send_to.size(), objects_to_send.size()); + + const auto receive_from = + Utilities::MPI::compute_point_to_point_communication_pattern(comm, send_to); + + // Sending buffers + std::vector > buffers_to_send(send_to.size()); + std::vector buffer_send_requests(send_to.size()); + { + unsigned int i = 0; + for (const auto &rank_obj : objects_to_send) + { + const auto &rank = rank_obj.first; + buffers_to_send[i] = Utilities::pack(rank_obj.second); + const int ierr = MPI_Isend(buffers_to_send[i].data(), + buffers_to_send[i].size(), MPI_CHAR, + rank, 21, comm, &buffer_send_requests[i]); + AssertThrowMPI(ierr); + ++i; + } + } + + // Receiving buffers + std::map received_objects; + { + std::vector buffer; + // We do this on a first come/first served basis + for (unsigned int i = 0; i(buffer); + } + } + + // Wait to have sent all objects. + MPI_Waitall(send_to.size(), buffer_send_requests.data(),MPI_STATUSES_IGNORE); + + return received_objects; +#endif // deal.II with MPI + } + template std::vector all_gather(const MPI_Comm &comm, const T &object) diff --git a/include/deal.II/base/mpi.templates.h b/include/deal.II/base/mpi.templates.h index f0cf9c208a..5c8cc75a96 100644 --- a/include/deal.II/base/mpi.templates.h +++ b/include/deal.II/base/mpi.templates.h @@ -190,87 +190,6 @@ namespace Utilities - template - std::map - some_to_some(const MPI_Comm &comm, - const std::map &objects_to_send) - { -#ifndef DEAL_II_WITH_MPI - (void)comm; - Assert(objects_to_send.size() == 0, ExcMessage("Cannot send to more than one processor.")); - Assert(objects_to_send.find(0) != objects_to_send.end() || objects_to_send.size() == 0, - ExcMessage("Can only send to myself or to nobody.")); - return objects_to_send; -#else - - std::vector send_to(objects_to_send.size()); - { - unsigned int i=0; - for (const auto &m: objects_to_send) - send_to[i++] = m.first; - } - AssertDimension(send_to.size(), objects_to_send.size()); - - const auto receive_from = - Utilities::MPI::compute_point_to_point_communication_pattern(comm, send_to); - - // Sending buffers - std::vector > buffers_to_send(send_to.size()); - std::vector buffer_send_requests(send_to.size()); - { - unsigned int i = 0; - for (const auto &rank_obj : objects_to_send) - { - const auto &rank = rank_obj.first; - buffers_to_send[i] = Utilities::pack(rank_obj.second); - const int ierr = MPI_Isend(buffers_to_send[i].data(), - buffers_to_send[i].size(), MPI_CHAR, - rank, 21, comm, &buffer_send_requests[i]); - AssertThrowMPI(ierr); - ++i; - } - } - - // Receiving buffers - std::map received_objects; - { - std::vector buffer; - // We do this on a first come/first served basis - for (unsigned int i = 0; i(buffer); - } - } - - // Wait to have sent all objects. - MPI_Waitall(send_to.size(), buffer_send_requests.data(),MPI_STATUSES_IGNORE); - - return received_objects; -#endif // deal.II with MPI - } - - - template T sum (const T &t, const MPI_Comm &mpi_communicator) diff --git a/tests/base/mpi_some_to_some_01.cc b/tests/base/mpi_some_to_some_01.cc index f9319414ae..e5bca2c7b6 100644 --- a/tests/base/mpi_some_to_some_01.cc +++ b/tests/base/mpi_some_to_some_01.cc @@ -19,7 +19,7 @@ #include "../tests.h" #include -#include +#include #include diff --git a/tests/base/mpi_some_to_some_02.cc b/tests/base/mpi_some_to_some_02.cc index 8a442b9400..383fb15f30 100644 --- a/tests/base/mpi_some_to_some_02.cc +++ b/tests/base/mpi_some_to_some_02.cc @@ -19,8 +19,8 @@ #include "../tests.h" #include -#include #include + #include #include -- 2.39.5