]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
merge: unify compress() for linear algebra objects
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 14 Aug 2012 14:58:40 +0000 (14:58 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 14 Aug 2012 14:58:40 +0000 (14:58 +0000)
git-svn-id: https://svn.dealii.org/trunk@25986 0785d39b-7218-0410-832d-ea1e28bc413d

24 files changed:
deal.II/doc/doxygen/headers/distributed.h
deal.II/doc/doxygen/headers/glossary.h
deal.II/doc/news/changes.h
deal.II/include/deal.II/lac/block_matrix_base.h
deal.II/include/deal.II/lac/block_vector.h
deal.II/include/deal.II/lac/block_vector_base.h
deal.II/include/deal.II/lac/parallel_vector.h
deal.II/include/deal.II/lac/petsc_matrix_base.h
deal.II/include/deal.II/lac/petsc_parallel_vector.h
deal.II/include/deal.II/lac/petsc_vector.h
deal.II/include/deal.II/lac/petsc_vector_base.h
deal.II/include/deal.II/lac/trilinos_block_sparse_matrix.h
deal.II/include/deal.II/lac/trilinos_block_vector.h
deal.II/include/deal.II/lac/trilinos_parallel_block_vector.h
deal.II/include/deal.II/lac/trilinos_sparse_matrix.h
deal.II/include/deal.II/lac/trilinos_vector_base.h
deal.II/include/deal.II/lac/vector.h
deal.II/include/deal.II/numerics/vector_tools.templates.h
deal.II/source/distributed/solution_transfer.cc
deal.II/source/lac/constraint_matrix.cc
deal.II/source/lac/petsc_matrix_base.cc
deal.II/source/lac/petsc_vector_base.cc
deal.II/source/lac/trilinos_block_sparse_matrix.cc
deal.II/source/lac/trilinos_block_vector.cc

index b549dd4c8389249302d01e3085c380a809240576..f5ff673c460cb317619d9180139329ced9bf3ac1 100644 (file)
  * too many details. All the algorithms described below are implement in
  * classes and functions in namespace parallel::distributed.
  *
+ * One important aspect in parallel computations using MPI is that write
+ * access to matrix and vector elements requires a call to compress() after
+ * the operation is finished and before the object is used (for example read
+ * from). Also see @ref GlossCompress.
  *
  * <h4>Other resources</h4>
  *
index 008ed4e1e481bdb4fabb2018b45f820746a9f0c3..f1129b7982aad4675fe357d1efb6a1575a565a1b 100644 (file)
@@ -1,3 +1,4 @@
+
 //-------------------------------------------------------------------------
 //    $Id$
 //    Version: $Name$
  * ways:
  *
  * - You tell the object that you want to compress what operation is
- *   intended. The TrilinosWrappers::VectorBase::compress() can take
- *   such an additional argument.
+ *   intended. This can be done using the VectorOperation argument in
+ *   the various compress() functions.
  * - You do a fake addition or set operation on the object in question. For
  *   example, you can add a zero to an element of the matrix or vector,
  *   which has no effect other than telling the object that the next
index 1c45b5f3cd487b6ee20672fb9ffe83439efde58f..1e8ca84a17a8ecfa79e11c2dde5612931ed131db 100644 (file)
@@ -62,6 +62,14 @@ used to store boundary indicators internally.
 
 
 <ol>
+<li>
+Changed: unify the concept of compress() for all linear algebra
+objects. Introduce type VectorOperation to decide between
+add and insert. Implement also for serial vectors. Note:
+this breaks distributed::vector::compress(bool).
+<br>
+(Timo Heister, 2012/08/13)
+
 <li>
 Changed: Support for the METIS 4.x has been replaced with support for
 METIS 5.x. Use <code>--with-metis=path/to/metis</code> to configure
index c910989653fcf4f58345ae2b64f81c80c7141d32..8f68491ec64a12a3e638c156a56bdd74a0447815 100644 (file)
@@ -22,6 +22,7 @@
 #include <deal.II/lac/exceptions.h>
 #include <deal.II/lac/full_matrix.h>
 #include <deal.II/lac/matrix_iterator.h>
+#include <deal.II/lac/vector.h>
 
 #include <cmath>
 
@@ -736,8 +737,14 @@ class BlockMatrixBase : public Subscriptor
                                      /**
                                       * Call the compress() function on all
                                       * the subblocks of the matrix.
+                                     *
+                                     *
+                                     * See @ref GlossCompress "Compressing
+                                     * distributed objects" for more
+                                     * information.
                                       */
-    void compress ();
+    void compress (::dealii::VectorOperation::values operation
+                  =::dealii::VectorOperation::unknown);
 
                                      /**
                                       * Multiply the entire matrix by a
@@ -2316,11 +2323,11 @@ BlockMatrixBase<MatrixType>::diag_element (const unsigned int i) const
 template <class MatrixType>
 inline
 void
-BlockMatrixBase<MatrixType>::compress ()
+BlockMatrixBase<MatrixType>::compress (::dealii::VectorOperation::values operation)
 {
   for (unsigned int r=0; r<n_block_rows(); ++r)
     for (unsigned int c=0; c<n_block_cols(); ++c)
-      block(r,c).compress ();
+      block(r,c).compress (operation);
 }
 
 
index 7344af92cd5a0bb64b4eb130150eca76c8c74c0f..800e4cf5e0b522c354fcd0d85c99ab9c44c22078 100644 (file)
@@ -194,6 +194,22 @@ class BlockVector : public BlockVectorBase<Vector<Number> >
                                       */
     ~BlockVector ();
 
+                                     /**
+                                      * Call the compress() function on all
+                                      * the subblocks.
+                                     *
+                                     * This functionality only needs to be
+                                     * called if using MPI based vectors and
+                                     * exists in other objects for
+                                     * compatibility.
+                                     *
+                                     * See @ref GlossCompress "Compressing
+                                     * distributed objects" for more
+                                     * information.
+                                      */
+    void compress (::dealii::VectorOperation::values operation
+                  =::dealii::VectorOperation::unknown);
+
                                      /**
                                       * Copy operator: fill all components of
                                       * the vector with the given scalar
@@ -523,6 +539,14 @@ BlockVector<Number>::operator = (const BlockVector<Number2> &v)
   return *this;
 }
 
+template <typename Number>
+inline
+void BlockVector<Number>::compress (::dealii::VectorOperation::values operation)
+{
+  for (unsigned int i=0; i<this->n_blocks();++i)
+    this->components[i].compress(operation);
+}
+
 
 
 template <typename Number>
index f984a739a29d4e7a6a45614ec905f91368daf46f..dff90420e117fc48ec8a702166fb8f6a196b3a12 100644 (file)
@@ -787,8 +787,19 @@ class BlockVectorBase : public Subscriptor
                                      /**
                                       * Call the compress() function on all
                                       * the subblocks of the matrix.
+                                     *
+                                     * This functionality only needs to be
+                                     * called if using MPI based vectors and
+                                     * exists in other objects for
+                                     * compatibility.
+                                     *
+                                     * See @ref GlossCompress "Compressing
+                                     * distributed objects" for more
+                                     * information.
                                       */
-    void compress ();
+    void compress (::dealii::VectorOperation::values operation
+                    =::dealii::VectorOperation::unknown);
+    
 
                                      /**
                                       * Access to a single block.
@@ -1824,10 +1835,10 @@ BlockVectorBase<VectorType>::collect_sizes ()
 template <class VectorType>
 inline
 void
-BlockVectorBase<VectorType>::compress ()
+BlockVectorBase<VectorType>::compress (::dealii::VectorOperation::values operation)
 {
   for (unsigned int i=0; i<n_blocks(); ++i)
-    block(i).compress ();
+    block(i).compress (operation);
 }
 
 
index 2ae2dc5dfc90efd929ea8af1762cc3015581857e..e28dbc101fdf0ef87806ee20135d3af0c51b964d 100644 (file)
@@ -285,25 +285,17 @@ namespace parallel
                                          /**
                                           * This function copies the data that has
                                           * accumulated in the data buffer for ghost
-                                          * indices to the owning processor. If the
-                                          * optional argument @p add_ghost_data is set
-                                          * to true, the data is added into the
-                                          * respective positions of the owning
-                                          * processor, otherwise the new data
-                                          * overwrites the old content in the host
-                                          * vector. In that case, data coming from
-                                          * different processor to the same target
-                                          * entry should be identical. However, no
-                                          * checking is performed, so it is the user's
-                                          * responsibility to ensure consistency of
-                                          * data.
+                                          * indices to the owning processor. 
                                           *
-                                          * For the meaning of this argument, see the
-                                          * entry on
-                                          * @ref GlossCompress "Compressing distributed vectors and matrices"
+                                          * For the meaning of this argument,
+                                          * see the entry on @ref
+                                          * GlossCompress "Compressing
+                                          * distributed vectors and matrices"
                                           * in the glossary.
                                           */
-        void compress (const bool add_ghost_data = true);
+       void compress (::dealii::VectorOperation::values operation
+                      =::dealii::VectorOperation::unknown);
+
 
                                          /**
                                           * Fills the data field for ghost indices with
@@ -1137,10 +1129,13 @@ namespace parallel
     template <typename Number>
     inline
     void
-    Vector<Number>::compress (const bool add_ghost_data)
+    Vector<Number>::compress (::dealii::VectorOperation::values operation)
     {
       compress_start ();
-      compress_finish (add_ghost_data);
+      if (operation == ::dealii::VectorOperation::insert)
+       compress_finish (false);
+      else
+       compress_finish (true);
     }
 
 
index 727eee8567714bf134be7d103c10e6c6bd9fa7ed..e8b352e46f3fafad04e5b94a8f473860961904b4 100644 (file)
@@ -20,6 +20,7 @@
 #  include <deal.II/base/subscriptor.h>
 #  include <deal.II/lac/full_matrix.h>
 #  include <deal.II/lac/exceptions.h>
+#  include <deal.II/lac/vector.h>
 
 #  include <petscmat.h>
 #  include <deal.II/base/std_cxx1x/shared_ptr.h>
@@ -671,8 +672,8 @@ namespace PETScWrappers
                                         * for more information.
                                         * more information.
                                         */
-      void compress ();
-
+      void compress (::dealii::VectorOperation::values operation
+                    =::dealii::VectorOperation::unknown);
                                        /**
                                         * Return the value of the entry
                                         * (<i>i,j</i>).  This may be an
index d7f40bfbcf83e679655f2c73e73b32096546bfc6..df431183bd0e040d7cd3eabf94f12c8caeac8828 100644 (file)
@@ -543,7 +543,7 @@ namespace PETScWrappers
       for (unsigned int i=0; i<v.size(); ++i)
         (*this)(i) = v(i);
 
-      compress ();
+      compress (::dealii::VectorOperation::insert);
 
       return *this;
     }
index 5c34f2bd0ad71a00339538e5ac9cbcb6ea1c10de..cdee29885419ff88a80f0bd5a3780cc4b7194ac8 100644 (file)
@@ -399,7 +399,7 @@ namespace PETScWrappers
     for (unsigned int i=0; i<v.size(); ++i)
       (*this)(i) = v(i);
 
-    compress ();
+    compress (::dealii::VectorOperation::insert);
 
     return *this;
   }
index a5df5e3d60b4e5710ec9af748dbc466dbb28b2bb..808ccf1c09e1e1e201a3331c3d6b73ac5095c694 100644 (file)
@@ -19,6 +19,7 @@
 
 #  include <deal.II/base/subscriptor.h>
 #  include <deal.II/lac/exceptions.h>
+#  include <deal.II/lac/vector.h>
 
 #  include <vector>
 #  include <utility>
@@ -294,9 +295,9 @@ namespace PETScWrappers
                                         *
                                         * See @ref GlossCompress "Compressing distributed objects"
                                         * for more information.
-                                        * more information.
                                         */
-      void compress ();
+      void compress (::dealii::VectorOperation::values operation
+                    =::dealii::VectorOperation::unknown);
 
                                        /**
                                         * Set all components of the vector to
@@ -823,33 +824,6 @@ namespace PETScWrappers
                                         */
       IndexSet ghost_indices;
 
-                                       /**
-                                        * PETSc doesn't allow to mix additions
-                                        * to matrix entries and overwriting
-                                        * them (to make synchronisation of
-                                        * parallel computations
-                                        * simpler). Since the interface of the
-                                        * existing classes don't support the
-                                        * notion of not interleaving things,
-                                        * we have to emulate this
-                                        * ourselves. The way we do it is to,
-                                        * for each access operation, store
-                                        * whether it is an insertion or an
-                                        * addition. If the previous one was of
-                                        * different type, then we first have
-                                        * to flush the PETSc buffers;
-                                        * otherwise, we can simply go on.
-                                        *
-                                        * The following structure and variable
-                                        * declare and store the previous
-                                        * state.
-                                        */
-      struct LastAction
-      {
-          enum Values { none, insert, add };
-      };
-
-
                                        /**
                                         * Store whether the last action was a
                                         * write or add operation. This
@@ -858,7 +832,7 @@ namespace PETScWrappers
                                         * even though the vector object they
                                         * refer to is constant.
                                         */
-      mutable LastAction::Values last_action;
+      mutable ::dealii::VectorOperation::values last_action;
 
                                        /**
                                         * Make the reference class a friend.
@@ -954,10 +928,10 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator = (const PetscScalar &value) const
     {
-      Assert ((vector.last_action == VectorBase::LastAction::insert)
+      Assert ((vector.last_action == VectorOperation::insert)
               ||
-              (vector.last_action == VectorBase::LastAction::none),
-              ExcWrongMode (VectorBase::LastAction::insert,
+              (vector.last_action == VectorOperation::unknown),
+              ExcWrongMode (VectorOperation::insert,
                             vector.last_action));
 
 #ifdef PETSC_USE_64BIT_INDICES
@@ -970,7 +944,7 @@ namespace PETScWrappers
         = VecSetValues (vector, 1, &petsc_i, &value, INSERT_VALUES);
       AssertThrow (ierr == 0, ExcPETScError(ierr));
 
-      vector.last_action = VectorBase::LastAction::insert;
+      vector.last_action = VectorOperation::insert;
 
       return *this;
     }
@@ -981,13 +955,13 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator += (const PetscScalar &value) const
     {
-      Assert ((vector.last_action == VectorBase::LastAction::add)
+      Assert ((vector.last_action == VectorOperation::add)
               ||
-              (vector.last_action == VectorBase::LastAction::none),
-              ExcWrongMode (VectorBase::LastAction::add,
+              (vector.last_action == VectorOperation::unknown),
+              ExcWrongMode (VectorOperation::add,
                             vector.last_action));
 
-      vector.last_action = VectorBase::LastAction::add;
+      vector.last_action = VectorOperation::add;
 
                                        // we have to do above actions in any
                                        // case to be consistent with the MPI
@@ -1019,13 +993,13 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator -= (const PetscScalar &value) const
     {
-      Assert ((vector.last_action == VectorBase::LastAction::add)
+      Assert ((vector.last_action == VectorOperation::add)
               ||
-              (vector.last_action == VectorBase::LastAction::none),
-              ExcWrongMode (VectorBase::LastAction::add,
+              (vector.last_action == VectorOperation::unknown),
+              ExcWrongMode (VectorOperation::add,
                             vector.last_action));
 
-      vector.last_action = VectorBase::LastAction::add;
+      vector.last_action = VectorOperation::add;
 
                                        // we have to do above actions in any
                                        // case to be consistent with the MPI
@@ -1058,13 +1032,13 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator *= (const PetscScalar &value) const
     {
-      Assert ((vector.last_action == VectorBase::LastAction::insert)
+      Assert ((vector.last_action == VectorOperation::insert)
               ||
-              (vector.last_action == VectorBase::LastAction::none),
-              ExcWrongMode (VectorBase::LastAction::insert,
+              (vector.last_action == VectorOperation::unknown),
+              ExcWrongMode (VectorOperation::insert,
                             vector.last_action));
 
-      vector.last_action = VectorBase::LastAction::insert;
+      vector.last_action = VectorOperation::insert;
 
                                        // we have to do above actions in any
                                        // case to be consistent with the MPI
@@ -1098,13 +1072,13 @@ namespace PETScWrappers
     const VectorReference &
     VectorReference::operator /= (const PetscScalar &value) const
     {
-      Assert ((vector.last_action == VectorBase::LastAction::insert)
+      Assert ((vector.last_action == VectorOperation::insert)
               ||
-              (vector.last_action == VectorBase::LastAction::none),
-              ExcWrongMode (VectorBase::LastAction::insert,
+              (vector.last_action == VectorOperation::unknown),
+              ExcWrongMode (VectorOperation::insert,
                             vector.last_action));
 
-      vector.last_action = VectorBase::LastAction::insert;
+      vector.last_action = VectorOperation::insert;
 
                                        // we have to do above actions in any
                                        // case to be consistent with the MPI
index 20034ccfc487c7fb160b7327d7e4b5d71a5b8eab..767c2082a479afe4fa6a680ec37e437fd310e2b1 100644 (file)
@@ -246,20 +246,6 @@ namespace TrilinosWrappers
       void reinit (const ::dealii::BlockSparseMatrix<double> &deal_ii_sparse_matrix,
                    const double                               drop_tolerance=1e-13);
 
-                                       /**
-                                        * This function calls the compress()
-                                        * command of all matrices after
-                                        * the assembly is
-                                        * completed. Note that all MPI
-                                        * processes need to call this
-                                        * command (whereas the individual
-                                        * assembly routines will most probably
-                                        * only be called on each processor
-                                        * individually) before any
-                                        * can complete it.
-                                        */
-      void compress ();
-
                                        /**
                                         * Returns the state of the
                                         * matrix, i.e., whether
index 61017fd564a33c5ab677721227ca7951214ea663..a5c22e2d03c70406013af7f0bd9a70725cbf3b2c 100644 (file)
@@ -186,6 +186,22 @@ namespace TrilinosWrappers
                                         */
       ~BlockVector ();
 
+                                      /**
+                                       * use compress(VectorOperation) instead
+                                       *
+                                       * @deprecated
+                                       *
+                                       * See @ref GlossCompress "Compressing
+                                       * distributed objects" for more
+                                       * information.
+                                       */
+      void compress (const Epetra_CombineMode last_action);
+      
+                                        /**
+                                         * so it is not hidden
+                                         */
+      using BlockVectorBase<Vector>::compress;
+
                                        /**
                                         * Copy operator: fill all
                                         * components of the vector that
@@ -503,6 +519,21 @@ namespace TrilinosWrappers
   }
 
 
+  inline
+  void
+  BlockVector::compress (const Epetra_CombineMode last_action)
+  {
+    ::dealii::VectorOperation::values last_action_;
+    if (last_action == Add)
+      last_action_ = ::dealii::VectorOperation::add;
+    else if (last_action == Insert)
+      last_action_ = ::dealii::VectorOperation::insert;
+    else
+      AssertThrow(false, ExcNotImplemented());
+
+    this->compress(last_action_);
+  }
+
   inline
   void
   BlockVector::swap (BlockVector &v)
index c18190c41004cd72bfa7a60bb5fc559883605625..841b0081161042c0f1f471f4ac098e6000447be9 100644 (file)
@@ -306,36 +306,23 @@ namespace TrilinosWrappers
         void import_nonlocal_data_for_fe (const TrilinosWrappers::BlockSparseMatrix &m,
                                           const BlockVector                         &v);
 
-                                         /**
-                                          * Compress the underlying
-                                          * representation of the Trilinos
-                                          * object, i.e. flush the buffers
-                                          * of the vector object if it has
-                                          * any. This function is
-                                          * necessary after writing into a
-                                          * vector element-by-element and
-                                          * before anything else can be
-                                          * done on it.
-                                          *
-                                          * The (defaulted) argument can
-                                          * be used to specify the
-                                          * compress mode
-                                          * (<code>Add</code> or
-                                          * <code>Insert</code>) in case
-                                          * the vector has not been
-                                          * written to since the last
-                                          * time this function was
-                                          * called. The argument is
-                                          * ignored if the vector has
-                                          * been added or written to
-                                          * since the last time
-                                          * compress() was called.
-                                          *
-                                          * See @ref GlossCompress "Compressing distributed objects"
-                                          * for more information.
-                                          * more information.
-                                          */
-        void compress (const Epetra_CombineMode last_action = Zero);
+
+                                        /**
+                                         * use compress(VectorOperation) instead
+                                         *
+                                         * @deprecated
+                                         *
+                                         * See @ref GlossCompress "Compressing
+                                         * distributed objects" for more
+                                         * information.
+                                         */
+       void compress (const Epetra_CombineMode last_action);
+       
+                                        /**
+                                         * so it is not hidden
+                                         */
+       using BlockVectorBase<Vector>::compress;
+
 
                                          /**
                                           * Returns the state of the
@@ -471,6 +458,23 @@ namespace TrilinosWrappers
 
 
 
+    inline
+    void
+    BlockVector::compress (const Epetra_CombineMode last_action)
+    {
+      ::dealii::VectorOperation::values last_action_;
+      if (last_action == Add)
+       last_action_ = ::dealii::VectorOperation::add;
+      else if (last_action == Insert)
+       last_action_ = ::dealii::VectorOperation::insert;
+      else
+       AssertThrow(false, ExcNotImplemented());
+      
+      this->compress(last_action_);
+    }
+
+    
+
     template <typename Number>
     BlockVector &
     BlockVector::operator = (const ::dealii::BlockVector<Number> &v)
index ef463416db273f5382ed93ac355a77e00ada2566..696d0e8e4b5986017b136d97e345c3f1f0ae5aba 100644 (file)
@@ -1163,7 +1163,8 @@ namespace TrilinosWrappers
                                         * See @ref GlossCompress "Compressing distributed objects"
                                         * for more information.
                                         */
-      void compress ();
+      void compress (::dealii::VectorOperation::values operation
+                    =::dealii::VectorOperation::unknown);
 
                                        /**
                                         * Set the element (<i>i,j</i>)
@@ -2588,7 +2589,7 @@ namespace TrilinosWrappers
 
   inline
   void
-  SparseMatrix::compress ()
+  SparseMatrix::compress (::dealii::VectorOperation::values operation)
   {
                                   // flush buffers
     int ierr;
index 549bc76afbd10f389f9995ea860aa6b81ae1925a..2b462a77078832e6f1825d6c5bd97b7a590f789c 100644 (file)
@@ -344,9 +344,14 @@ namespace TrilinosWrappers
                                         *
                                         * See @ref GlossCompress "Compressing distributed objects"
                                         * for more information.
-                                        * more information.
                                         */
-      void compress (const Epetra_CombineMode last_action = Zero);
+      void compress (::dealii::VectorOperation::values operation
+                    =::dealii::VectorOperation::unknown);
+
+                                      /**
+                                       * @deprecated
+                                       */
+      void compress (const Epetra_CombineMode last_action);
 
                                        /**
                                         * Returns the state of the
@@ -1204,10 +1209,42 @@ namespace TrilinosWrappers
 
   inline
   void
-  VectorBase::compress (const Epetra_CombineMode given_last_action)
+  VectorBase::compress (const Epetra_CombineMode last_action)
   {
-    Epetra_CombineMode mode = (last_action != Zero) ?
-                              last_action : given_last_action;
+    ::dealii::VectorOperation::values last_action_;
+    if (last_action == Add)
+      last_action_ = ::dealii::VectorOperation::add;
+    else if (last_action == Insert)
+      last_action_ = ::dealii::VectorOperation::insert;
+    else
+      AssertThrow(false, ExcNotImplemented());
+
+    compress(last_action_);
+  }
+  
+
+
+  inline
+  void
+  VectorBase::compress (::dealii::VectorOperation::values given_last_action)
+  {
+                                    //Select which mode to send to
+                                    //Trilinos. Note that we use last_action
+                                    //if available and ignore what the user
+                                    //tells us to detect wrongly mixed
+                                    //operations. Typically given_last_action
+                                    //is only used on machines that do not
+                                    //execute an operation (because they have
+                                    //no own cells for example).
+    Epetra_CombineMode mode = last_action;
+    if (last_action == Zero)
+      {
+       if (given_last_action==::dealii::VectorOperation::add)
+         mode = Add;
+       else if (given_last_action==::dealii::VectorOperation::insert)
+         mode = Insert;
+      }
+
 #ifdef DEBUG
 #  ifdef DEAL_II_COMPILER_SUPPORTS_MPI
                                      // check that every process has decided
index 2500fc913df7c0f81d7576592027c4265948fb4f..5e232a756a33cd07809e8afaa9365849b5737d70 100644 (file)
@@ -65,6 +65,21 @@ template <typename> class VectorView;
  *@{
  */
 
+/**
+ * This enum keeps track of the current operation in parallel linear algebra
+ * objects like Vectors and Matrices.
+ *
+ * It is used in the various compress() functions. They also exist in serial
+ * codes for compatibility and are empty there.
+ *
+ * See @ref GlossCompress "Compressing distributed objects" for more
+ * information.
+ */
+struct VectorOperation
+{
+    enum values { unknown, insert, add };
+};
+
 
 /**
  * Numerical vector of data.  For this class there are different types
@@ -297,7 +312,8 @@ class Vector : public Subscriptor
                                       * this class, it is immaterial and thus
                                       * an empty function.
                                       */
-    void compress () const;
+    void compress (::dealii::VectorOperation::values operation
+                  =::dealii::VectorOperation::unknown) const;
 
                                      /**
                                       * Change the dimension of the vector to
@@ -1495,7 +1511,7 @@ Vector<Number>::operator != (const Vector<Number2>& v) const
 template <typename Number>
 inline
 void
-Vector<Number>::compress () const
+Vector<Number>::compress (::dealii::VectorOperation::values) const
 {}
 
 
index 190b8866e729277e07a4c5777ad8ece7212a2320..673e069acc716b07d73ae9632cd0f9fa56acb4fc 100644 (file)
@@ -259,6 +259,7 @@ namespace VectorTools
                   = function_values_scalar[fe_index][dof_to_rep_index_table[fe_index][i]];
             }
         }
+    vec.compress(::dealii::VectorOperation::insert);    
   }
 
 
index 8022f743c3620449f657afa6dfe62cba53f33930..11e46f6551b9f247c80e99fbbf18d10ad37e39f3 100644 (file)
@@ -40,41 +40,6 @@ namespace parallel
   namespace distributed
   {
 
-    namespace
-    {
-      template <class VECTOR>
-      void compress_vector_insert(VECTOR & vec)
-      {
-        vec.compress();
-      }
-
-#ifdef DEAL_II_USE_TRILINOS
-      void compress_vector_insert(TrilinosWrappers::Vector & vec)
-      {
-        vec.compress(Insert);
-      }
-
-      void compress_vector_insert(TrilinosWrappers::BlockVector & vec)
-      {
-        for (unsigned int i=0;i<vec.n_blocks();++i)
-          vec.block(i).compress(Insert);
-      }
-
-      void compress_vector_insert(TrilinosWrappers::MPI::Vector & vec)
-      {
-        vec.compress(Insert);
-      }
-
-      void compress_vector_insert(TrilinosWrappers::MPI::BlockVector & vec)
-      {
-        for (unsigned int i=0;i<vec.n_blocks();++i)
-          vec.block(i).compress(Insert);
-      }
-#endif
-    }
-
-
-
     template<int dim, typename VECTOR, class DH>
     SolutionTransfer<dim, VECTOR, DH>::SolutionTransfer(const DH &dof)
                     :
@@ -206,10 +171,11 @@ namespace parallel
                                                    std_cxx1x::_3,
                                                    std_cxx1x::ref(all_out)));
 
+      
       for (typename std::vector<VECTOR*>::iterator it=all_out.begin();
            it !=all_out.end();
            ++it)
-        compress_vector_insert(*(*it));
+       (*it)->compress(::dealii::VectorOperation::insert);
 
       input_vectors.clear();
     }
index 55df9b2a4bbebdedf694bc81241a4ace9f1c4594..51befc61459dffdadb68460d3e4bb7246145b028 100644 (file)
@@ -1922,7 +1922,7 @@ ConstraintMatrix::distribute (TrilinosWrappers::MPI::Vector &vec) const
                                    // constraints, so we need to explicitly
                                    // state, that the others are doing an
                                    // insert here:
-  vec.compress (Insert);
+  vec.compress (::dealii::VectorOperation::insert);
 }
 
 
@@ -2016,7 +2016,7 @@ ConstraintMatrix::distribute (TrilinosWrappers::MPI::BlockVector &vec) const
                           it->entries[i].second);
           vec(it->line) = new_value;
         }
-      vec.block(block).compress(Insert);
+      vec.block(block).compress(::dealii::VectorOperation::insert);
     }
 }
 
index e0e3220c2f63bb435c1ff6eebc89cb58337e58dc..605aecf2b0ac67756efc315d531fcb721001743c 100644 (file)
@@ -275,7 +275,7 @@ namespace PETScWrappers
 
 
   void
-  MatrixBase::compress ()
+  MatrixBase::compress (::dealii::VectorOperation::values operation)
   {
                                      // flush buffers
     int ierr;
index 6820ff126a9d01189e2a0884d25b36738203dec1..77bff1b40d55f94f8cfb27c0cd4374c10066c0c7 100644 (file)
@@ -177,7 +177,7 @@ namespace PETScWrappers
   VectorBase::VectorBase ()
                   :
                   ghosted(false),
-                  last_action (LastAction::none),
+                  last_action (::dealii::VectorOperation::unknown),
                   attained_ownership(true)
   {}
 
@@ -188,7 +188,7 @@ namespace PETScWrappers
                   Subscriptor (),
                   ghosted(v.ghosted),
                   ghost_indices(v.ghost_indices),
-                  last_action (LastAction::none),
+                  last_action (::dealii::VectorOperation::unknown),
                   attained_ownership(true)
   {
     int ierr = VecDuplicate (v.vector, &vector);
@@ -205,7 +205,7 @@ namespace PETScWrappers
                   Subscriptor (),
                   vector(v),
                   ghosted(false),
-                  last_action (LastAction::none),
+                  last_action (::dealii::VectorOperation::unknown),
                   attained_ownership(false)
   {}
 
@@ -405,15 +405,14 @@ namespace PETScWrappers
 
 
   void
-  VectorBase::compress ()
+  VectorBase::compress (::dealii::VectorOperation::values operation)
   {
     // note that one may think that we only need to do something
-    // if in fact the state is anything but LastAction::none. but
+    // if in fact the state is anything but last_action::unknown. but
     // that's not true: one frequently gets into situations where
     // only one processor (or a subset of processors) actually writes
     // something into a vector, but we still need to call
-    // VecAssemblyBegin/End on all processors, even those that are
-    // still in LastAction::none state
+    // VecAssemblyBegin/End on all processors.
     int ierr;
     ierr = VecAssemblyBegin(vector);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
@@ -422,7 +421,7 @@ namespace PETScWrappers
 
     // reset the last action field to indicate that we're back to
     // a pristine state
-    last_action = VectorBase::LastAction::none;
+    last_action = ::dealii::VectorOperation::unknown;
   }
 
 
@@ -1120,7 +1119,7 @@ namespace PETScWrappers
   std::size_t
   VectorBase::memory_consumption () const
   {
-    std::size_t mem = sizeof(Vec)+sizeof(LastAction::Values)
+    std::size_t mem = sizeof(Vec)+sizeof(last_action)
       +MemoryConsumption::memory_consumption(ghosted)
       +MemoryConsumption::memory_consumption(ghost_indices);
 
@@ -1145,14 +1144,13 @@ namespace PETScWrappers
                                     const PetscScalar  *values,
                                     const bool          add_values)
   {
-    Assert ((last_action == (add_values ?
-                             LastAction::add :
-                             LastAction::insert))
+    ::dealii::VectorOperation::values action = (add_values ?
+                                               ::dealii::VectorOperation::add :
+                                               ::dealii::VectorOperation::insert);
+    Assert ((last_action == action)
             ||
-            (last_action == LastAction::none),
-            internal::VectorReference::ExcWrongMode ((add_values ?
-                                                      LastAction::add :
-                                                      LastAction::insert),
+            (last_action == ::dealii::VectorOperation::unknown),
+            internal::VectorReference::ExcWrongMode (action,
                                                      last_action));
 
                                      // VecSetValues complains if we
@@ -1181,9 +1179,7 @@ namespace PETScWrappers
 
     // set the mode here, independent of whether we have actually
     // written elements or whether the list was empty
-    last_action = (add_values ?
-                   VectorBase::LastAction::add :
-                   VectorBase::LastAction::insert);
+    last_action = action;
   }
 
 
index a107de8656182df532f2f2e79818447a82349f2e..e6452b6b8f599a3b1ee81e615bc56fede7ae6bfd 100644 (file)
@@ -249,14 +249,6 @@ namespace TrilinosWrappers
 
 
 
-  void
-  BlockSparseMatrix::compress()
-  {
-    for (unsigned int r=0; r<this->n_block_rows(); ++r)
-      for (unsigned int c=0; c<this->n_block_cols(); ++c)
-        this->block(r,c).compress();
-  }
-
 
 
   void
index e15cca09720457dbb874a9813921ce9293dd169e..3b3f5136958cf5dca7dfe743a256f9b28ccabe7c 100644 (file)
@@ -174,15 +174,6 @@ namespace TrilinosWrappers
 
 
 
-    void
-    BlockVector::compress (const Epetra_CombineMode last_action)
-    {
-      for (unsigned int i=0; i<n_blocks(); ++i)
-        components[i].compress(last_action);
-    }
-
-
-
     void BlockVector::print (std::ostream       &out,
                              const unsigned int  precision,
                              const bool          scientific,

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.