]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Reduce access to possibly invalid communicator as much as possible.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Mon, 6 Mar 2017 08:17:28 +0000 (09:17 +0100)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 7 Mar 2017 08:11:09 +0000 (09:11 +0100)
source/lac/trilinos_vector.cc

index c24c8105df19b33d37b3dcb7aa9dafae39440588..1af1c4c9a691a4e4a830cc8736560df40fe6b5f3 100644 (file)
@@ -360,7 +360,7 @@ namespace TrilinosWrappers
         }
 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI)
       const Epetra_MpiComm *comm_ptr
-        = dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()));
+        = dynamic_cast<const Epetra_MpiComm *>(&(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<const Epetra_MpiComm *>(&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)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.