DiagonalPreconditioner.h
Go to the documentation of this file.
1 /*
2  * DiagonalPreconditioner.h
3  *
4  * Created on: Apr 23, 2016
5  * Author: Michael Wegner (michael.wegner@student.kit.edu)
6  */
7
8 #ifndef NETWORKIT_CPP_NUMERICS_PRECONDITIONER_DIAGONALPRECONDITIONER_H_
9 #define NETWORKIT_CPP_NUMERICS_PRECONDITIONER_DIAGONALPRECONDITIONER_H_
10
11 #include "../../algebraic/CSRMatrix.h"
12
13 namespace NetworKit {
14
21 public:
23  DiagonalPreconditioner() = default;
24
29  DiagonalPreconditioner(const CSRMatrix& A) : inv_diag(A.numberOfRows()) {
30  assert(A.numberOfColumns() == A.numberOfRows());
31
32  // Diagonal preconditioner just needs to store the inverse diagonal of A
33  inv_diag = A.diagonal();
34 #pragma omp parallel for
35  for (index i = 0; i < inv_diag.getDimension(); ++i) {
36  if (inv_diag[i]) inv_diag[i] = 1.0 / inv_diag[i];
37  }
38  }
39
40  virtual ~DiagonalPreconditioner() = default;
41
45  Vector rhs(const Vector& b) const {
46  assert(b.getDimension() == inv_diag.getDimension());
47  Vector out(b.getDimension());
48  for (index i = 0; i < b.getDimension(); ++i) {
49  out[i] = inv_diag[i] * b[i];
50  }
51  return out;
52  }
53
54 private:
55  Vector inv_diag;
56 };
57
58 } /* namespace NetworKit */
59
60 #endif /* NETWORKIT_CPP_NUMERICS_PRECONDITIONER_DIAGONALPRECONDITIONER_H_ */
count getDimension() const
Definition: Vector.h:74
count numberOfColumns() const
Definition: CSRMatrix.h:178
uint64_t index
Typedefs.
Definition: Globals.h:20
count numberOfRows() const
Definition: CSRMatrix.h:171
Simple preconditioner that approximates the matrix by a diagonal matrix.
Definition: DiagonalPreconditioner.h:20
DiagonalPreconditioner()=default
Default constructor.
The Vector class represents a basic vector with double coefficients.
Definition: Vector.h:25
The CSRMatrix class represents a sparse matrix stored in CSR-Format (i.e.
Definition: CSRMatrix.h:26
Vector diagonal() const
Definition: CSRMatrix.cpp:263
Vector rhs(const Vector &b) const
Returns the preconditioned right-hand-side .
Definition: DiagonalPreconditioner.h:45
virtual ~DiagonalPreconditioner()=default
DiagonalPreconditioner(const CSRMatrix &A)
Constructs a diagonal preconditioner for the matrix A.
Definition: DiagonalPreconditioner.h:29