]> https://gitweb.dealii.org/ - dealii.git/commitdiff
p::distributed::BlockVector: add MemorySpace
authorTimo Heister <timo.heister@gmail.com>
Fri, 21 Mar 2025 20:11:04 +0000 (16:11 -0400)
committerTimo Heister <timo.heister@gmail.com>
Fri, 21 Mar 2025 20:11:04 +0000 (16:11 -0400)
and instantiate for ::Host and ::Default

include/deal.II/base/template_constraints.h
include/deal.II/lac/la_parallel_block_vector.h
include/deal.II/lac/la_parallel_block_vector.templates.h
include/deal.II/lac/la_parallel_vector.h
include/deal.II/lac/precondition.h
source/lac/la_parallel_block_vector.cc
source/lac/la_parallel_block_vector.inst.in

index 515ee535e92fa349781988cd4ef17fb66916147f..7a37c5fad75507ef558a8f5375654ff6199d2c11 100644 (file)
@@ -625,7 +625,7 @@ namespace LinearAlgebra
     template <typename Number, typename MemorySpace>
     class Vector;
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     class BlockVector;
   } // namespace distributed
 } // namespace LinearAlgebra
@@ -747,9 +747,10 @@ namespace concepts
     inline constexpr bool is_dealii_vector_type<
       dealii::LinearAlgebra::distributed::Vector<Number, MemorySpace>> = true;
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     inline constexpr bool is_dealii_vector_type<
-      dealii::LinearAlgebra::distributed::BlockVector<Number>> = true;
+      dealii::LinearAlgebra::distributed::BlockVector<Number, MemorySpace>> =
+      true;
 
 #  ifdef DEAL_II_WITH_PETSC
     template <>
index 1ffede99de0bdae78da6a825ef6728002d34d00a..ae85065faedbe1cbabb6b94a42d8260898be4066 100644 (file)
@@ -80,8 +80,8 @@ namespace LinearAlgebra
      * @see
      * @ref GlossBlockLA "Block (linear algebra)"
      */
-    template <typename Number>
-    class BlockVector : public BlockVectorBase<Vector<Number>>
+    template <typename Number, typename MemorySpace = MemorySpace::Host>
+    class BlockVector : public BlockVectorBase<Vector<Number, MemorySpace>>
     {
     public:
       /**
@@ -101,7 +101,7 @@ namespace LinearAlgebra
       /**
        * Typedef the base class for simpler access to its own alias.
        */
-      using BaseClass = BlockVectorBase<Vector<Number>>;
+      using BaseClass = BlockVectorBase<Vector<Number, MemorySpace>>;
 
       /**
        * Typedef the type of the underlying vector.
@@ -143,7 +143,7 @@ namespace LinearAlgebra
        * Copy-Constructor. Dimension set to that of V, all components are
        * copied from V
        */
-      BlockVector(const BlockVector<Number> &V);
+      BlockVector(const BlockVector<Number, MemorySpace> &V);
 
       /**
        * Copy constructor taking a BlockVector of another data type. This will
@@ -152,7 +152,7 @@ namespace LinearAlgebra
        * BlockVector with data elements with less accuracy.
        */
       template <typename OtherNumber>
-      explicit BlockVector(const BlockVector<OtherNumber> &v);
+      explicit BlockVector(const BlockVector<OtherNumber, MemorySpace> &v);
 
       /**
        * Constructor. Set the number of blocks to <tt>block_sizes.size()</tt>
@@ -232,13 +232,13 @@ namespace LinearAlgebra
        */
       template <class Number2>
       BlockVector &
-      operator=(const BlockVector<Number2> &V);
+      operator=(const BlockVector<Number2, MemorySpace> &V);
 
       /**
        * Copy a regular vector into a block vector.
        */
       BlockVector &
-      operator=(const Vector<Number> &V);
+      operator=(const Vector<Number, MemorySpace> &V);
 
 #ifdef DEAL_II_WITH_PETSC
       /**
@@ -248,7 +248,7 @@ namespace LinearAlgebra
        *
        * This operator is only available if deal.II was configured with PETSc.
        */
-      BlockVector<Number> &
+      BlockVector<Number, MemorySpace> &
       operator=(const PETScWrappers::MPI::BlockVector &petsc_vec);
 #endif
 
@@ -261,7 +261,7 @@ namespace LinearAlgebra
        * This operator is only available if deal.II was configured with
        * Trilinos.
        */
-      BlockVector<Number> &
+      BlockVector<Number, MemorySpace> &
       operator=(const TrilinosWrappers::MPI::BlockVector &trilinos_vec);
 #endif
 
@@ -322,8 +322,8 @@ namespace LinearAlgebra
        */
       template <typename Number2>
       void
-      reinit(const BlockVector<Number2> &V,
-             const bool                  omit_zeroing_entries = false);
+      reinit(const BlockVector<Number2, MemorySpace> &V,
+             const bool omit_zeroing_entries = false);
 
       /**
        * Initialize the block vector. For each block, the local range is
@@ -336,8 +336,8 @@ namespace LinearAlgebra
        *
        * This function involves global communication, so it should only be
        * called once for a given layout. Use the @p reinit function with
-       * BlockVector<Number> argument to create additional vectors with the same
-       * parallel layout.
+       * BlockVector<Number, MemorySpace> argument to create additional vectors
+       * with the same parallel layout.
        *
        * @see
        * @ref GlossGhostedVector "vectors with ghost elements"
@@ -462,7 +462,8 @@ namespace LinearAlgebra
        */
       template <typename Number2>
       void
-      copy_locally_owned_data_from(const BlockVector<Number2> &src);
+      copy_locally_owned_data_from(
+        const BlockVector<Number2, MemorySpace> &src);
 
       /**
        * This is a collective add operation that adds a whole set of values
@@ -478,7 +479,7 @@ namespace LinearAlgebra
        * s*(*this)+V</tt>.
        */
       void
-      sadd(const Number s, const BlockVector<Number> &V);
+      sadd(const Number s, const BlockVector<Number, MemorySpace> &V);
 
       /**
        * Return whether the vector contains only elements with value zero.
@@ -519,7 +520,7 @@ namespace LinearAlgebra
        * functions.
        */
       void
-      swap(BlockVector<Number> &v) noexcept;
+      swap(BlockVector<Number, MemorySpace> &v) noexcept;
       /** @} */
 
       /**
@@ -530,26 +531,26 @@ namespace LinearAlgebra
       /**
        * Multiply the entire vector by a fixed factor.
        */
-      BlockVector<Number> &
+      BlockVector<Number, MemorySpace> &
       operator*=(const Number factor);
 
       /**
        * Divide the entire vector by a fixed factor.
        */
-      BlockVector<Number> &
+      BlockVector<Number, MemorySpace> &
       operator/=(const Number factor);
 
       /**
        * Add the vector @p V to the present one.
        */
-      BlockVector<Number> &
-      operator+=(const BlockVector<Number> &V);
+      BlockVector<Number, MemorySpace> &
+      operator+=(const BlockVector<Number, MemorySpace> &V);
 
       /**
        * Subtract the vector @p V from the present one.
        */
-      BlockVector<Number> &
-      operator-=(const BlockVector<Number> &V);
+      BlockVector<Number, MemorySpace> &
+      operator-=(const BlockVector<Number, MemorySpace> &V);
 
       /**
        * Import all the elements present in the vector's IndexSet from the input
@@ -582,7 +583,7 @@ namespace LinearAlgebra
        * Return the scalar product of two vectors.
        */
       Number
-      operator*(const BlockVector<Number> &V) const;
+      operator*(const BlockVector<Number, MemorySpace> &V) const;
 
       /**
        * Calculate the scalar product between each block of this vector and @p V
@@ -602,8 +603,8 @@ namespace LinearAlgebra
        */
       template <typename FullMatrixType>
       void
-      multivector_inner_product(FullMatrixType            &matrix,
-                                const BlockVector<Number> &V,
+      multivector_inner_product(FullMatrixType                         &matrix,
+                                const BlockVector<Number, MemorySpace> &V,
                                 const bool symmetric = false) const;
 
       /**
@@ -624,9 +625,10 @@ namespace LinearAlgebra
        */
       template <typename FullMatrixType>
       Number
-      multivector_inner_product_with_metric(const FullMatrixType      &matrix,
-                                            const BlockVector<Number> &V,
-                                            const bool symmetric = false) const;
+      multivector_inner_product_with_metric(
+        const FullMatrixType                   &matrix,
+        const BlockVector<Number, MemorySpace> &V,
+        const bool                              symmetric = false) const;
 
       /**
        * Set each block of this vector as follows:
@@ -639,10 +641,10 @@ namespace LinearAlgebra
        */
       template <typename FullMatrixType>
       void
-      mmult(BlockVector<Number &V,
-            const FullMatrixType &matrix,
-            const Number          s = Number(0.),
-            const Number          b = Number(1.)) const;
+      mmult(BlockVector<Number, MemorySpace> &V,
+            const FullMatrixType             &matrix,
+            const Number                      s = Number(0.),
+            const Number                      b = Number(1.)) const;
 
       /**
        * Add @p a to all components. Note that @p a is a scalar not a vector.
@@ -654,16 +656,16 @@ namespace LinearAlgebra
        * Simple addition of a multiple of a vector, i.e. <tt>*this += a*V</tt>.
        */
       void
-      add(const Number a, const BlockVector<Number> &V);
+      add(const Number a, const BlockVector<Number, MemorySpace> &V);
 
       /**
        * Multiple addition of scaled vectors, i.e. <tt>*this += a*V+b*W</tt>.
        */
       void
-      add(const Number               a,
-          const BlockVector<Number> &V,
-          const Number               b,
-          const BlockVector<Number> &W);
+      add(const Number                            a,
+          const BlockVector<Number, MemorySpace> &V,
+          const Number                            b,
+          const BlockVector<Number, MemorySpace> &W);
 
       /**
        * A collective add operation: This function adds a whole set of values
@@ -678,7 +680,9 @@ namespace LinearAlgebra
        * s*(*this)+a*V</tt>.
        */
       void
-      sadd(const Number s, const Number a, const BlockVector<Number> &V);
+      sadd(const Number                            s,
+           const Number                            a,
+           const BlockVector<Number, MemorySpace> &V);
 
       /**
        * Scale each element of this vector by the corresponding element in the
@@ -686,13 +690,13 @@ namespace LinearAlgebra
        * immediate re-assignment) by a diagonal scaling matrix.
        */
       void
-      scale(const BlockVector<Number> &scaling_factors);
+      scale(const BlockVector<Number, MemorySpace> &scaling_factors);
 
       /**
        * Assignment <tt>*this = a*V</tt>.
        */
       void
-      equ(const Number a, const BlockVector<Number> &V);
+      equ(const Number a, const BlockVector<Number, MemorySpace> &V);
 
       /**
        * Return the l<sub>1</sub> norm of the vector (i.e., the sum of the
@@ -742,9 +746,9 @@ namespace LinearAlgebra
        * $\left<v,w\right>=\sum_i v_i \bar{w_i}$.
        */
       Number
-      add_and_dot(const Number               a,
-                  const BlockVector<Number> &V,
-                  const BlockVector<Number> &W);
+      add_and_dot(const Number                            a,
+                  const BlockVector<Number, MemorySpace> &V,
+                  const BlockVector<Number, MemorySpace> &W);
 
       /**
        * Return the global size of the vector, equal to the sum of the number of
@@ -816,10 +820,10 @@ namespace LinearAlgebra
  *
  * @relatesalso BlockVector
  */
-template <typename Number>
+template <typename Number, typename MemorySpace>
 inline void
-swap(LinearAlgebra::distributed::BlockVector<Number> &u,
-     LinearAlgebra::distributed::BlockVector<Number> &v) noexcept
+swap(LinearAlgebra::distributed::BlockVector<Number, MemorySpace> &u,
+     LinearAlgebra::distributed::BlockVector<Number, MemorySpace> &v) noexcept
 {
   u.swap(v);
 }
@@ -829,8 +833,9 @@ swap(LinearAlgebra::distributed::BlockVector<Number> &u,
  * Declare dealii::LinearAlgebra::distributed::BlockVector as distributed
  * vector.
  */
-template <typename Number>
-struct is_serial_vector<LinearAlgebra::distributed::BlockVector<Number>>
+template <typename Number, typename MemorySpace>
+struct is_serial_vector<
+  LinearAlgebra::distributed::BlockVector<Number, MemorySpace>>
   : std::false_type
 {};
 
index e431643448f25f95a9e4712a4709cb824a8ce096..bc10b70516a5f6bcf2f3557df633f576bd47781c 100644 (file)
@@ -40,42 +40,45 @@ namespace LinearAlgebra
 {
   namespace distributed
   {
-    template <typename Number>
-    BlockVector<Number>::BlockVector(const size_type n_blocks,
-                                     const size_type block_size)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace>::BlockVector(const size_type n_blocks,
+                                                  const size_type block_size)
     {
       reinit(n_blocks, block_size);
     }
 
 
 
-    template <typename Number>
-    BlockVector<Number>::BlockVector(const std::vector<size_type> &n)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace>::BlockVector(
+      const std::vector<size_type> &n)
     {
       reinit(n, false);
     }
 
 
-    template <typename Number>
-    BlockVector<Number>::BlockVector(const std::vector<IndexSet> &local_ranges,
-                                     const std::vector<IndexSet> &ghost_indices,
-                                     const MPI_Comm               communicator)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace>::BlockVector(
+      const std::vector<IndexSet> &local_ranges,
+      const std::vector<IndexSet> &ghost_indices,
+      const MPI_Comm               communicator)
     {
       reinit(local_ranges, ghost_indices, communicator);
     }
 
 
-    template <typename Number>
-    BlockVector<Number>::BlockVector(const std::vector<IndexSet> &local_ranges,
-                                     const MPI_Comm               communicator)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace>::BlockVector(
+      const std::vector<IndexSet> &local_ranges,
+      const MPI_Comm               communicator)
     {
       reinit(local_ranges, communicator);
     }
 
 
 
-    template <typename Number>
-    BlockVector<Number>::BlockVector(
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace>::BlockVector(
       const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
                      &partitioners,
       const MPI_Comm &comm_sm)
@@ -85,9 +88,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number>::BlockVector(const BlockVector<Number> &v)
-      : BlockVectorBase<Vector<Number>>()
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace>::BlockVector(
+      const BlockVector<Number, MemorySpace> &v)
+      : BlockVectorBase<Vector<Number, MemorySpace>>()
     {
       this->block_indices = v.block_indices;
 
@@ -100,9 +104,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     template <typename OtherNumber>
-    BlockVector<Number>::BlockVector(const BlockVector<OtherNumber> &v)
+    BlockVector<Number, MemorySpace>::BlockVector(
+      const BlockVector<OtherNumber, MemorySpace> &v)
     {
       reinit(v, true);
       *this = v;
@@ -110,21 +115,22 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::reinit(const size_type n_bl,
-                                const size_type bl_sz,
-                                const bool      omit_zeroing_entries)
+    BlockVector<Number, MemorySpace>::reinit(const size_type n_bl,
+                                             const size_type bl_sz,
+                                             const bool omit_zeroing_entries)
     {
       std::vector<size_type> n(n_bl, bl_sz);
       reinit(n, omit_zeroing_entries);
     }
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::reinit(const std::vector<size_type> &block_sizes,
-                                const bool omit_zeroing_entries)
+    BlockVector<Number, MemorySpace>::reinit(
+      const std::vector<size_type> &block_sizes,
+      const bool                    omit_zeroing_entries)
     {
       this->block_indices.reinit(block_sizes);
 
@@ -137,11 +143,12 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     template <typename Number2>
     void
-    BlockVector<Number>::reinit(const BlockVector<Number2> &v,
-                                const bool omit_zeroing_entries)
+    BlockVector<Number, MemorySpace>::reinit(
+      const BlockVector<Number2, MemorySpace> &v,
+      const bool                               omit_zeroing_entries)
     {
       if (this->n_blocks() != v.n_blocks())
         this->block_indices = v.get_block_indices();
@@ -155,11 +162,12 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::reinit(const std::vector<IndexSet> &local_ranges,
-                                const std::vector<IndexSet> &ghost_indices,
-                                const MPI_Comm               communicator)
+    BlockVector<Number, MemorySpace>::reinit(
+      const std::vector<IndexSet> &local_ranges,
+      const std::vector<IndexSet> &ghost_indices,
+      const MPI_Comm               communicator)
     {
       AssertDimension(local_ranges.size(), ghost_indices.size());
 
@@ -179,10 +187,11 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::reinit(const std::vector<IndexSet> &local_ranges,
-                                const MPI_Comm               communicator)
+    BlockVector<Number, MemorySpace>::reinit(
+      const std::vector<IndexSet> &local_ranges,
+      const MPI_Comm               communicator)
     {
       // update the number of blocks
       this->block_indices.reinit(local_ranges.size(), 0);
@@ -198,9 +207,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::reinit(
+    BlockVector<Number, MemorySpace>::reinit(
       const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
                      &partitioners,
       const MPI_Comm &comm_sm)
@@ -219,9 +228,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::reinit(
+    BlockVector<Number, MemorySpace>::reinit(
       const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
         &partitioners,
       const bool /*make_ghosted*/,
@@ -232,9 +241,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator=(const value_type s)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator=(const value_type s)
     {
       AssertIsFinite(s);
 
@@ -244,9 +253,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator=(const BlockVector &v)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator=(const BlockVector &v)
     {
       // we only allow assignment to vectors with the same number of blocks
       // or to an empty BlockVector
@@ -267,9 +276,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator=(const Vector<Number> &v)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator=(
+      const Vector<Number, MemorySpace> &v)
     {
       BaseClass::operator=(v);
       return *this;
@@ -277,10 +287,11 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     template <typename Number2>
-    BlockVector<Number> &
-    BlockVector<Number>::operator=(const BlockVector<Number2> &v)
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator=(
+      const BlockVector<Number2, MemorySpace> &v)
     {
       reinit(v, true);
       BaseClass::operator=(v);
@@ -289,11 +300,11 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     template <typename Number2>
     void
-    BlockVector<Number>::copy_locally_owned_data_from(
-      const BlockVector<Number2> &v)
+    BlockVector<Number, MemorySpace>::copy_locally_owned_data_from(
+      const BlockVector<Number2, MemorySpace> &v)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
 
@@ -337,9 +348,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator=(
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator=(
       const PETScWrappers::MPI::BlockVector &petsc_vec)
     {
       AssertDimension(this->n_blocks(), petsc_vec.n_blocks());
@@ -387,9 +398,9 @@ namespace LinearAlgebra
 
 #ifdef DEAL_II_WITH_TRILINOS
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator=(
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator=(
       const TrilinosWrappers::MPI::BlockVector &trilinos_vec)
     {
       AssertDimension(this->n_blocks(), trilinos_vec.n_blocks());
@@ -415,9 +426,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::compress(VectorOperation::values operation)
+    BlockVector<Number, MemorySpace>::compress(
+      VectorOperation::values operation)
     {
       const unsigned int n_chunks =
         (this->n_blocks() + communication_block_size - 1) /
@@ -443,9 +455,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::update_ghost_values() const
+    BlockVector<Number, MemorySpace>::update_ghost_values() const
     {
       const unsigned int n_chunks =
         (this->n_blocks() + communication_block_size - 1) /
@@ -469,9 +481,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::zero_out_ghost_values() const
+    BlockVector<Number, MemorySpace>::zero_out_ghost_values() const
     {
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
         this->block(block).zero_out_ghost_values();
@@ -479,9 +491,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     bool
-    BlockVector<Number>::has_ghost_elements() const
+    BlockVector<Number, MemorySpace>::has_ghost_elements() const
     {
       bool has_ghost_elements = false;
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
@@ -492,9 +504,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::set_ghost_state(const bool ghosted) const
+    BlockVector<Number, MemorySpace>::set_ghost_state(const bool ghosted) const
     {
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
         this->block(block).set_ghost_state(ghosted);
@@ -502,9 +514,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator*=(const Number factor)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator*=(const Number factor)
     {
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
         this->block(block) *= factor;
@@ -513,9 +525,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator/=(const Number factor)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator/=(const Number factor)
     {
       operator*=(static_cast<Number>(1.) / factor);
       return *this;
@@ -523,9 +535,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::scale(const BlockVector<Number> &v)
+    BlockVector<Number, MemorySpace>::scale(
+      const BlockVector<Number, MemorySpace> &v)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
@@ -534,9 +547,11 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::equ(const Number a, const BlockVector<Number> &v)
+    BlockVector<Number, MemorySpace>::equ(
+      const Number                            a,
+      const BlockVector<Number, MemorySpace> &v)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
@@ -545,9 +560,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator+=(const BlockVector<Number> &v)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator+=(
+      const BlockVector<Number, MemorySpace> &v)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
@@ -558,9 +574,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    BlockVector<Number> &
-    BlockVector<Number>::operator-=(const BlockVector<Number> &v)
+    template <typename Number, typename MemorySpace>
+    BlockVector<Number, MemorySpace> &
+    BlockVector<Number, MemorySpace>::operator-=(
+      const BlockVector<Number, MemorySpace> &v)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
@@ -571,9 +588,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::add(const Number a)
+    BlockVector<Number, MemorySpace>::add(const Number a)
     {
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
         this->block(block).add(a);
@@ -581,9 +598,11 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::add(const Number a, const BlockVector<Number> &v)
+    BlockVector<Number, MemorySpace>::add(
+      const Number                            a,
+      const BlockVector<Number, MemorySpace> &v)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
@@ -592,12 +611,13 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::add(const Number               a,
-                             const BlockVector<Number> &v,
-                             const Number               b,
-                             const BlockVector<Number> &w)
+    BlockVector<Number, MemorySpace>::add(
+      const Number                            a,
+      const BlockVector<Number, MemorySpace> &v,
+      const Number                            b,
+      const BlockVector<Number, MemorySpace> &w)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       AssertDimension(this->n_blocks(), w.n_blocks());
@@ -608,11 +628,12 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::sadd(const Number               x,
-                              const Number               a,
-                              const BlockVector<Number> &v)
+    BlockVector<Number, MemorySpace>::sadd(
+      const Number                            x,
+      const Number                            a,
+      const BlockVector<Number, MemorySpace> &v)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
@@ -621,9 +642,11 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::sadd(const Number x, const BlockVector<Number> &v)
+    BlockVector<Number, MemorySpace>::sadd(
+      const Number                            x,
+      const BlockVector<Number, MemorySpace> &v)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       for (unsigned int block = 0; block < this->n_blocks(); ++block)
@@ -632,11 +655,12 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     template <typename OtherNumber>
     void
-    BlockVector<Number>::add(const std::vector<size_type>        &indices,
-                             const ::dealii::Vector<OtherNumber> &values)
+    BlockVector<Number, MemorySpace>::add(
+      const std::vector<size_type>        &indices,
+      const ::dealii::Vector<OtherNumber> &values)
     {
       for (size_type i = 0; i < indices.size(); ++i)
         (*this)(indices[i]) += values[i];
@@ -644,10 +668,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::add(const std::vector<size_type> &indices,
-                             const std::vector<Number>    &values)
+    BlockVector<Number, MemorySpace>::add(const std::vector<size_type> &indices,
+                                          const std::vector<Number>    &values)
     {
       for (size_type i = 0; i < indices.size(); ++i)
         (*this)(indices[i]) += values[i];
@@ -655,9 +679,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     bool
-    BlockVector<Number>::all_zero() const
+    BlockVector<Number, MemorySpace>::all_zero() const
     {
       Assert(this->n_blocks() > 0, ExcEmptyObject());
 
@@ -677,9 +701,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     Number
-    BlockVector<Number>::operator*(const BlockVector<Number> &v) const
+    BlockVector<Number, MemorySpace>::operator*(
+      const BlockVector<Number, MemorySpace> &v) const
     {
       Assert(this->n_blocks() > 0, ExcEmptyObject());
       AssertDimension(this->n_blocks(), v.n_blocks());
@@ -697,9 +722,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     inline Number
-    BlockVector<Number>::mean_value() const
+    BlockVector<Number, MemorySpace>::mean_value() const
     {
       Assert(this->n_blocks() > 0, ExcEmptyObject());
 
@@ -720,9 +745,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    inline typename BlockVector<Number>::real_type
-    BlockVector<Number>::l1_norm() const
+    template <typename Number, typename MemorySpace>
+    inline typename BlockVector<Number, MemorySpace>::real_type
+    BlockVector<Number, MemorySpace>::l1_norm() const
     {
       Assert(this->n_blocks() > 0, ExcEmptyObject());
 
@@ -739,9 +764,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    inline typename BlockVector<Number>::real_type
-    BlockVector<Number>::norm_sqr() const
+    template <typename Number, typename MemorySpace>
+    inline typename BlockVector<Number, MemorySpace>::real_type
+    BlockVector<Number, MemorySpace>::norm_sqr() const
     {
       Assert(this->n_blocks() > 0, ExcEmptyObject());
 
@@ -758,18 +783,18 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    inline typename BlockVector<Number>::real_type
-    BlockVector<Number>::l2_norm() const
+    template <typename Number, typename MemorySpace>
+    inline typename BlockVector<Number, MemorySpace>::real_type
+    BlockVector<Number, MemorySpace>::l2_norm() const
     {
       return std::sqrt(norm_sqr());
     }
 
 
 
-    template <typename Number>
-    inline typename BlockVector<Number>::real_type
-    BlockVector<Number>::lp_norm(const real_type p) const
+    template <typename Number, typename MemorySpace>
+    inline typename BlockVector<Number, MemorySpace>::real_type
+    BlockVector<Number, MemorySpace>::lp_norm(const real_type p) const
     {
       Assert(this->n_blocks() > 0, ExcEmptyObject());
 
@@ -788,9 +813,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    inline typename BlockVector<Number>::real_type
-    BlockVector<Number>::linfty_norm() const
+    template <typename Number, typename MemorySpace>
+    inline typename BlockVector<Number, MemorySpace>::real_type
+    BlockVector<Number, MemorySpace>::linfty_norm() const
     {
       Assert(this->n_blocks() > 0, ExcEmptyObject());
 
@@ -808,11 +833,12 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     inline Number
-    BlockVector<Number>::add_and_dot(const Number               a,
-                                     const BlockVector<Number> &v,
-                                     const BlockVector<Number> &w)
+    BlockVector<Number, MemorySpace>::add_and_dot(
+      const Number                            a,
+      const BlockVector<Number, MemorySpace> &v,
+      const BlockVector<Number, MemorySpace> &w)
     {
       AssertDimension(this->n_blocks(), v.n_blocks());
       AssertDimension(this->n_blocks(), w.n_blocks());
@@ -831,9 +857,10 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     inline void
-    BlockVector<Number>::swap(BlockVector<Number> &v) noexcept
+    BlockVector<Number, MemorySpace>::swap(
+      BlockVector<Number, MemorySpace> &v) noexcept
     {
       Assert(this->n_blocks() == v.n_blocks(),
              ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
@@ -845,18 +872,18 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
-    typename BlockVector<Number>::size_type
-    BlockVector<Number>::size() const
+    template <typename Number, typename MemorySpace>
+    typename BlockVector<Number, MemorySpace>::size_type
+    BlockVector<Number, MemorySpace>::size() const
     {
       return this->block_indices.total_size();
     }
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     inline void
-    BlockVector<Number>::import_elements(
+    BlockVector<Number, MemorySpace>::import_elements(
       const LinearAlgebra::ReadWriteVector<Number> &,
       const VectorOperation::values,
       const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase> &)
@@ -866,9 +893,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     IndexSet
-    BlockVector<Number>::locally_owned_elements() const
+    BlockVector<Number, MemorySpace>::locally_owned_elements() const
     {
       IndexSet is(size());
 
@@ -885,12 +912,12 @@ namespace LinearAlgebra
       return is;
     }
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     void
-    BlockVector<Number>::print(std::ostream      &out,
-                               const unsigned int precision,
-                               const bool         scientific,
-                               const bool         across) const
+    BlockVector<Number, MemorySpace>::print(std::ostream      &out,
+                                            const unsigned int precision,
+                                            const bool         scientific,
+                                            const bool         across) const
     {
       for (unsigned int b = 0; b < this->n_blocks(); ++b)
         this->block(b).print(out, precision, scientific, across);
@@ -898,9 +925,9 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     std::size_t
-    BlockVector<Number>::memory_consumption() const
+    BlockVector<Number, MemorySpace>::memory_consumption() const
     {
       return (MemoryConsumption::memory_consumption(this->block_indices) +
               MemoryConsumption::memory_consumption(this->components));
@@ -928,12 +955,13 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     template <typename FullMatrixType>
     void
-    BlockVector<Number>::multivector_inner_product(FullMatrixType &matrix,
-                                                   const BlockVector<Number> &V,
-                                                   const bool symmetric) const
+    BlockVector<Number, MemorySpace>::multivector_inner_product(
+      FullMatrixType                         &matrix,
+      const BlockVector<Number, MemorySpace> &V,
+      const bool                              symmetric) const
     {
       const unsigned int m = this->n_blocks();
       const unsigned int n = V.n_blocks();
@@ -978,13 +1006,13 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     template <typename FullMatrixType>
     Number
-    BlockVector<Number>::multivector_inner_product_with_metric(
-      const FullMatrixType      &matrix,
-      const BlockVector<Number> &V,
-      const bool                 symmetric) const
+    BlockVector<Number, MemorySpace>::multivector_inner_product_with_metric(
+      const FullMatrixType                   &matrix,
+      const BlockVector<Number, MemorySpace> &V,
+      const bool                              symmetric) const
     {
       Number res = Number(0.);
 
@@ -1027,13 +1055,13 @@ namespace LinearAlgebra
 
 
 
-    template <typename Number>
+    template <typename Number, typename MemorySpace>
     template <typename FullMatrixType>
     void
-    BlockVector<Number>::mmult(BlockVector<Number>  &V,
-                               const FullMatrixType &matrix,
-                               const Number          s,
-                               const Number          b) const
+    BlockVector<Number, MemorySpace>::mmult(BlockVector<Number, MemorySpace> &V,
+                                            const FullMatrixType &matrix,
+                                            const Number          s,
+                                            const Number          b) const
     {
       const unsigned int m = this->n_blocks();
       const unsigned int n = V.n_blocks();
index d476a1d4a9cc86706574bb0ebf3fc05207a5c57b..566ea28ef25c6ed039434a67328b43444e5a88d8 100644 (file)
@@ -51,7 +51,7 @@ namespace LinearAlgebra
    */
   namespace distributed
   {
-    template <typename>
+    template <typename, typename>
     class BlockVector;
   }
 
@@ -1472,7 +1472,7 @@ namespace LinearAlgebra
       friend class Vector;
 
       // Make BlockVector type friends.
-      template <typename Number2>
+      template <typename Number2, typename MemorySpace2>
       friend class BlockVector;
     };
     /** @} */
index e7a79ec2a1ffd8fa040e0f769104327c2fab68ee..c16b14a5033546368edad3a998804b53ec64fafa 100644 (file)
@@ -46,7 +46,7 @@ namespace LinearAlgebra
   {
     template <typename, typename>
     class Vector;
-    template <typename>
+    template <typename, typename>
     class BlockVector;
   } // namespace distributed
 } // namespace LinearAlgebra
@@ -2334,10 +2334,11 @@ namespace internal
     vector.add(-mean_value);
   }
 
-  template <typename Number>
+  template <typename Number, typename MemorySpace>
   void
   set_initial_guess(
-    ::dealii::LinearAlgebra::distributed::BlockVector<Number> &vector)
+    ::dealii::LinearAlgebra::distributed::BlockVector<Number, MemorySpace>
+      &vector)
   {
     for (unsigned int block = 0; block < vector.n_blocks(); ++block)
       set_initial_guess(vector.block(block));
index a8aa8d4b29303986b2b8c229469ce668fbc4e76f..e997e9c33284e8aa57629da05b48454b851b240d 100644 (file)
@@ -30,9 +30,10 @@ namespace LinearAlgebra
 {
   namespace distributed
   {
-#define TEMPL_COPY_CONSTRUCTOR(S1, S2)                 \
-  template BlockVector<S1> &BlockVector<S1>::operator= \
-    <S2>(const BlockVector<S2> &)
+#define TEMPL_COPY_CONSTRUCTOR(S1, S2)                    \
+  template BlockVector<S1, ::dealii::MemorySpace::Host> & \
+  BlockVector<S1, ::dealii::MemorySpace::Host>::operator= \
+    <S2>(const BlockVector<S2, ::dealii::MemorySpace::Host> &)
 
     TEMPL_COPY_CONSTRUCTOR(double, float);
     TEMPL_COPY_CONSTRUCTOR(float, double);
index e13c9a1146bbac5f2a71ea52e6adf396d21aa390..da63a81c219d660222bf3d43b5d8b840bb79fc72 100644 (file)
@@ -21,41 +21,51 @@ for (SCALAR : REAL_AND_COMPLEX_SCALARS)
       namespace distributed
       \{
 #ifdef DEAL_II_HAVE_CXX20
-        static_assert(concepts::is_vector_space_vector<BlockVector<SCALAR>>);
+        static_assert(concepts::is_vector_space_vector<
+                      BlockVector<SCALAR, ::dealii::MemorySpace::Host>>);
+        // static_assert(concepts::is_vector_space_vector<BlockVector<SCALAR,
+        // ::dealii::MemorySpace::Default>>);
 #endif
 
-        template class BlockVector<SCALAR>;
+        template class BlockVector<SCALAR, ::dealii::MemorySpace::Host>;
+        template class BlockVector<SCALAR, ::dealii::MemorySpace::Default>;
 
         template void
-        BlockVector<SCALAR>::multivector_inner_product(
-          FullMatrix<SCALAR> &,
-          const BlockVector<SCALAR> &V,
-          const bool) const;
+        BlockVector<SCALAR, ::dealii::MemorySpace::Host>::
+          multivector_inner_product(
+            FullMatrix<SCALAR> &,
+            const BlockVector<SCALAR, ::dealii::MemorySpace::Host> &V,
+            const bool) const;
         template void
-        BlockVector<SCALAR>::multivector_inner_product(
-          LAPACKFullMatrix<SCALAR> &,
-          const BlockVector<SCALAR> &V,
-          const bool) const;
+        BlockVector<SCALAR, ::dealii::MemorySpace::Host>::
+          multivector_inner_product(
+            LAPACKFullMatrix<SCALAR> &,
+            const BlockVector<SCALAR, ::dealii::MemorySpace::Host> &V,
+            const bool) const;
         template SCALAR
-        BlockVector<SCALAR>::multivector_inner_product_with_metric(
-          const FullMatrix<SCALAR> &,
-          const BlockVector<SCALAR> &V,
-          const bool) const;
+        BlockVector<SCALAR, ::dealii::MemorySpace::Host>::
+          multivector_inner_product_with_metric(
+            const FullMatrix<SCALAR> &,
+            const BlockVector<SCALAR, ::dealii::MemorySpace::Host> &V,
+            const bool) const;
         template SCALAR
-        BlockVector<SCALAR>::multivector_inner_product_with_metric(
-          const LAPACKFullMatrix<SCALAR> &,
-          const BlockVector<SCALAR> &V,
-          const bool) const;
+        BlockVector<SCALAR, ::dealii::MemorySpace::Host>::
+          multivector_inner_product_with_metric(
+            const LAPACKFullMatrix<SCALAR> &,
+            const BlockVector<SCALAR, ::dealii::MemorySpace::Host> &V,
+            const bool) const;
         template void
-        BlockVector<SCALAR>::mmult(BlockVector<SCALAR> &V,
-                                   const FullMatrix<SCALAR> &,
-                                   const SCALAR,
-                                   const SCALAR) const;
+        BlockVector<SCALAR, ::dealii::MemorySpace::Host>::mmult(
+          BlockVector<SCALAR, ::dealii::MemorySpace::Host> &V,
+          const FullMatrix<SCALAR> &,
+          const SCALAR,
+          const SCALAR) const;
         template void
-        BlockVector<SCALAR>::mmult(BlockVector<SCALAR> &V,
-                                   const LAPACKFullMatrix<SCALAR> &,
-                                   const SCALAR,
-                                   const SCALAR) const;
+        BlockVector<SCALAR, ::dealii::MemorySpace::Host>::mmult(
+          BlockVector<SCALAR, ::dealii::MemorySpace::Host> &V,
+          const LAPACKFullMatrix<SCALAR> &,
+          const SCALAR,
+          const SCALAR) const;
       \}
     \}
   }
@@ -67,13 +77,17 @@ for (S1 : REAL_AND_COMPLEX_SCALARS; S2 : REAL_SCALARS)
       namespace distributed
       \{
         template void
-        BlockVector<S1>::reinit<S2>(const BlockVector<S2> &, const bool);
+        BlockVector<S1, ::dealii::MemorySpace::Host>::reinit<S2>(
+          const BlockVector<S2, ::dealii::MemorySpace::Host> &,
+          const bool);
         template void
-        BlockVector<S1>::copy_locally_owned_data_from<S2>(
-          const BlockVector<S2> &);
+        BlockVector<S1, ::dealii::MemorySpace::Host>::
+          copy_locally_owned_data_from<S2>(
+            const BlockVector<S2, ::dealii::MemorySpace::Host> &);
         template void
-        BlockVector<S1>::add<S2>(const std::vector<size_type> &,
-                                 const ::dealii::Vector<S2> &);
+        BlockVector<S1, ::dealii::MemorySpace::Host>::add<S2>(
+          const std::vector<size_type> &,
+          const ::dealii::Vector<S2> &);
       \}
     \}
   }
@@ -87,13 +101,17 @@ for (S1, S2 : COMPLEX_SCALARS)
       namespace distributed
       \{
         template void
-        BlockVector<S1>::reinit<S2>(const BlockVector<S2> &, const bool);
+        BlockVector<S1, ::dealii::MemorySpace::Host>::reinit<S2>(
+          const BlockVector<S2, ::dealii::MemorySpace::Host> &,
+          const bool);
         template void
-        BlockVector<S1>::copy_locally_owned_data_from<S2>(
-          const BlockVector<S2> &);
+        BlockVector<S1, ::dealii::MemorySpace::Host>::
+          copy_locally_owned_data_from<S2>(
+            const BlockVector<S2, ::dealii::MemorySpace::Host> &);
         template void
-        BlockVector<S1>::add<S2>(const std::vector<size_type> &,
-                                 const ::dealii::Vector<S2> &);
+        BlockVector<S1, ::dealii::MemorySpace::Host>::add<S2>(
+          const std::vector<size_type> &,
+          const ::dealii::Vector<S2> &);
       \}
     \}
   }

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.