monolish
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 
13 namespace monolish::equation {
14 
30 template <typename MATRIX, typename Float>
31 class none : public monolish::solver::solver<MATRIX, Float> {
32 public:
33  void create_precond(MATRIX &A);
34  void apply_precond(const vector<Float> &r, vector<Float> &z);
35  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
36 
44  [[nodiscard]] std::string name() const { return "monolish::equation::none"; }
45 
53  [[nodiscard]] std::string solver_name() const { return "none"; }
54 };
55 
71 template <typename MATRIX, typename Float>
72 class CG : public monolish::solver::solver<MATRIX, Float> {
73 private:
74  [[nodiscard]] int monolish_CG(MATRIX &A, vector<Float> &x, vector<Float> &b);
75 
76 public:
85  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
86 
87  void create_precond(MATRIX &A) {
88  throw std::runtime_error("this precond. is not impl.");
89  }
90 
92  throw std::runtime_error("this precond. is not impl.");
93  }
94 
102  [[nodiscard]] std::string name() const { return "monolish::equation::CG"; }
103 
111  [[nodiscard]] std::string solver_name() const { return "CG"; }
112 };
113 
129 template <typename MATRIX, typename Float>
130 class BiCGSTAB : public monolish::solver::solver<MATRIX, Float> {
131 private:
132  [[nodiscard]] int monolish_BiCGSTAB(MATRIX &A, vector<Float> &x,
133  vector<Float> &b);
134 
135 public:
144  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
145 
146  void create_precond(MATRIX &A) {
147  throw std::runtime_error("this precond. is not impl.");
148  }
149 
151  throw std::runtime_error("this precond. is not impl.");
152  }
153 
161  [[nodiscard]] std::string name() const {
162  return "monolish::equation::BiCGSTAB";
163  }
164 
172  [[nodiscard]] std::string solver_name() const { return "BiCGSTAB"; }
173 };
174 
190 template <typename MATRIX, typename Float>
191 class Jacobi : public monolish::solver::solver<MATRIX, Float> {
192 private:
193  [[nodiscard]] int monolish_Jacobi(MATRIX &A, vector<Float> &x,
194  vector<Float> &b);
195 
196 public:
205  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
206  void create_precond(MATRIX &A);
207  void apply_precond(const vector<Float> &r, vector<Float> &z);
208 
216  [[nodiscard]] std::string name() const {
217  return "monolish::equation::Jacobi";
218  }
219 
227  [[nodiscard]] std::string solver_name() const { return "Jacobi"; }
228 };
229 
250 template <typename MATRIX, typename Float>
251 class SOR : public monolish::solver::solver<MATRIX, Float> {
252 private:
253  [[nodiscard]] int monolish_SOR(MATRIX &A, vector<Float> &x, vector<Float> &b);
254 
255 public:
269  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
270  void create_precond(MATRIX &A);
271  void apply_precond(const vector<Float> &r, vector<Float> &z);
272 
280  [[nodiscard]] std::string name() const { return "monolish::equation::SOR"; }
281 
289  [[nodiscard]] std::string solver_name() const { return "SOR"; }
290 };
291 
307 template <typename MATRIX, typename Float>
308 class LU : public monolish::solver::solver<MATRIX, Float> {
309 private:
310  int lib = 1; // lib is 1
311  [[nodiscard]] int mumps_LU(MATRIX &A, vector<double> &x, vector<double> &b);
312  [[nodiscard]] int cusolver_LU(MATRIX &A, vector<double> &x,
313  vector<double> &b);
314 
315 public:
316  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
317  [[nodiscard]] int solve(MATRIX &A, vector<Float> &xb);
318 
319  void create_precond(MATRIX &A) {
320  throw std::runtime_error("this precond. is not impl.");
321  }
323  throw std::runtime_error("this precond. is not impl.");
324  }
325 
333  [[nodiscard]] std::string name() const { return "monolish::equation::LU"; }
334 
342  [[nodiscard]] std::string solver_name() const { return "LU"; }
343 };
344 
360 template <typename MATRIX, typename Float>
361 class QR : public monolish::solver::solver<MATRIX, Float> {
362 private:
363  int lib = 1; // lib is 1
364  [[nodiscard]] int cusolver_QR(MATRIX &A, vector<double> &x,
365  vector<double> &b);
366  [[nodiscard]] int cusolver_QR(MATRIX &A, vector<float> &x, vector<float> &b);
367 
368 public:
372  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
373  void create_precond(MATRIX &A) {
374  throw std::runtime_error("this precond. is not impl.");
375  }
377  throw std::runtime_error("this precond. is not impl.");
378  }
379 
387  [[nodiscard]] std::string name() const { return "monolish::equation::QR"; }
388 
396  [[nodiscard]] std::string solver_name() const { return "QR"; }
397 };
398 
414 template <typename MATRIX, typename Float>
415 class Cholesky : public monolish::solver::solver<MATRIX, Float> {
416 private:
417  int lib = 1; // lib is 1
418  [[nodiscard]] int cusolver_Cholesky(MATRIX &A, vector<float> &x,
419  vector<float> &b);
420  [[nodiscard]] int cusolver_Cholesky(MATRIX &A, vector<double> &x,
421  vector<double> &b);
422 
423 public:
427  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
428  [[nodiscard]] int solve(MATRIX &A, vector<Float> &xb);
429 
431  throw std::runtime_error("this precond. is not impl.");
432  }
434  throw std::runtime_error("this precond. is not impl.");
435  }
436 
444  [[nodiscard]] std::string name() const {
445  return "monolish::equation::Cholesky";
446  }
447 
455  [[nodiscard]] std::string solver_name() const { return "Cholesky"; }
456 };
457 
458 } // namespace monolish::equation
monolish::equation::BiCGSTAB
BiCGSTAB solver class.
Definition: monolish_equation.hpp:130
monolish::equation::LU::cusolver_LU
int cusolver_LU(MATRIX &A, vector< double > &x, vector< double > &b)
monolish::equation::QR::cusolver_QR
int cusolver_QR(MATRIX &A, vector< double > &x, vector< double > &b)
monolish::equation::none::create_precond
void create_precond(MATRIX &A)
monolish::equation::SOR::monolish_SOR
int monolish_SOR(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::equation::BiCGSTAB::solver_name
std::string solver_name() const
get solver name "BiCGSTAB"
Definition: monolish_equation.hpp:172
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::Jacobi::name
std::string name() const
get solver name "monolish::equation::Jacobi"
Definition: monolish_equation.hpp:216
monolish::equation::SOR::solver_name
std::string solver_name() const
get solver name "SOR"
Definition: monolish_equation.hpp:289
monolish::equation::Cholesky::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax=b
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:373
monolish::equation::Cholesky
Cholesky solver class.
Definition: monolish_equation.hpp:415
monolish::equation::Cholesky::name
std::string name() const
get solver name "monolish::equation::Cholesky"
Definition: monolish_equation.hpp:444
monolish::equation::BiCGSTAB::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:150
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:251
monolish::equation::LU::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:319
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:146
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:27
monolish::equation::CG
CG solver class.
Definition: monolish_equation.hpp:72
monolish::equation::LU
LU solver class.
Definition: monolish_equation.hpp:308
monolish::equation::Jacobi::solver_name
std::string solver_name() const
get solver name "Jacobi"
Definition: monolish_equation.hpp:227
monolish::equation::Cholesky::lib
int lib
Definition: monolish_equation.hpp:417
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::Cholesky::solver_name
std::string solver_name() const
get solver name "Cholesky"
Definition: monolish_equation.hpp:455
monolish::equation::CG::name
std::string name() const
get solver name "monolish::equation::CG"
Definition: monolish_equation.hpp:102
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:361
monolish::equation::CG::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:91
monolish::equation::LU::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:322
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:396
monolish::equation::LU::solver_name
std::string solver_name() const
get solver name "LU"
Definition: monolish_equation.hpp:342
monolish::equation::BiCGSTAB::name
std::string name() const
get solver name "monolish::equation::BiCGSTAB"
Definition: monolish_equation.hpp:161
monolish::equation
Linear equation solvers for Dense and sparse matrix Scalar.
Definition: monolish_equation.hpp:13
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:433
monolish::equation::CG::solver_name
std::string solver_name() const
get solver name "CG"
Definition: monolish_equation.hpp:111
monolish::equation::LU::name
std::string name() const
get solver name "monolish::equation::LU"
Definition: monolish_equation.hpp:333
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:376
monolish::equation::QR::name
std::string name() const
get solver name "monolish::equation::QR"
Definition: monolish_equation.hpp:387
monolish::equation::LU::lib
int lib
Definition: monolish_equation.hpp:310
monolish::equation::CG::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:87
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:31
monolish::equation::Jacobi
Jacobi solver class.
Definition: monolish_equation.hpp:191
monolish::equation::SOR::name
std::string name() const
get solver name "monolish::equation::SOR"
Definition: monolish_equation.hpp:280
monolish::matrix::CRS
Compressed Row Storage (CRS) format Matrix.
Definition: monolish_coo.hpp:29
monolish::equation::none::name
std::string name() const
get solver name "monolish::equation::none"
Definition: monolish_equation.hpp:44
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:430
monolish::equation::QR::lib
int lib
Definition: monolish_equation.hpp:363
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:53