From d8f2acf61b98637b0824ff0c97af276aadbf239e Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Mon, 4 Nov 2019 20:38:50 -0500 Subject: [PATCH] return MPI_Comm by const ref Fix a few places where we return the MPI_Comm by value. This is problematic if we pass it to a function taking a reference and storing it: CollectiveMutex::ScopedLock lock(mutex, tria.get_communicator()); --- include/deal.II/distributed/tria_base.h | 2 +- include/deal.II/multigrid/multigrid.h | 10 +++++----- source/distributed/tria_base.cc | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/deal.II/distributed/tria_base.h b/include/deal.II/distributed/tria_base.h index ffdb86988f..dbfe8d5cdf 100644 --- a/include/deal.II/distributed/tria_base.h +++ b/include/deal.II/distributed/tria_base.h @@ -93,7 +93,7 @@ namespace parallel /** * Return MPI communicator used by this triangulation. */ - virtual MPI_Comm + virtual const MPI_Comm & get_communicator() const; /** diff --git a/include/deal.II/multigrid/multigrid.h b/include/deal.II/multigrid/multigrid.h index 97e8e54390..7c738ea95d 100644 --- a/include/deal.II/multigrid/multigrid.h +++ b/include/deal.II/multigrid/multigrid.h @@ -577,7 +577,7 @@ public: /** * Return the MPI communicator object in use with this preconditioner. */ - MPI_Comm + const MPI_Comm & get_mpi_communicator() const; /** @@ -929,14 +929,14 @@ PreconditionMG::locally_owned_domain_indices( template -MPI_Comm +const MPI_Comm & PreconditionMG::get_mpi_communicator() const { - // currently parallel GMG works with distributed Triangulation only, + // currently parallel GMG works with parallel triangulations only, // so it should be a safe bet to use it to query MPI communicator: const Triangulation &tria = dof_handler_vector[0]->get_triangulation(); - const parallel::distributed::Triangulation *ptria = - dynamic_cast *>(&tria); + const parallel::TriangulationBase *ptria = + dynamic_cast *>(&tria); Assert(ptria != nullptr, ExcInternalError()); return ptria->get_communicator(); } diff --git a/source/distributed/tria_base.cc b/source/distributed/tria_base.cc index ab57bb0e6e..1586e61bb0 100644 --- a/source/distributed/tria_base.cc +++ b/source/distributed/tria_base.cc @@ -167,7 +167,7 @@ namespace parallel } template - MPI_Comm + const MPI_Comm & TriangulationBase::get_communicator() const { return mpi_communicator; -- 2.39.5