]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make the Vec type of PETScWrappers::MPI::Vector invariant.
authorDavid Wells <wellsd2@rpi.edu>
Sat, 29 Apr 2017 13:38:46 +0000 (09:38 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 29 Apr 2017 14:08:21 +0000 (10:08 -0400)
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.

doc/news/changes/minor/20170429DavidWells [new file with mode: 0644]
include/deal.II/lac/petsc_parallel_vector.h
source/lac/petsc_parallel_vector.cc

diff --git a/doc/news/changes/minor/20170429DavidWells b/doc/news/changes/minor/20170429DavidWells
new file mode 100644 (file)
index 0000000..98df64e
--- /dev/null
@@ -0,0 +1,3 @@
+Changed: The PETScWrappers::MPI::Vector class always corresponds to a PETSc
+vector with type <code>mpi</code>, even when empty.
+<br> (David Wells, 2017/03/29)
index 64adf0365574229bbf4ccc2b9310f39719f08fe2..fcd19d58bab6b74e2d17b546f4743008acd93903 100644 (file)
@@ -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())
index 80d4d1096f58913725fb1973dfdc83903901c2a4..5965ffaa938b77b488010487cedb04486463558d 100644 (file)
@@ -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);
     }
 
 

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.