]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a clear function for PETSc serial and parallel vectors 947/head
authormsteigemann <msteigemann@yahoo.de>
Thu, 21 May 2015 05:53:24 +0000 (07:53 +0200)
committermsteigemann <msteigemann@yahoo.de>
Sat, 23 May 2015 05:04:38 +0000 (07:04 +0200)
doc/news/changes.h
include/deal.II/lac/petsc_parallel_vector.h
include/deal.II/lac/petsc_vector.h
include/deal.II/lac/petsc_vector_base.h
source/lac/petsc_parallel_vector.cc
source/lac/petsc_vector.cc
source/lac/petsc_vector_base.cc

index 1d9097ce2931ed68d34d9ff38b60bb65698a8841..82eb39000980ff14d2957054e11aaa101d99a353 100644 (file)
@@ -512,6 +512,12 @@ inconvenience this causes.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li> New: Add a clear function to the PETSc::Vector
+  and PETSc::MPI::Vector classes similar to the Trilinos vector classes.
+  <br>
+  (Martin Steigemann 2015/05/22)
+  </li>
+
   <li> New: Three new quadrature formulas in quadrature_lib, based on
   Chebyshev quadrature rules. See functions QGaussChebyshev,
   QGaussRadauChebyshev and QGaussLobattoChebyshev.
index 1b987c3417474b138ac08126b0888f264a125e00..ca7a3449dbcbf8e68a1cfce027b615bfe3441eac 100644 (file)
@@ -262,6 +262,12 @@ namespace PETScWrappers
       explicit Vector (const IndexSet &local,
                        const MPI_Comm &communicator);
 
+      /**
+       * Release all memory and return to a state just like after having called
+       * the default constructor.
+       */
+      void clear ();
+
       /**
        * Copy the given vector. Resize the present vector if necessary. Also
        * take over the MPI communicator of @p v.
index c923ffc22e8ff3b8ea8870c9a7ace37704a55994..5c907f0f83a596b0ec4c990a86daad9bea21c672 100644 (file)
@@ -118,6 +118,12 @@ namespace PETScWrappers
      */
     explicit Vector (const MPI::Vector &v);
 
+    /**
+     * Release all memory and return to a state just like after having called
+     * the default constructor.
+     */
+    void clear ();
+
     /**
      * Copy the given vector. Resize the present vector if necessary.
      */
index 4d60dfb11a1b7f17784110a835bb2b9f9e56fe40..e17617ef06c257ee36f13e3970a5eb7a3f43f734 100644 (file)
@@ -260,6 +260,12 @@ namespace PETScWrappers
      */
     virtual ~VectorBase ();
 
+    /**
+     * Release all memory and return to a state just like after having called
+     * the default constructor.
+     */
+    virtual void clear ();
+
     /**
      * Compress the underlying representation of the PETSc object, i.e. flush
      * the buffers of the vector object if it has any. This function is
index 87fde1ad6e71f3c4a8c3eac39ceccd7482541cb4..5037b9fc6447acbbe0ce6a556adf8f8ccb3edc1f 100644 (file)
@@ -80,6 +80,7 @@ namespace PETScWrappers
     }
 
 
+
     Vector::Vector (const IndexSet   &local,
                     const MPI_Comm     &communicator)
       :
@@ -90,6 +91,23 @@ 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;
+      int ierr = VecCreateSeq (PETSC_COMM_SELF, n, &vector);
+      AssertThrow (ierr == 0, ExcPETScError(ierr));
+    }
+
+
+
     void
     Vector::reinit (const MPI_Comm  &comm,
                     const size_type  n,
index 0cf745a7b200a4c1deee1db35765e984c90d51ef..8baa0aeecf7209154965f040a5fadda00256ce02 100644 (file)
@@ -61,6 +61,15 @@ namespace PETScWrappers
 
 
 
+  void
+  Vector::clear ()
+  {
+    VectorBase::clear ();
+    Vector::create_vector (0);
+  }
+
+
+
   void
   Vector::reinit (const size_type n,
                   const bool      fast)
index b127024d25de8592ce0a843c19251a26f6f756c7..0feeaef91a33185c0530bf845dd2ced36341a423 100644 (file)
@@ -210,6 +210,27 @@ namespace PETScWrappers
 
 
 
+  void
+  VectorBase::clear ()
+  {
+    if (attained_ownership)
+      {
+#if DEAL_II_PETSC_VERSION_LT(3,2,0)
+        const int ierr = VecDestroy (vector);
+#else
+        const int ierr = VecDestroy (&vector);
+#endif
+        AssertThrow (ierr == 0, ExcPETScError(ierr));
+      }
+
+    ghosted = false;
+    ghost_indices.clear ();
+    last_action = ::dealii::VectorOperation::unknown;
+    attained_ownership = true;
+  }
+
+
+
   VectorBase &
   VectorBase::operator = (const PetscScalar s)
   {

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.