monolish  0.17.3-dev.16
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);
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);
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);
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;
354  void *cusparse_handle = nullptr;
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);
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;
416  void *cusparse_handle = nullptr;
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);
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
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by BiCGSTAB method (lib=0: monolish)
std::string name() const
get solver name "monolish::equation::BiCGSTAB"
int monolish_BiCGSTAB(MATRIX &A, vector< Float > &x, vector< Float > &b)
std::string solver_name() const
get solver name "BiCGSTAB"
void apply_precond(const vector< Float > &r, vector< Float > &z)
int monolish_CG(MATRIX &A, vector< Float > &x, vector< Float > &b)
void create_precond(MATRIX &A)
void apply_precond(const vector< Float > &r, vector< Float > &z)
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by BiCGSTAB method(lib=0: monolish)
std::string solver_name() const
get solver name "CG"
std::string name() const
get solver name "monolish::equation::CG"
int cusolver_Cholesky(MATRIX &A, vector< float > &x, vector< float > &b)
void create_precond(matrix::CRS< Float > &A)
int cusolver_Cholesky(MATRIX &A, vector< double > &x, vector< double > &b)
void apply_precond(const vector< Float > &r, vector< Float > &z)
std::string name() const
get solver name "monolish::equation::Cholesky"
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax=b
std::string solver_name() const
get solver name "Cholesky"
int solve(MATRIX &A, vector< Float > &xb)
Incomplete Cholesky solver class.
std::string solver_name() const
get solver name "IC"
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve with incomplete Cholesky factorization
void create_precond(MATRIX &A)
monolish::vector< Float > zbuf
int cusparse_IC(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::vector< double > buf
std::string name() const
get solver name "monolish::equation::IC"
void apply_precond(const vector< Float > &r, vector< Float > &z)
Incomplete LU solver class.
void apply_precond(const vector< Float > &r, vector< Float > &z)
std::string solver_name() const
get solver name "ILU"
monolish::vector< double > buf
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve with incomplete LU factorization
std::string name() const
get solver name "monolish::equation::ILU"
int cusparse_ILU(MATRIX &A, vector< Float > &x, vector< Float > &b)
monolish::vector< Float > zbuf
void create_precond(MATRIX &A)
std::string name() const
get solver name "monolish::equation::Jacobi"
void apply_precond(const vector< Float > &r, vector< Float > &z)
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by jacobi method(lib=0: monolish)
void create_precond(MATRIX &A)
std::string solver_name() const
get solver name "Jacobi"
int monolish_Jacobi(MATRIX &A, vector< Float > &x, vector< Float > &b)
std::string solver_name() const
get solver name "LU"
std::string name() const
get solver name "monolish::equation::LU"
int cusolver_LU(MATRIX &A, vector< double > &x, vector< double > &b)
void create_precond(MATRIX &A)
void apply_precond(const vector< Float > &r, vector< Float > &z)
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
int solve(MATRIX &A, vector< Float > &xb)
int mumps_LU(MATRIX &A, vector< double > &x, vector< double > &b)
int cusolver_QR(MATRIX &A, vector< double > &x, vector< double > &b)
void create_precond(MATRIX &A)
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax=b
void apply_precond(const vector< Float > &r, vector< Float > &z)
std::string name() const
get solver name "monolish::equation::QR"
std::string solver_name() const
get solver name "QR"
int cusolver_QR(MATRIX &A, vector< float > &x, vector< float > &b)
std::string solver_name() const
get solver name "SOR"
void apply_precond(const vector< Float > &r, vector< Float > &z)
void create_precond(MATRIX &A)
int monolish_SOR(MATRIX &A, vector< Float > &x, vector< Float > &b)
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by SOR method(lib=0: monolish)
std::string name() const
get solver name "monolish::equation::SOR"
none solver class(nothing to do)
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
std::string name() const
get solver name "monolish::equation::none"
std::string solver_name() const
get solver name "none"
void apply_precond(const vector< Float > &r, vector< Float > &z)
void create_precond(MATRIX &A)
Compressed Row Storage (CRS) format Matrix.
monolish namespaces