Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
la_parallel_block_vector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2020 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_la_parallel_block_vector_h
17 #define dealii_la_parallel_block_vector_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 
29 
30 #include <cstdio>
31 #include <vector>
32 
34 
35 
36 // Forward declarations
37 #ifndef DOXYGEN
38 # ifdef DEAL_II_WITH_PETSC
39 namespace PETScWrappers
40 {
41  namespace MPI
42  {
43  class BlockVector;
44  }
45 } // namespace PETScWrappers
46 # endif
47 
48 # ifdef DEAL_II_WITH_TRILINOS
49 namespace TrilinosWrappers
50 {
51  namespace MPI
52  {
53  class BlockVector;
54  }
55 } // namespace TrilinosWrappers
56 # endif
57 #endif
58 
59 namespace LinearAlgebra
60 {
61  namespace distributed
62  {
84  template <typename Number>
85  class BlockVector : public BlockVectorBase<Vector<Number>>,
86  public VectorSpaceVector<Number>
87  {
88  public:
101  static constexpr unsigned int communication_block_size = 20;
102 
107 
111  using BlockType = typename BaseClass::BlockType;
112 
117  using real_type = typename BaseClass::real_type;
118  using pointer = typename BaseClass::pointer;
120  using reference = typename BaseClass::reference;
122  using size_type = typename BaseClass::size_type;
123  using iterator = typename BaseClass::iterator;
125 
130 
141  explicit BlockVector(const size_type num_blocks = 0,
142  const size_type block_size = 0);
143 
149 
162  template <typename OtherNumber>
163  explicit BlockVector(const BlockVector<OtherNumber> &v);
164 
169  BlockVector(const std::vector<size_type> &block_sizes);
170 
175  BlockVector(const std::vector<IndexSet> &local_ranges,
176  const std::vector<IndexSet> &ghost_indices,
177  const MPI_Comm communicator);
178 
182  BlockVector(const std::vector<IndexSet> &local_ranges,
183  const MPI_Comm communicator);
184 
193  virtual ~BlockVector() override = default;
194 
199  virtual BlockVector &
200  operator=(const value_type s) override;
201 
206  BlockVector &
207  operator=(const BlockVector &V);
208 
213  template <class Number2>
214  BlockVector &
215  operator=(const BlockVector<Number2> &V);
216 
220  BlockVector &
221  operator=(const Vector<Number> &V);
222 
223 #ifdef DEAL_II_WITH_PETSC
224 
232  operator=(const PETScWrappers::MPI::BlockVector &petsc_vec);
233 #endif
234 
235 #ifdef DEAL_II_WITH_TRILINOS
236 
245  operator=(const TrilinosWrappers::MPI::BlockVector &trilinos_vec);
246 #endif
247 
261  void
262  reinit(const size_type num_blocks,
263  const size_type block_size = 0,
264  const bool omit_zeroing_entries = false);
265 
285  void
286  reinit(const std::vector<size_type> &N,
287  const bool omit_zeroing_entries = false);
288 
303  template <typename Number2>
304  void
306  const bool omit_zeroing_entries = false);
307 
332  virtual void
333  compress(::VectorOperation::values operation) override;
334 
343  void
344  update_ghost_values() const;
345 
354  void
355  zero_out_ghosts() const;
356 
360  bool
361  has_ghost_elements() const;
362 
367  template <typename OtherNumber>
368  void
369  add(const std::vector<size_type> & indices,
370  const ::Vector<OtherNumber> &values);
371 
376  void
377  sadd(const Number s, const BlockVector<Number> &V);
378 
384  virtual bool
385  all_zero() const override;
386 
390  virtual Number
391  mean_value() const override;
392 
397  real_type
398  lp_norm(const real_type p) const;
399 
417  void
420 
425 
430  virtual void
432  const bool omit_zeroing_entries = false) override;
433 
437  virtual BlockVector<Number> &
438  operator*=(const Number factor) override;
439 
443  virtual BlockVector<Number> &
444  operator/=(const Number factor) override;
445 
449  virtual BlockVector<Number> &
450  operator+=(const VectorSpaceVector<Number> &V) override;
451 
455  virtual BlockVector<Number> &
456  operator-=(const VectorSpaceVector<Number> &V) override;
457 
466  virtual void
467  import(
469  VectorOperation::values operation,
470  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
471  std::shared_ptr<const CommunicationPatternBase>()) override;
472 
476  virtual Number
477  operator*(const VectorSpaceVector<Number> &V) const override;
478 
495  template <typename FullMatrixType>
496  void
497  multivector_inner_product(FullMatrixType & matrix,
498  const BlockVector<Number> &V,
499  const bool symmetric = false) const;
500 
517  template <typename FullMatrixType>
518  Number
519  multivector_inner_product_with_metric(const FullMatrixType & matrix,
520  const BlockVector<Number> &V,
521  const bool symmetric = false) const;
522 
532  template <typename FullMatrixType>
533  void
534  mmult(BlockVector<Number> & V,
535  const FullMatrixType &matrix,
536  const Number s = Number(0.),
537  const Number b = Number(1.)) const;
538 
542  virtual void
543  add(const Number a) override;
544 
548  virtual void
549  add(const Number a, const VectorSpaceVector<Number> &V) override;
550 
554  virtual void
555  add(const Number a,
556  const VectorSpaceVector<Number> &V,
557  const Number b,
558  const VectorSpaceVector<Number> &W) override;
559 
564  virtual void
565  add(const std::vector<size_type> &indices,
566  const std::vector<Number> & values);
567 
572  virtual void
573  sadd(const Number s,
574  const Number a,
575  const VectorSpaceVector<Number> &V) override;
576 
582  virtual void
583  scale(const VectorSpaceVector<Number> &scaling_factors) override;
584 
588  virtual void
589  equ(const Number a, const VectorSpaceVector<Number> &V) override;
590 
595  virtual real_type
596  l1_norm() const override;
597 
602  virtual real_type
603  l2_norm() const override;
604 
608  real_type
609  norm_sqr() const;
610 
615  virtual real_type
616  linfty_norm() const override;
617 
638  virtual Number
639  add_and_dot(const Number a,
640  const VectorSpaceVector<Number> &V,
641  const VectorSpaceVector<Number> &W) override;
642 
647  virtual size_type
648  size() const override;
649 
661  virtual ::IndexSet
662  locally_owned_elements() const override;
663 
667  virtual void
668  print(std::ostream & out,
669  const unsigned int precision = 3,
670  const bool scientific = true,
671  const bool across = true) const override;
672 
676  virtual std::size_t
677  memory_consumption() const override;
679 
690  DeclException0(ExcVectorTypeNotCompatible);
691 
695  DeclException0(ExcIteratorRangeDoesNotMatchVectorSize);
697  };
698 
701  } // end of namespace distributed
702 
703 } // end of namespace LinearAlgebra
704 
705 
714 template <typename Number>
715 inline void
718 {
719  u.swap(v);
720 }
721 
722 
729 template <typename Number>
731  : std::false_type
732 {};
733 
734 
736 
737 #ifdef DEAL_II_MSVC
738 # include <deal.II/lac/la_parallel_block_vector.templates.h>
739 #endif
740 
741 #endif
Matrix is symmetric.
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:621
Contents is actually a matrix.
types::global_dof_index size_type
Definition: cuda_kernels.h:45
std::vector< value_type > l2_norm(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:837
typename BaseClass::const_reference const_reference
__global__ void add_and_dot(Number *res, Number *v1, const Number *v2, const Number *v3, const Number a, const size_type N)
constexpr int block_size
Definition: cuda_size.h:29
static const char V
typename BaseClass::const_iterator const_iterator
void swap(BlockVector &u, BlockVector &v)
std::string compress(const std::string &input)
Definition: utilities.cc:392
BlockVector< double > BlockVector
Number linfty_norm(const Tensor< 2, dim, Number > &t)
Definition: tensor.h:2732
#define DeclException0(Exception0)
Definition: exceptions.h:473
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
void swap(BlockVector< Number > &v)
__global__ void equ(Number *val, const Number a, const Number *V_val, const size_type N)
__global__ void sadd(const Number s, Number *val, const Number a, const Number *V_val, const size_type N)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
typename BlockType::value_type value_type
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
typename BlockType::real_type real_type
Number l1_norm(const Tensor< 2, dim, Number > &t)
Definition: tensor.h:2705
static const char N
typename BlockType::const_reference const_reference
std::enable_if< std::is_floating_point< T >::value &&std::is_floating_point< U >::value, typename ProductType< std::complex< T >, std::complex< U > >::type >::type operator*(const std::complex< T > &left, const std::complex< U > &right)
typename BaseClass::const_pointer const_pointer
typename BlockType::reference reference
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)