From 7ef75ad651fbf10f6b79c82a619b42ac0a735307 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Tue, 22 Oct 2019 21:20:05 +0200 Subject: [PATCH] add MPI::free_communicator function --- include/deal.II/base/mpi.h | 17 ++++++++++++++++- source/base/mpi.cc | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 294994e744..2c03fabdf3 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -191,11 +191,26 @@ namespace Utilities * can interact without interfering with each other. * * When no longer needed, the communicator created here needs to be - * destroyed using MPI_Comm_free. + * destroyed using free_communicator(). + * + * This function is equivalent to calling + * MPI_Comm_dup(mpi_communicator, &return_value);. */ MPI_Comm duplicate_communicator(const MPI_Comm &mpi_communicator); + /** + * Free the given + * @ref GlossMPICommunicator "communicator" + * @p mpi_communicator that was duplicated using duplicate_communicator(). + * + * The argument is passed by reference and will be invalidated and set to + * the MPI null handle. This function is equivalent to calling + * MPI_Comm_free(&mpi_communicator);. + */ + void + free_communicator(MPI_Comm &mpi_communicator); + /** * If @p comm is an intracommunicator, this function returns a new * communicator @p newcomm with communication group defined by the diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 4de6ac44ef..3c7318b519 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -103,6 +103,15 @@ namespace Utilities + void + free_communicator(MPI_Comm &mpi_communicator) + { + const int ierr = MPI_Comm_free(&mpi_communicator); + AssertThrowMPI(ierr); + } + + + int create_group(const MPI_Comm & comm, const MPI_Group &group, @@ -521,6 +530,7 @@ namespace Utilities } + std::vector create_ascending_partitioning(const MPI_Comm & /*comm*/, const IndexSet::size_type &local_size) @@ -529,6 +539,7 @@ namespace Utilities } + MPI_Comm duplicate_communicator(const MPI_Comm &mpi_communicator) { @@ -537,6 +548,12 @@ namespace Utilities + void + free_communicator(MPI_Comm & /*mpi_communicator*/) + {} + + + MinMaxAvg min_max_avg(const double my_value, const MPI_Comm &) { -- 2.39.5