monolish  0.15.1
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 IC : public monolish::solver::solver<MATRIX, Float> {
309 private:
310  int cusparse_IC(MATRIX &A, vector<Float> &x, vector<Float> &b);
311  void *matM = 0, *matL = 0;
312  void *infoM = 0, *infoL = 0, *infoLt = 0;
314  int bufsize;
317 
318 public:
319  ~IC();
325  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
326  void create_precond(MATRIX &A);
327  void apply_precond(const vector<Float> &r, vector<Float> &z);
328 
336  std::string name() const { return "monolish::equation::IC"; }
337 
345  std::string solver_name() const { return "IC"; }
346 };
347 
363 template <typename MATRIX, typename Float>
364 class ILU : public monolish::solver::solver<MATRIX, Float> {
365 private:
366  int cusparse_ILU(MATRIX &A, vector<Float> &x, vector<Float> &b);
367  void *matM = 0, *matL = 0, *matU = 0;
368  void *infoM = 0, *infoL = 0, *infoU = 0;
370  int bufsize;
373 
374 public:
375  ~ILU();
381  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
382  void create_precond(MATRIX &A);
383  void apply_precond(const vector<Float> &r, vector<Float> &z);
384 
392  std::string name() const { return "monolish::equation::ILU"; }
393 
401  std::string solver_name() const { return "ILU"; }
402 };
403 
419 template <typename MATRIX, typename Float>
420 class LU : public monolish::solver::solver<MATRIX, Float> {
421 private:
422  int lib = 1; // lib is 1
423  [[nodiscard]] int mumps_LU(MATRIX &A, vector<double> &x, vector<double> &b);
424  [[nodiscard]] int cusolver_LU(MATRIX &A, vector<double> &x,
425  vector<double> &b);
426 
427 public:
428  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
429  [[nodiscard]] int solve(MATRIX &A, vector<Float> &xb);
430 
431  void create_precond(MATRIX &A) {
432  throw std::runtime_error("this precond. is not impl.");
433  }
435  throw std::runtime_error("this precond. is not impl.");
436  }
437 
445  [[nodiscard]] std::string name() const { return "monolish::equation::LU"; }
446 
454  [[nodiscard]] std::string solver_name() const { return "LU"; }
455 };
456 
472 template <typename MATRIX, typename Float>
473 class QR : public monolish::solver::solver<MATRIX, Float> {
474 private:
475  int lib = 1; // lib is 1
476  [[nodiscard]] int cusolver_QR(MATRIX &A, vector<double> &x,
477  vector<double> &b);
478  [[nodiscard]] int cusolver_QR(MATRIX &A, vector<float> &x, vector<float> &b);
479 
480 public:
484  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
485  void create_precond(MATRIX &A) {
486  throw std::runtime_error("this precond. is not impl.");
487  }
489  throw std::runtime_error("this precond. is not impl.");
490  }
491 
499  [[nodiscard]] std::string name() const { return "monolish::equation::QR"; }
500 
508  [[nodiscard]] std::string solver_name() const { return "QR"; }
509 };
510 
526 template <typename MATRIX, typename Float>
527 class Cholesky : public monolish::solver::solver<MATRIX, Float> {
528 private:
529  int lib = 1; // lib is 1
530  [[nodiscard]] int cusolver_Cholesky(MATRIX &A, vector<float> &x,
531  vector<float> &b);
532  [[nodiscard]] int cusolver_Cholesky(MATRIX &A, vector<double> &x,
533  vector<double> &b);
534 
535 public:
539  [[nodiscard]] int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
540  [[nodiscard]] int solve(MATRIX &A, vector<Float> &xb);
541 
543  throw std::runtime_error("this precond. is not impl.");
544  }
546  throw std::runtime_error("this precond. is not impl.");
547  }
548 
556  [[nodiscard]] std::string name() const {
557  return "monolish::equation::Cholesky";
558  }
559 
567  [[nodiscard]] std::string solver_name() const { return "Cholesky"; }
568 };
569 
570 } // 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::IC::infoM
void * infoM
Definition: monolish_equation.hpp:312
monolish::equation::IC::infoLt
void * infoLt
Definition: monolish_equation.hpp:312
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:367
monolish::equation::none::create_precond
void create_precond(MATRIX &A)
monolish::equation::IC::matL
void * matL
Definition: monolish_equation.hpp:311
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:312
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::IC::cusparse_handle
void * cusparse_handle
Definition: monolish_equation.hpp:313
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::ILU::infoU
void * infoU
Definition: monolish_equation.hpp:368
monolish::equation::IC::zbuf
monolish::vector< Float > zbuf
Definition: monolish_equation.hpp:316
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:485
monolish::equation::ILU::buf
monolish::vector< double > buf
Definition: monolish_equation.hpp:371
monolish::equation::ILU::~ILU
~ILU()
monolish::equation::IC::name
std::string name() const
get solver name "monolish::equation::IC"
Definition: monolish_equation.hpp:336
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:527
monolish::equation::ILU::solver_name
std::string solver_name() const
get solver name "ILU"
Definition: monolish_equation.hpp:401
monolish::equation::IC::matM
void * matM
Definition: monolish_equation.hpp:311
monolish::equation::IC::buf
monolish::vector< double > buf
Definition: monolish_equation.hpp:315
monolish::equation::Cholesky::name
std::string name() const
get solver name "monolish::equation::Cholesky"
Definition: monolish_equation.hpp:556
monolish::equation::IC
Incomplete Cholesky solver class.
Definition: monolish_equation.hpp:308
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::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:431
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:420
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 incomprete 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:345
monolish::equation::ILU::zbuf
monolish::vector< Float > zbuf
Definition: monolish_equation.hpp:372
monolish::equation::Jacobi::solver_name
std::string solver_name() const
get solver name "Jacobi"
Definition: monolish_equation.hpp:227
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:529
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:367
monolish::equation::Cholesky::solver_name
std::string solver_name() const
get solver name "Cholesky"
Definition: monolish_equation.hpp:567
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: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:473
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:434
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:508
monolish::equation::ILU::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve with incomprete LU factorization
monolish::equation::LU::solver_name
std::string solver_name() const
get solver name "LU"
Definition: monolish_equation.hpp:454
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:545
monolish::equation::ILU
Incomplete LU solver class.
Definition: monolish_equation.hpp:364
monolish::equation::CG::solver_name
std::string solver_name() const
get solver name "CG"
Definition: monolish_equation.hpp:111
monolish::equation::ILU::cusparse_handle
void * cusparse_handle
Definition: monolish_equation.hpp:369
monolish::equation::IC::bufsize
int bufsize
Definition: monolish_equation.hpp:314
monolish::equation::LU::name
std::string name() const
get solver name "monolish::equation::LU"
Definition: monolish_equation.hpp:445
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:488
monolish::equation::IC::~IC
~IC()
monolish::equation::QR::name
std::string name() const
get solver name "monolish::equation::QR"
Definition: monolish_equation.hpp:499
monolish::equation::LU::lib
int lib
Definition: monolish_equation.hpp:422
monolish::equation::CG::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:87
monolish::equation::ILU::infoL
void * infoL
Definition: monolish_equation.hpp:368
monolish::equation::ILU::name
std::string name() const
get solver name "monolish::equation::ILU"
Definition: monolish_equation.hpp:392
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::ILU::matM
void * matM
Definition: monolish_equation.hpp:367
monolish::equation::ILU::bufsize
int bufsize
Definition: monolish_equation.hpp:370
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::ILU::infoM
void * infoM
Definition: monolish_equation.hpp:368
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:542
monolish::equation::QR::lib
int lib
Definition: monolish_equation.hpp:475
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