From: Timo Heister Date: Tue, 5 Nov 2019 01:38:50 +0000 (-0500) Subject: return MPI_Comm by const ref X-Git-Tag: v9.2.0-rc1~903^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8f2acf61b98637b0824ff0c97af276aadbf239e;p=dealii.git 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()); --- 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;