]> https://gitweb.dealii.org/ - dealii.git/commitdiff
fix all_zero() for PETSc vectors. add documentation for Trilinos as well.
authorTimo Heister <timo.heister@gmail.com>
Fri, 17 Jan 2014 22:46:29 +0000 (22:46 +0000)
committerTimo Heister <timo.heister@gmail.com>
Fri, 17 Jan 2014 22:46:29 +0000 (22:46 +0000)
git-svn-id: https://svn.dealii.org/trunk@32242 0785d39b-7218-0410-832d-ea1e28bc413d

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

index aa8a9151e8bd815aa225faff608b6aa31f874f4d..8fd8bc22e3db6cc0d10dec7b3c9a4fd1914cb603 100644 (file)
@@ -84,6 +84,12 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li> Fixed: PETScWrappers::MPI::Vector::all_zero() was broken with more than
+  one processor (illegal memory access) and did not communicate between all
+  processors. Documentation for many vector types of all_zero() has been extended.
+  <br>
+  (Timo Heister, 2014/01/17)
+  </li>
 
   <li> Fixed: DoFCellAccessor::set_dof_values_by_interpolation and
   DoFCellAccessor::get_interpolated_dof_values could previously be
index a93dccae5a7df90a0b7145731a1d10e89632e346..7ccb1f97434a8b7bd5ec7924c88dcd23c0d17a59 100644 (file)
@@ -427,9 +427,8 @@ namespace parallel
 
       /**
        * Return whether the vector contains only elements with value
-       * zero. This function is mainly for internal consistency checks and
-       * should seldom be used when not in debug mode since it uses quite some
-       * time.
+       * zero. This is a collective operation. This function is expensive, because
+       * potentially all elements have to be checked.
        */
       bool all_zero () const;
 
index bc3ee07627c093a25ead661bcce5079a2f395327..eaf007917a969a4d6141e04c1b293f3659c021c6 100644 (file)
@@ -502,6 +502,14 @@ namespace PETScWrappers
                   const bool          scientific = true,
                   const bool          across     = true) const;
 
+      /**
+       * @copydoc PETScWrappers::VectorBase::all_zero()
+       * 
+       * @note This function overloads the one in the base class
+       * to make this a collective operation.
+       */
+      bool all_zero () const;
+
     protected:
       /**
        * Create a vector of length
index 6de405f3b518b514b80cc14f808e4bf5d3f32c32..403a8ec8eb9401245f3e759199bc75f5408d3425 100644 (file)
@@ -626,12 +626,9 @@ namespace PETScWrappers
                       const VectorBase &v);
 
     /**
-     * Return whether the vector contains
-     * only elements with value zero. This
-     * function is mainly for internal
-     * consistency checks and should
-     * seldom be used when not in debug
-     * mode since it uses quite some time.
+     * Return whether the vector contains only elements with value
+     * zero. This is a collective operation. This function is expensive, because
+     * potentially all elements have to be checked.
      */
     bool all_zero () const;
 
index 39b9b79991326845a0c8fe756c3cc79273eb07b1..3ed409cd87569171cc604c6af726fa5168f016dd 100644 (file)
@@ -482,9 +482,9 @@ namespace TrilinosWrappers
     real_type linfty_norm () const;
 
     /**
-     * Return whether the vector contains only elements with value zero. This
-     * function is mainly for internal consistency checks and should seldom be
-     * used when not in debug mode since it uses quite some time.
+     * Return whether the vector contains only elements with value
+     * zero. This is a collective operation. This function is expensive, because
+     * potentially all elements have to be checked.
      */
     bool all_zero () const;
 
index 848ba3eec1eb0dfd0a7c9db2b2f677783abf6e01..ce866b663dc79fdc3ca8de275630ec4b40963ed8 100644 (file)
@@ -359,6 +359,21 @@ namespace PETScWrappers
 
 
 
+    bool
+    Vector::all_zero() const
+    {
+      unsigned int has_nonzero = VectorBase::all_zero()?0:1;
+#ifdef DEAL_II_WITH_MPI
+    // in parallel, check that the vector
+    // is zero on _all_ processors.
+    unsigned int num_nonzero = Utilities::MPI::sum(has_nonzero, communicator);
+    return num_nonzero == 0;
+#else
+    return has_nonzero == 0;
+#endif
+    }
+
+
     void
     Vector::print (std::ostream      &out,
                    const unsigned int precision,
index 4166708d9801a3fe01058e5d059e3d18351de609..5f4bd0118c421fd838540fd4f2dd673ae9614aa4 100644 (file)
@@ -662,7 +662,7 @@ namespace PETScWrappers
     AssertThrow (ierr == 0, ExcPETScError(ierr));
 
     const PetscScalar *ptr  = start_ptr,
-                       *eptr = start_ptr + size();
+                       *eptr = start_ptr + local_size();
     bool flag = true;
     while (ptr != eptr)
       {
@@ -715,7 +715,7 @@ namespace PETScWrappers
     AssertThrow (ierr == 0, ExcPETScError(ierr));
 
     const PetscScalar *ptr  = start_ptr,
-                       *eptr = start_ptr + size();
+                       *eptr = start_ptr + local_size();
     bool flag = true;
     while (ptr != eptr)
       {

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.