From ff1e25eaf5ef4c17efd262cd86995b9892f927c4 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Mon, 6 Mar 2017 09:17:28 +0100 Subject: [PATCH] Reduce access to possibly invalid communicator as much as possible. --- source/lac/trilinos_vector.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/source/lac/trilinos_vector.cc b/source/lac/trilinos_vector.cc index c24c8105df..1af1c4c9a6 100644 --- a/source/lac/trilinos_vector.cc +++ b/source/lac/trilinos_vector.cc @@ -360,7 +360,7 @@ namespace TrilinosWrappers } #if defined(DEBUG) && defined(DEAL_II_WITH_MPI) const Epetra_MpiComm *comm_ptr - = dynamic_cast(&(vector->Comm())); + = dynamic_cast(&(v.vector->Comm())); Assert (comm_ptr != 0, ExcInternalError()); const size_type n_elements_global = Utilities::MPI::sum (owned_elements.n_elements(), comm_ptr->Comm()); @@ -494,6 +494,7 @@ namespace TrilinosWrappers } + Vector & Vector::operator = (const Vector &v) { @@ -504,6 +505,25 @@ namespace TrilinosWrappers const Epetra_MpiComm *v_comm = dynamic_cast(&v.vector->Comm()); const bool same_communicators = my_comm != NULL && v_comm != NULL && my_comm->DataPtr() == v_comm->DataPtr(); + // Need to ask MPI whether the communicators are the same. We would like + // to use the following checks but currently we cannot make sure the + // memory of my_comm is not stale from some MPI_Comm_free + // somewhere. This can happen when a vector lives in GrowingVectorMemory + // data structures. Thus, the following code is commented out. + // + //if (my_comm != NULL && v_comm != NULL && my_comm->DataPtr() != v_comm->DataPtr()) + // { + // int communicators_same = 0; + // const int ierr = MPI_Comm_compare (my_comm->GetMpiComm(), + // v_comm->GetMpiComm(), + // &communicators_same); + // AssertThrowMPI(ierr); + // if (!(communicators_same == MPI_IDENT || + // communicators_same == MPI_CONGRUENT)) + // same_communicators = false; + // else + // same_communicators = true; + // } #else const bool same_communicators = true; #endif @@ -512,7 +532,7 @@ namespace TrilinosWrappers // layout (just need to copy the local data, not reset the memory and // the underlying Epetra_Map). The third case means that we have to // rebuild the calling vector. - if (same_communicators && vector->Map().SameAs(v.vector->Map())) + if (same_communicators && v.vector->Map().SameAs(vector->Map())) { *vector = *v.vector; if (v.nonlocal_vector.get() != 0) -- 2.39.5