From 8dc0212bc02c57360fcbfb0cdd16ae2d913be745 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Tue, 24 Feb 2015 10:10:30 -0500 Subject: [PATCH] add compress() error checks for PETSc vectors --- include/deal.II/lac/petsc_vector_base.h | 4 ++-- source/lac/petsc_vector_base.cc | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/deal.II/lac/petsc_vector_base.h b/include/deal.II/lac/petsc_vector_base.h index 56c4286f8e..4d60dfb11a 100644 --- a/include/deal.II/lac/petsc_vector_base.h +++ b/include/deal.II/lac/petsc_vector_base.h @@ -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. diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index 44fe52e1b3..f9934c815c 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -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 -- 2.39.5