]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Remove the automatic way of compressing PETSc vectors based on the mode. This was...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 3 Aug 2011 16:36:41 +0000 (16:36 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 3 Aug 2011 16:36:41 +0000 (16:36 +0000)
git-svn-id: https://svn.dealii.org/trunk@24007 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/lac/petsc_vector_base.h
deal.II/source/lac/petsc_vector_base.cc

index 8f039d9d82259ce3ef97a62301d155479b31db58..73f578c4f2dbc60f5ce971d3947b377339d44715 100644 (file)
@@ -21,6 +21,19 @@ inconvenience this causes.
 </p>
 
 <ol>
+<li> Changed: The PETScWrapper::VectorBase class tried to keep track of
+whether the last operation done on a vector was to add to an element or to
+write into one. If the previous such operation was of a different kind
+than the current one, we would flush buffers (see the description in
+@ref GlossCompress). However, trying to do this automatically turned
+out to be an endless source of hard-to-find bugs in %parallel programs.
+The scheme has therefore now been changed to the following: the class
+keeps track of the previous operation and if it differs from the
+current one, reports an error stating that the user needs to call
+PETScWrapper::VectorBase::compress() instead.
+<br>
+(Wolfgang Bangerth, 2011/08/03)
+
 <li> Changed: The classes Tensor, SymmetricTensor and Point now have an
 additional template argument for the number type. While a default template
 value of double ensures that all old code is still valid, this
index 8bf647553c6be616e6223b4f6c5fab56ec5f6d58..a271f7e32ceaad8a780e83bb6edc4209287da3ad 100644 (file)
@@ -172,6 +172,22 @@ namespace PETScWrappers
                         << " of a distributed vector, but only elements "
                         << arg2 << " through " << arg3
                         << " are stored locally and can be accessed.");
+       /**
+        * Exception.
+        */
+       DeclException2 (ExcWrongMode,
+                       int, int,
+                       << "You tried to do a "
+                       << (arg1 == 1 ?
+                           "'set'" :
+                           (arg1 == 2 ?
+                            "'add'" : "???"))
+                       << " operation but the vector is currently in "
+                       << (arg2 == 1 ?
+                           "'set'" :
+                           (arg2 == 2 ?
+                            "'add'" : "???"))
+                       << " mode. You first have to call 'compress()'.");
 
       private:
                                          /**
@@ -906,16 +922,11 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator = (const PetscScalar &value) const
     {
-      // if the last action was an addition, we need to flush buffers
-      if (vector.last_action == VectorBase::LastAction::add)
-        {
-          int ierr;
-          ierr = VecAssemblyBegin (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-          ierr = VecAssemblyEnd (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-        }
+      Assert ((vector.last_action == VectorBase::LastAction::insert)
+              ||
+              (vector.last_action == VectorBase::LastAction::none),
+             ExcWrongMode (VectorBase::LastAction::insert,
+                           vector.last_action));
 
 #ifdef PETSC_USE_64BIT_INDICES
       const PetscInt petsc_i = index;
@@ -938,16 +949,11 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator += (const PetscScalar &value) const
     {
-      // if the last action was a set operation, we need to flush buffers      
-      if (vector.last_action == VectorBase::LastAction::insert)
-        {
-          int ierr;
-          ierr = VecAssemblyBegin (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-          ierr = VecAssemblyEnd (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-        }
+      Assert ((vector.last_action == VectorBase::LastAction::add)
+              ||
+              (vector.last_action == VectorBase::LastAction::none),
+             ExcWrongMode (VectorBase::LastAction::add,
+                           vector.last_action));
 
       vector.last_action = VectorBase::LastAction::add;
 
@@ -981,16 +987,11 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator -= (const PetscScalar &value) const
     {
-      // if the last action was a set operation, we need to flush buffers
-      if (vector.last_action == VectorBase::LastAction::insert)
-        {
-          int ierr;
-          ierr = VecAssemblyBegin (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-          ierr = VecAssemblyEnd (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-        }
+      Assert ((vector.last_action == VectorBase::LastAction::add)
+              ||
+              (vector.last_action == VectorBase::LastAction::none),
+             ExcWrongMode (VectorBase::LastAction::add,
+                           vector.last_action));
 
       vector.last_action = VectorBase::LastAction::add;
 
@@ -1025,16 +1026,11 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator *= (const PetscScalar &value) const
     {
-      // if the last action was an addition, we need to flush buffers
-      if (vector.last_action == VectorBase::LastAction::add)
-        {
-          int ierr;
-          ierr = VecAssemblyBegin (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-          ierr = VecAssemblyEnd (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-        }
+      Assert ((vector.last_action == VectorBase::LastAction::insert)
+              ||
+              (vector.last_action == VectorBase::LastAction::none),
+             ExcWrongMode (VectorBase::LastAction::insert,
+                           vector.last_action));
 
       vector.last_action = VectorBase::LastAction::insert;
 
@@ -1070,16 +1066,11 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator /= (const PetscScalar &value) const
     {
-      // if the last action was a set operation, we need to flush buffers
-      if (vector.last_action == VectorBase::LastAction::insert)
-        {
-          int ierr;
-          ierr = VecAssemblyBegin (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-          ierr = VecAssemblyEnd (vector);
-          AssertThrow (ierr == 0, ExcPETScError(ierr));
-        }
+      Assert ((vector.last_action == VectorBase::LastAction::insert)
+              ||
+              (vector.last_action == VectorBase::LastAction::none),
+             ExcWrongMode (VectorBase::LastAction::insert,
+                           vector.last_action));
 
       vector.last_action = VectorBase::LastAction::insert;
 
index e31f29a01267ed4795cd312a8c10984c54bbae16..a2ba8446730bf047d3e7ffc520abbc0d738d9f47 100644 (file)
@@ -1121,20 +1121,15 @@ namespace PETScWrappers
                                    const PetscScalar  *values,
                                    const bool          add_values)
   {
-    // if the last action was a set operation, we need to flush buffers
-    if (last_action == VectorBase::LastAction::insert)
-      {
-        int ierr;
-        ierr = VecAssemblyBegin (vector);
-        AssertThrow (ierr == 0, ExcPETScError(ierr));
-
-        ierr = VecAssemblyEnd (vector);
-        AssertThrow (ierr == 0, ExcPETScError(ierr));
-       // reset the last action field to indicate that we're back to
-       // a pristine state
-       last_action = VectorBase::LastAction::none;
-      }
+    Assert ((last_action == (add_values ? 
+                             LastAction::add :
+                             LastAction::insert))
+            ||
+            (last_action == LastAction::none),
+           internal::VectorReference::ExcWrongMode ((add_values ? 
+                                                     LastAction::add :
+                                                     LastAction::insert),
+                                                    last_action));
 
                                     // VecSetValues complains if we
                                     // come with an empty
@@ -1153,9 +1148,7 @@ namespace PETScWrappers
        const int * petsc_indices = (const int*)indices;
 #endif
 
-       InsertMode mode = ADD_VALUES;
-       if (!add_values)
-         mode = INSERT_VALUES;
+       const InsertMode mode = (add_values ? ADD_VALUES : INSERT_VALUES);
        const int ierr
          = VecSetValues (vector, n_elements, petsc_indices, values,
                          mode);
@@ -1164,7 +1157,9 @@ namespace PETScWrappers
 
     // set the mode here, independent of whether we have actually
     // written elements or whether the list was empty
-    last_action = LastAction::insert;
+    last_action = (add_values ? 
+                   VectorBase::LastAction::add :
+                   VectorBase::LastAction::insert);
   }
 
 

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.