monolish  0.16.0
MONOlithic LInear equation Solvers for Highly-parallel architecture
monolish_equation.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <vector>
3 
4 #include "./monolish_solver.hpp"
6 #include <functional>
7 
8 namespace monolish {
13 namespace equation {
14 
40 template <typename MATRIX, typename Float>
41 class none : public monolish::solver::solver<MATRIX, Float> {
42 public:
43  void create_precond(MATRIX &A);
44  void apply_precond(const vector<Float> &r, vector<Float> &z);
45  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
46 
54  [[nodiscard]] std::string name() const { return "monolish::equation::none"; }
55 
63  [[nodiscard]] std::string solver_name() const { return "none"; }
64 };
87 template <typename MATRIX, typename Float>
88 class CG : public monolish::solver::solver<MATRIX, Float> {
89 private:
90  [[nodiscard]] int monolish_CG(MATRIX &A, vector<Float> &x, vector<Float> &b);
91 
92 public:
101  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
102 
103  void create_precond(MATRIX &A) {
104  throw std::runtime_error("this precond. is not impl.");
105  }
106 
108  throw std::runtime_error("this precond. is not impl.");
109  }
110 
118  [[nodiscard]] std::string name() const { return "monolish::equation::CG"; }
119 
127  [[nodiscard]] std::string solver_name() const { return "CG"; }
128 };
152 template <typename MATRIX, typename Float>
153 class BiCGSTAB : public monolish::solver::solver<MATRIX, Float> {
154 private:
155  [[nodiscard]] int monolish_BiCGSTAB(MATRIX &A, vector<Float> &x,
156  vector<Float> &b);
157 
158 public:
167  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
168 
169  void create_precond(MATRIX &A) {
170  throw std::runtime_error("this precond. is not impl.");
171  }
172 
174  throw std::runtime_error("this precond. is not impl.");
175  }
176 
184  [[nodiscard]] std::string name() const {
185  return "monolish::equation::BiCGSTAB";
186  }
187 
195  [[nodiscard]] std::string solver_name() const { return "BiCGSTAB"; }
196 };
219 template <typename MATRIX, typename Float>
220 class Jacobi : public monolish::solver::solver<MATRIX, Float> {
221 private:
222  [[nodiscard]] int monolish_Jacobi(MATRIX &A, vector<Float> &x,
223  vector<Float> &b);
224 
225 public:
234  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
235  void create_precond(MATRIX &A);
236  void apply_precond(const vector<Float> &r, vector<Float> &z);
237 
245  [[nodiscard]] std::string name() const {
246  return "monolish::equation::Jacobi";
247  }
248 
256  [[nodiscard]] std::string solver_name() const { return "Jacobi"; }
257 };
285 template <typename MATRIX, typename Float>
286 class SOR : public monolish::solver::solver<MATRIX, Float> {
287 private:
288  [[nodiscard]] int monolish_SOR(MATRIX &A, vector<Float> &x, vector<Float> &b);
289 
290 public:
304  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
305  void create_precond(MATRIX &A);
306  void apply_precond(const vector<Float> &r, vector<Float> &z);
307 
315  [[nodiscard]] std::string name() const { return "monolish::equation::SOR"; }
316 
324  [[nodiscard]] std::string solver_name() const { return "SOR"; }
325 };
348 template <typename MATRIX, typename Float>
349 class IC : public monolish::solver::solver<MATRIX, Float> {
350 private:
351  int cusparse_IC(MATRIX &A, vector<Float> &x, vector<Float> &b);
352  void *matM = 0, *matL = 0;
353  void *infoM = 0, *infoL = 0, *infoLt = 0;
355  int bufsize;
358 
359 public:
360  ~IC();
366  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
367  void create_precond(MATRIX &A);
368  void apply_precond(const vector<Float> &r, vector<Float> &z);
369 
377  std::string name() const { return "monolish::equation::IC"; }
378 
386  std::string solver_name() const { return "IC"; }
387 };
410 template <typename MATRIX, typename Float>
411 class ILU : public monolish::solver::solver<MATRIX, Float> {
412 private:
413  int cusparse_ILU(MATRIX &A, vector<Float> &x, vector<Float> &b);
414  void *matM = 0, *matL = 0, *matU = 0;
415  void *infoM = 0, *infoL = 0, *infoU = 0;
417  int bufsize;
420 
421 public:
422  ~ILU();
428  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
429  void create_precond(MATRIX &A);
430  void apply_precond(const vector<Float> &r, vector<Float> &z);
431 
439  std::string name() const { return "monolish::equation::ILU"; }
440 
448  std::string solver_name() const { return "ILU"; }
449 };
472 template <typename MATRIX, typename Float>
473 class LU : public monolish::solver::solver<MATRIX, Float> {
474 private:
475  int lib = 1; // lib is 1
476  [[nodiscard]] int mumps_LU(MATRIX &A, vector<double> &x, vector<double> &b);
477  [[nodiscard]] int cusolver_LU(MATRIX &A, vector<double> &x,
478  vector<double> &b);
479 
480 public:
481  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
482  [[nodiscard]] int solve(MATRIX &A, vector<Float> &xb);
483 
484  void create_precond(MATRIX &A) {
485  throw std::runtime_error("this precond. is not impl.");
486  }
488  throw std::runtime_error("this precond. is not impl.");
489  }
490 
498  [[nodiscard]] std::string name() const { return "monolish::equation::LU"; }
499 
507  [[nodiscard]] std::string solver_name() const { return "LU"; }
508 };
531 template <typename MATRIX, typename Float>
532 class QR : public monolish::solver::solver<MATRIX, Float> {
533 private:
534  int lib = 1; // lib is 1
535  [[nodiscard]] int cusolver_QR(MATRIX &A, vector<double> &x,
536  vector<double> &b);
537  [[nodiscard]] int cusolver_QR(MATRIX &A, vector<float> &x, vector<float> &b);
538 
539 public:
543  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
544  void create_precond(MATRIX &A) {
545  throw std::runtime_error("this precond. is not impl.");
546  }
548  throw std::runtime_error("this precond. is not impl.");
549  }
550 
558  [[nodiscard]] std::string name() const { return "monolish::equation::QR"; }
559 
567  [[nodiscard]] std::string solver_name() const { return "QR"; }
568 };
591 template <typename MATRIX, typename Float>
592 class Cholesky : public monolish::solver::solver<MATRIX, Float> {
593 private:
594  int lib = 1; // lib is 1
595  [[nodiscard]] int cusolver_Cholesky(MATRIX &A, vector<float> &x,
596  vector<float> &b);
597  [[nodiscard]] int cusolver_Cholesky(MATRIX &A, vector<double> &x,
598  vector<double> &b);
599 
600 public:
604  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
605  [[nodiscard]] int solve(MATRIX &A, vector<Float> &xb);
606 
608  throw std::runtime_error("this precond. is not impl.");
609  }
611  throw std::runtime_error("this precond. is not impl.");
612  }
613 
621  [[nodiscard]] std::string name() const {
622  return "monolish::equation::Cholesky";
623  }
624 
632  [[nodiscard]] std::string solver_name() const { return "Cholesky"; }
633 };
637 } // namespace equation
638 } // namespace monolish
monolish::equation::BiCGSTAB
BiCGSTAB solver class.
Definition: monolish_equation.hpp:153
monolish::equation::LU::cusolver_LU
int cusolver_LU(MATRIX &A, vector< double > &x, vector< double > &b)
monolish::equation::IC::infoM
void * infoM
Definition: monolish_equation.hpp:353
monolish::equation::IC::infoLt
void * infoLt
Definition: monolish_equation.hpp:353
monolish::equation::QR::cusolver_QR
int cusolver_QR(MATRIX &A, vector< double > &x, vector< double > &b)
monolish::equation::ILU::matU
void * matU
Definition: monolish_equation.hpp:414
monolish::equation::none::create_precond
void create_precond(MATRIX &A)
monolish::equation::IC::matL
void * matL
Definition: monolish_equation.hpp:352
monolish::equation::SOR::monolish_SOR
int monolish_SOR(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::equation::IC::infoL
void * infoL
Definition: monolish_equation.hpp:353
monolish::equation::BiCGSTAB::solver_name
std::string solver_name() const
get solver name "BiCGSTAB"
Definition: monolish_equation.hpp:195
monolish::equation::Jacobi::create_precond
void create_precond(MATRIX &A)
monolish::equation::BiCGSTAB::monolish_BiCGSTAB
int monolish_BiCGSTAB(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::equation::IC::cusparse_handle
void * cusparse_handle
Definition: monolish_equation.hpp:354
monolish::equation::Jacobi::name
std::string name() const
get solver name "monolish::equation::Jacobi"
Definition: monolish_equation.hpp:245
monolish::equation::SOR::solver_name
std::string solver_name() const
get solver name "SOR"
Definition: monolish_equation.hpp:324
monolish::equation::Cholesky::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax=b
monolish::equation::ILU::infoU
void * infoU
Definition: monolish_equation.hpp:415
monolish::equation::IC::zbuf
monolish::vector< Float > zbuf
Definition: monolish_equation.hpp:357
monolish::equation::Jacobi::monolish_Jacobi
int monolish_Jacobi(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::equation::QR::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:544
monolish::equation::ILU::buf
monolish::vector< double > buf
Definition: monolish_equation.hpp:418
monolish::equation::ILU::~ILU
~ILU()
monolish::equation::IC::name
std::string name() const
get solver name "monolish::equation::IC"
Definition: monolish_equation.hpp:377
monolish::equation::ILU::cusparse_ILU
int cusparse_ILU(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::equation::Cholesky
Cholesky solver class.
Definition: monolish_equation.hpp:592
monolish::equation::ILU::solver_name
std::string solver_name() const
get solver name "ILU"
Definition: monolish_equation.hpp:448
monolish::equation::IC::matM
void * matM
Definition: monolish_equation.hpp:352
monolish::equation::IC::buf
monolish::vector< double > buf
Definition: monolish_equation.hpp:356
monolish::equation::Cholesky::name
std::string name() const
get solver name "monolish::equation::Cholesky"
Definition: monolish_equation.hpp:621
monolish::equation::IC
Incomplete Cholesky solver class.
Definition: monolish_equation.hpp:349
monolish::equation::BiCGSTAB::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:173
monolish::equation::Cholesky::cusolver_Cholesky
int cusolver_Cholesky(MATRIX &A, vector< float > &x, vector< float > &b)
monolish_common.hpp
monolish::equation::SOR
SOR solver class.
Definition: monolish_equation.hpp:286
monolish::equation::IC::cusparse_IC
int cusparse_IC(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::equation::LU::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:484
monolish::equation::none::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
monolish::equation::CG::monolish_CG
int monolish_CG(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::equation::BiCGSTAB::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:169
monolish::equation::SOR::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
monolish::solver::solver
solver base class
Definition: monolish_solver.hpp:32
monolish::equation::CG
CG solver class.
Definition: monolish_equation.hpp:88
monolish::equation::LU
LU solver class.
Definition: monolish_equation.hpp:473
monolish::equation::ILU::create_precond
void create_precond(MATRIX &A)
monolish::equation::IC::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve with incomplete Cholesky factorization
monolish::equation::ILU::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
monolish::equation::IC::solver_name
std::string solver_name() const
get solver name "IC"
Definition: monolish_equation.hpp:386
monolish::equation::ILU::zbuf
monolish::vector< Float > zbuf
Definition: monolish_equation.hpp:419
monolish::equation::Jacobi::solver_name
std::string solver_name() const
get solver name "Jacobi"
Definition: monolish_equation.hpp:256
monolish::equation::IC::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
monolish::equation::Cholesky::lib
int lib
Definition: monolish_equation.hpp:594
monolish::equation::QR::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax=b
monolish::equation::LU::mumps_LU
int mumps_LU(MATRIX &A, vector< double > &x, vector< double > &b)
monolish::equation::ILU::matL
void * matL
Definition: monolish_equation.hpp:414
monolish
monolish namespaces
Definition: monolish_matrix_blas.hpp:5
monolish::equation::Cholesky::solver_name
std::string solver_name() const
get solver name "Cholesky"
Definition: monolish_equation.hpp:632
monolish::equation::IC::create_precond
void create_precond(MATRIX &A)
monolish::equation::CG::name
std::string name() const
get solver name "monolish::equation::CG"
Definition: monolish_equation.hpp:118
monolish::equation::Jacobi::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by jacobi method(lib=0: monolish)
monolish::equation::BiCGSTAB::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by BiCGSTAB method (lib=0: monolish)
monolish_solver.hpp
monolish::equation::QR
QR solver class.
Definition: monolish_equation.hpp:532
monolish::equation::CG::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:107
monolish::equation::LU::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:487
monolish::equation::SOR::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by SOR method(lib=0: monolish)
monolish::equation::QR::solver_name
std::string solver_name() const
get solver name "QR"
Definition: monolish_equation.hpp:567
monolish::equation::ILU::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve with incomplete LU factorization
monolish::equation::LU::solver_name
std::string solver_name() const
get solver name "LU"
Definition: monolish_equation.hpp:507
monolish::equation::BiCGSTAB::name
std::string name() const
get solver name "monolish::equation::BiCGSTAB"
Definition: monolish_equation.hpp:184
monolish::equation::LU::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::vector
vector class
Definition: monolish_coo.hpp:25
monolish::equation::Cholesky::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:610
monolish::equation::ILU
Incomplete LU solver class.
Definition: monolish_equation.hpp:411
monolish::equation::CG::solver_name
std::string solver_name() const
get solver name "CG"
Definition: monolish_equation.hpp:127
monolish::equation::ILU::cusparse_handle
void * cusparse_handle
Definition: monolish_equation.hpp:416
monolish::equation::IC::bufsize
int bufsize
Definition: monolish_equation.hpp:355
monolish::equation::LU::name
std::string name() const
get solver name "monolish::equation::LU"
Definition: monolish_equation.hpp:498
monolish::equation::SOR::create_precond
void create_precond(MATRIX &A)
monolish::equation::QR::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:547
monolish::equation::IC::~IC
~IC()
monolish::equation::QR::name
std::string name() const
get solver name "monolish::equation::QR"
Definition: monolish_equation.hpp:558
monolish::equation::LU::lib
int lib
Definition: monolish_equation.hpp:475
monolish::equation::CG::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:103
monolish::equation::ILU::infoL
void * infoL
Definition: monolish_equation.hpp:415
monolish::equation::ILU::name
std::string name() const
get solver name "monolish::equation::ILU"
Definition: monolish_equation.hpp:439
monolish::equation::CG::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by BiCGSTAB method(lib=0: monolish)
monolish::equation::none
none solver class(nothing to do)
Definition: monolish_equation.hpp:41
monolish::equation::ILU::matM
void * matM
Definition: monolish_equation.hpp:414
monolish::equation::ILU::bufsize
int bufsize
Definition: monolish_equation.hpp:417
monolish::equation::Jacobi
Jacobi solver class.
Definition: monolish_equation.hpp:220
monolish::equation::SOR::name
std::string name() const
get solver name "monolish::equation::SOR"
Definition: monolish_equation.hpp:315
monolish::matrix::CRS
Compressed Row Storage (CRS) format Matrix.
Definition: monolish_coo.hpp:29
monolish::equation::ILU::infoM
void * infoM
Definition: monolish_equation.hpp:415
monolish::equation::none::name
std::string name() const
get solver name "monolish::equation::none"
Definition: monolish_equation.hpp:54
monolish::equation::none::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::equation::Cholesky::create_precond
void create_precond(matrix::CRS< Float > &A)
Definition: monolish_equation.hpp:607
monolish::equation::QR::lib
int lib
Definition: monolish_equation.hpp:534
monolish::equation::Jacobi::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
monolish::equation::none::solver_name
std::string solver_name() const
get solver name "none"
Definition: monolish_equation.hpp:63