Reference documentation for deal.II version Git 06d359936b 2020-09-19 18:16:22 -0400
\(\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  {
83  template <typename Number>
84  class BlockVector : public BlockVectorBase<Vector<Number>>,
85  public VectorSpaceVector<Number>
86  {
87  public:
100  static constexpr unsigned int communication_block_size = 20;
101 
106 
110  using BlockType = typename BaseClass::BlockType;
111 
116  using real_type = typename BaseClass::real_type;
117  using pointer = typename BaseClass::pointer;
119  using reference = typename BaseClass::reference;
121  using size_type = typename BaseClass::size_type;
122  using iterator = typename BaseClass::iterator;
124 
129 
140  explicit BlockVector(const size_type num_blocks = 0,
141  const size_type block_size = 0);
142 
148 
161  template <typename OtherNumber>
162  explicit BlockVector(const BlockVector<OtherNumber> &v);
163 
168  BlockVector(const std::vector<size_type> &block_sizes);
169 
174  BlockVector(const std::vector<IndexSet> &local_ranges,
175  const std::vector<IndexSet> &ghost_indices,
176  const MPI_Comm communicator);
177 
181  BlockVector(const std::vector<IndexSet> &local_ranges,
182  const MPI_Comm communicator);
183 
192  virtual ~BlockVector() override = default;
193 
198  virtual BlockVector &
199  operator=(const value_type s) override;
200 
205  BlockVector &
206  operator=(const BlockVector &V);
207 
212  template <class Number2>
213  BlockVector &
214  operator=(const BlockVector<Number2> &V);
215 
219  BlockVector &
220  operator=(const Vector<Number> &V);
221 
222 #ifdef DEAL_II_WITH_PETSC
223 
231  operator=(const PETScWrappers::MPI::BlockVector &petsc_vec);
232 #endif
233 
234 #ifdef DEAL_II_WITH_TRILINOS
235 
244  operator=(const TrilinosWrappers::MPI::BlockVector &trilinos_vec);
245 #endif
246 
260  void
261  reinit(const size_type num_blocks,
262  const size_type block_size = 0,
263  const bool omit_zeroing_entries = false);
264 
284  void
285  reinit(const std::vector<size_type> &N,
286  const bool omit_zeroing_entries = false);
287 
302  template <typename Number2>
303  void
305  const bool omit_zeroing_entries = false);
306 
330  virtual void
331  compress(::VectorOperation::values operation) override;
332 
341  void
342  update_ghost_values() const;
343 
352  void
353  zero_out_ghosts() const;
354 
358  bool
359  has_ghost_elements() const;
360 
365  template <typename OtherNumber>
366  void
367  add(const std::vector<size_type> & indices,
368  const ::Vector<OtherNumber> &values);
369 
374  void
375  sadd(const Number s, const BlockVector<Number> &V);
376 
382  virtual bool
383  all_zero() const override;
384 
388  virtual Number
389  mean_value() const override;
390 
395  real_type
396  lp_norm(const real_type p) const;
397 
415  void
418 
423 
428  virtual void
430  const bool omit_zeroing_entries = false) override;
431 
435  virtual BlockVector<Number> &
436  operator*=(const Number factor) override;
437 
441  virtual BlockVector<Number> &
442  operator/=(const Number factor) override;
443 
447  virtual BlockVector<Number> &
448  operator+=(const VectorSpaceVector<Number> &V) override;
449 
453  virtual BlockVector<Number> &
454  operator-=(const VectorSpaceVector<Number> &V) override;
455 
464  virtual void
465  import(
467  VectorOperation::values operation,
468  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
469  std::shared_ptr<const CommunicationPatternBase>()) override;
470 
474  virtual Number
475  operator*(const VectorSpaceVector<Number> &V) const override;
476 
493  template <typename FullMatrixType>
494  void
495  multivector_inner_product(FullMatrixType & matrix,
496  const BlockVector<Number> &V,
497  const bool symmetric = false) const;
498 
515  template <typename FullMatrixType>
516  Number
517  multivector_inner_product_with_metric(const FullMatrixType & matrix,
518  const BlockVector<Number> &V,
519  const bool symmetric = false) const;
520 
530  template <typename FullMatrixType>
531  void
532  mmult(BlockVector<Number> & V,
533  const FullMatrixType &matrix,
534  const Number s = Number(0.),
535  const Number b = Number(1.)) const;
536 
540  virtual void
541  add(const Number a) override;
542 
546  virtual void
547  add(const Number a, const VectorSpaceVector<Number> &V) override;
548 
552  virtual void
553  add(const Number a,
554  const VectorSpaceVector<Number> &V,
555  const Number b,
556  const VectorSpaceVector<Number> &W) override;
557 
562  virtual void
563  add(const std::vector<size_type> &indices,
564  const std::vector<Number> & values);
565 
570  virtual void
571  sadd(const Number s,
572  const Number a,
573  const VectorSpaceVector<Number> &V) override;
574 
580  virtual void
581  scale(const VectorSpaceVector<Number> &scaling_factors) override;
582 
586  virtual void
587  equ(const Number a, const VectorSpaceVector<Number> &V) override;
588 
593  virtual real_type
594  l1_norm() const override;
595 
600  virtual real_type
601  l2_norm() const override;
602 
606  real_type
607  norm_sqr() const;
608 
613  virtual real_type
614  linfty_norm() const override;
615 
636  virtual Number
637  add_and_dot(const Number a,
638  const VectorSpaceVector<Number> &V,
639  const VectorSpaceVector<Number> &W) override;
640 
645  virtual size_type
646  size() const override;
647 
659  virtual ::IndexSet
660  locally_owned_elements() const override;
661 
665  virtual void
666  print(std::ostream & out,
667  const unsigned int precision = 3,
668  const bool scientific = true,
669  const bool across = true) const override;
670 
674  virtual std::size_t
675  memory_consumption() const override;
677 
688  DeclException0(ExcVectorTypeNotCompatible);
689 
693  DeclException0(ExcIteratorRangeDoesNotMatchVectorSize);
695  };
696 
699  } // end of namespace distributed
700 
701 } // end of namespace LinearAlgebra
702 
703 
711 template <typename Number>
712 inline void
715 {
716  u.swap(v);
717 }
718 
719 
724 template <typename Number>
726  : std::false_type
727 {};
728 
729 
731 
732 #ifdef DEAL_II_MSVC
733 # include <deal.II/lac/la_parallel_block_vector.templates.h>
734 #endif
735 
736 #endif
Matrix is symmetric.
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:618
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:835
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:2811
#define DeclException0(Exception0)
Definition: exceptions.h:470
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
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:362
typename BlockType::real_type real_type
Number l1_norm(const Tensor< 2, dim, Number > &t)
Definition: tensor.h:2785
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)