From: David Wells Date: Sat, 29 Apr 2017 13:38:46 +0000 (-0400) Subject: Make the Vec type of PETScWrappers::MPI::Vector invariant. X-Git-Tag: v9.0.0-rc1~1638^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9337f1ae31f11a96fc0da47779656851615073e5;p=dealii.git Make the Vec type of PETScWrappers::MPI::Vector invariant. PETSc supports both sequential ('seq') and distributed ('mpi') vectors: since this vector is supposed to be distributed, we should always make it an MPI (or ghosted) vector to simplify this class. --- diff --git a/doc/news/changes/minor/20170429DavidWells b/doc/news/changes/minor/20170429DavidWells new file mode 100644 index 0000000000..98df64e2d4 --- /dev/null +++ b/doc/news/changes/minor/20170429DavidWells @@ -0,0 +1,3 @@ +Changed: The PETScWrappers::MPI::Vector class always corresponds to a PETSc +vector with type mpi, even when empty. +
(David Wells, 2017/03/29) diff --git a/include/deal.II/lac/petsc_parallel_vector.h b/include/deal.II/lac/petsc_parallel_vector.h index 64adf03655..fcd19d58ba 100644 --- a/include/deal.II/lac/petsc_parallel_vector.h +++ b/include/deal.II/lac/petsc_parallel_vector.h @@ -483,30 +483,6 @@ namespace PETScWrappers internal::VectorReference::ExcWrongMode (VectorOperation::unknown, last_action)); - - if (v.size()==0) - { - // this happens if v has not been initialized to something useful: - // Vector x,v; - // x=v; - // we skip the code below and create a simple serial vector of - // length 0 - -#if DEAL_II_PETSC_VERSION_LT(3,2,0) - PetscErrorCode ierr = VecDestroy (vector); -#else - PetscErrorCode ierr = VecDestroy (&vector); -#endif - AssertThrow (ierr == 0, ExcPETScError(ierr)); - - const int n = 0; - ierr = VecCreateSeq (PETSC_COMM_SELF, n, &vector); - AssertThrow (ierr == 0, ExcPETScError(ierr)); - ghosted = false; - ghost_indices.clear(); - return *this; - } - // if the vectors have different sizes, // then first resize the present one if (size() != v.size()) diff --git a/source/lac/petsc_parallel_vector.cc b/source/lac/petsc_parallel_vector.cc index 80d4d1096f..5965ffaa93 100644 --- a/source/lac/petsc_parallel_vector.cc +++ b/source/lac/petsc_parallel_vector.cc @@ -32,12 +32,7 @@ namespace PETScWrappers Vector::Vector () : communicator (MPI_COMM_SELF) { - // this is an invalid empty vector, so we can just as well create a - // sequential one to avoid all the overhead incurred by parallelism - const int n = 0; - const PetscErrorCode ierr = VecCreateSeq (PETSC_COMM_SELF, n, &vector); - AssertThrow (ierr == 0, ExcPETScError(ierr)); - ghosted = false; + create_vector(0, 0); } @@ -104,15 +99,10 @@ namespace PETScWrappers void Vector::clear () { - // destroy the PETSc Vec and create an invalid empty vector, - // so we can just as well create a sequential one to avoid - // all the overhead incurred by parallelism attained_ownership = true; VectorBase::clear (); - const int n = 0; - const PetscErrorCode ierr = VecCreateSeq (PETSC_COMM_SELF, n, &vector); - AssertThrow (ierr == 0, ExcPETScError(ierr)); + create_vector(0, 0); }