From 2227afc20f966056180d178715508dd48ebab3a0 Mon Sep 17 00:00:00 2001 From: heister Date: Fri, 17 Jan 2014 22:46:29 +0000 Subject: [PATCH] fix all_zero() for PETSc vectors. add documentation for Trilinos as well. git-svn-id: https://svn.dealii.org/trunk@32242 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 6 ++++++ deal.II/include/deal.II/lac/parallel_vector.h | 5 ++--- .../include/deal.II/lac/petsc_parallel_vector.h | 8 ++++++++ deal.II/include/deal.II/lac/petsc_vector_base.h | 9 +++------ .../include/deal.II/lac/trilinos_vector_base.h | 6 +++--- deal.II/source/lac/petsc_parallel_vector.cc | 15 +++++++++++++++ deal.II/source/lac/petsc_vector_base.cc | 4 ++-- 7 files changed, 39 insertions(+), 14 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index aa8a9151e8..8fd8bc22e3 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -84,6 +84,12 @@ inconvenience this causes.

Specific improvements

    +
  1. 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. +
    + (Timo Heister, 2014/01/17) +
  2. Fixed: DoFCellAccessor::set_dof_values_by_interpolation and DoFCellAccessor::get_interpolated_dof_values could previously be diff --git a/deal.II/include/deal.II/lac/parallel_vector.h b/deal.II/include/deal.II/lac/parallel_vector.h index a93dccae5a..7ccb1f9743 100644 --- a/deal.II/include/deal.II/lac/parallel_vector.h +++ b/deal.II/include/deal.II/lac/parallel_vector.h @@ -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; diff --git a/deal.II/include/deal.II/lac/petsc_parallel_vector.h b/deal.II/include/deal.II/lac/petsc_parallel_vector.h index bc3ee07627..eaf007917a 100644 --- a/deal.II/include/deal.II/lac/petsc_parallel_vector.h +++ b/deal.II/include/deal.II/lac/petsc_parallel_vector.h @@ -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 diff --git a/deal.II/include/deal.II/lac/petsc_vector_base.h b/deal.II/include/deal.II/lac/petsc_vector_base.h index 6de405f3b5..403a8ec8eb 100644 --- a/deal.II/include/deal.II/lac/petsc_vector_base.h +++ b/deal.II/include/deal.II/lac/petsc_vector_base.h @@ -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; diff --git a/deal.II/include/deal.II/lac/trilinos_vector_base.h b/deal.II/include/deal.II/lac/trilinos_vector_base.h index 39b9b79991..3ed409cd87 100644 --- a/deal.II/include/deal.II/lac/trilinos_vector_base.h +++ b/deal.II/include/deal.II/lac/trilinos_vector_base.h @@ -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; diff --git a/deal.II/source/lac/petsc_parallel_vector.cc b/deal.II/source/lac/petsc_parallel_vector.cc index 848ba3eec1..ce866b663d 100644 --- a/deal.II/source/lac/petsc_parallel_vector.cc +++ b/deal.II/source/lac/petsc_parallel_vector.cc @@ -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, diff --git a/deal.II/source/lac/petsc_vector_base.cc b/deal.II/source/lac/petsc_vector_base.cc index 4166708d98..5f4bd0118c 100644 --- a/deal.II/source/lac/petsc_vector_base.cc +++ b/deal.II/source/lac/petsc_vector_base.cc @@ -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) { -- 2.39.5