preconditioner.hpp 6.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
// **************************************************************************
//
//    PARALUTION   www.paralution.com
//
//    Copyright (C) 2015  PARALUTION Labs UG (haftungsbeschränkt) & Co. KG
//                        Am Hasensprung 6, 76571 Gaggenau
//                        Handelsregister: Amtsgericht Mannheim, HRA 706051
//                        Vertreten durch:
//                        PARALUTION Labs Verwaltungs UG (haftungsbeschränkt)
//                        Am Hasensprung 6, 76571 Gaggenau
//                        Handelsregister: Amtsgericht Mannheim, HRB 721277
//                        Geschäftsführer: Dimitar Lukarski, Nico Trost
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// **************************************************************************



// PARALUTION version 1.1.0 


#ifndef PARALUTION_PRECONDITIONER_HPP_
#define PARALUTION_PRECONDITIONER_HPP_

#include "../solver.hpp"

namespace paralution {

/// Base preconditioner class
template <class OperatorType, class VectorType, typename ValueType>
class Preconditioner : public Solver<OperatorType, VectorType, ValueType> {

public:

  Preconditioner();
  virtual ~Preconditioner();

  virtual void SolveZeroSol(const VectorType &rhs,
                            VectorType *x);

protected:

  virtual void PrintStart_(void) const;
  virtual void PrintEnd_(void) const;


};

//// Jacobi preconditioner
template <class OperatorType, class VectorType, typename ValueType>
class Jacobi : public Preconditioner<OperatorType, VectorType, ValueType> {

public:

  Jacobi();
  virtual ~Jacobi();

  virtual void Print(void) const;
  virtual void Solve(const VectorType &rhs,
                     VectorType *x);
  virtual void Build(void);
  virtual void Clear(void);

  virtual void ResetOperator(const OperatorType &op);

protected:

  virtual void MoveToHostLocalData_(void);
  virtual void MoveToAcceleratorLocalData_(void) ;


private:

  VectorType inv_diag_entries_;

};

/// Gauss-Seidel (GS) preconditioner
template <class OperatorType, class VectorType, typename ValueType>
class GS : public Preconditioner<OperatorType, VectorType, ValueType> {

public:

  GS();
  virtual ~GS();

  virtual void Print(void) const;
  virtual void Solve(const VectorType &rhs,
                     VectorType *x);
  virtual void Build(void);
  virtual void Clear(void);

  virtual void ResetOperator(const OperatorType &op);

protected:

  virtual void MoveToHostLocalData_(void);
  virtual void MoveToAcceleratorLocalData_(void);


private:

  OperatorType GS_;

};

/// Symmetric Gauss-Seidel (SGS) preconditioner
template <class OperatorType, class VectorType, typename ValueType>
class SGS : public Preconditioner<OperatorType, VectorType, ValueType> {

public:

  SGS();
  virtual ~SGS();

  virtual void Print(void) const;
  virtual void Solve(const VectorType &rhs,
                     VectorType *x);
  virtual void Build(void);
  virtual void Clear(void);

  virtual void ResetOperator(const OperatorType &op);

protected:

  virtual void MoveToHostLocalData_(void);
  virtual void MoveToAcceleratorLocalData_(void);


private:

  OperatorType SGS_;

  VectorType diag_entries_;
  VectorType v_;

};

/// ILU preconditioner based on levels
template <class OperatorType, class VectorType, typename ValueType>
class ILU : public Preconditioner<OperatorType, VectorType, ValueType> {

public:

  ILU();
  virtual ~ILU();

  virtual void Print(void) const;  
  virtual void Solve(const VectorType &rhs,
                     VectorType *x);

  /// Initialize ILU(p) factorization based on power (see power(q)-pattern method, 
  /// D. Lukarski "Parallel Sparse Linear Algebra for Multi-core and Many-core 
  /// Platforms - Parallel Solvers and Preconditioners", PhD Thesis, 2012, KIT) 
  /// level==true build the structure based on levels; level==false build the
  /// structure only based on the power(p+1)
  virtual void Set(const int p, const bool level=true);
  virtual void Build(void);
  virtual void Clear(void);  


protected:

  virtual void MoveToHostLocalData_(void);
  virtual void MoveToAcceleratorLocalData_(void);


private:

  OperatorType ILU_;
  int p_;
  bool level_;

};

/// ILUT(t,m) preconditioner based on threshold and maximum number
/// of elements per row
template <class OperatorType, class VectorType, typename ValueType>
class ILUT : public Preconditioner<OperatorType, VectorType, ValueType> {

public:

  ILUT();
  virtual ~ILUT();

  virtual void Print(void) const;  
  virtual void Solve(const VectorType &rhs,
                     VectorType *x);

  /// ILUT with threshold
  virtual void Set(const double t);

  /// ILUT with threshold and maximum number of elements per row
  virtual void Set(const double t, const int maxrow);

  virtual void Build(void);
  virtual void Clear(void);  


protected:

  virtual void MoveToHostLocalData_(void);
  virtual void MoveToAcceleratorLocalData_(void);


private:

  OperatorType ILUT_;
  double t_;
  int max_row_;

};

/// Incomplete Cholesky with no fill-ins IC0
template <class OperatorType, class VectorType, typename ValueType>
class IC : public Preconditioner<OperatorType, VectorType, ValueType> {

public:

  IC();
  virtual ~IC();

  virtual void Print(void) const;  
  virtual void Solve(const VectorType &rhs,
                     VectorType *x);
  virtual void Build(void);
  virtual void Clear(void);  


protected:

  virtual void MoveToHostLocalData_(void);
  virtual void MoveToAcceleratorLocalData_(void);


private:

  OperatorType IC_;
  VectorType inv_diag_entries_;

};


}

#endif // PARALUTION_PRECONDITIONER_HPP_