]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add compress() error checks for PETSc vectors
authorTimo Heister <timo.heister@gmail.com>
Tue, 24 Feb 2015 15:10:30 +0000 (10:10 -0500)
committerTimo Heister <timo.heister@gmail.com>
Tue, 24 Feb 2015 22:28:23 +0000 (17:28 -0500)
include/deal.II/lac/petsc_vector_base.h
source/lac/petsc_vector_base.cc

index 56c4286f8ed374b91336e5eaf5f8a5fc7fa92f6a..4d60dfb11a1b7f17784110a835bb2b9f9e56fe40 100644 (file)
@@ -270,7 +270,7 @@ namespace PETScWrappers
      * @ref GlossCompress "Compressing distributed objects"
      * for more information.
      */
-    void compress (::dealii::VectorOperation::values operation);
+    void compress (const VectorOperation::values operation);
 
     /**
      * Set all components of the vector to the given number @p s. Simply pass
@@ -741,7 +741,7 @@ namespace PETScWrappers
      * variable is @p mutable so that the accessor classes can write to it,
      * even though the vector object they refer to is constant.
      */
-    mutable ::dealii::VectorOperation::values last_action;
+    mutable VectorOperation::values last_action;
 
     /**
      * Make the reference class a friend.
index 44fe52e1b343177a05102ee8131537d01c89ded6..f9934c815c3e518b98f792afe25757bff3b6ba43 100644 (file)
@@ -388,8 +388,27 @@ namespace PETScWrappers
 
 
   void
-  VectorBase::compress (::dealii::VectorOperation::values)
+  VectorBase::compress (const VectorOperation::values operation)
   {
+#ifdef DEBUG
+#ifdef DEAL_II_WITH_MPI
+    // Check that all processors agree that last_action is the same (or none!)
+
+    int my_int_last_action = last_action;
+    int all_int_last_action;
+
+    MPI_Allreduce(&my_int_last_action, &all_int_last_action, 1, MPI_INT,
+                  MPI_BOR, get_mpi_communicator());
+
+    AssertThrow(all_int_last_action != (::dealii::VectorOperation::add | ::dealii::VectorOperation::insert),
+                ExcMessage("Error: not all processors agree on the last VectorOperation before this compress() call."));
+#endif
+#endif
+
+    AssertThrow(last_action == ::dealii::VectorOperation::unknown
+                || last_action == operation,
+                ExcMessage("Missing compress() or calling with wrong VectorOperation argument."));
+
     // note that one may think that
     // we only need to do something
     // if in fact the state is

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.