monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
monolish_equation.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <vector>
3 
4 #if defined USE_MPI
5 #include <mpi.h>
6 #endif
7 
8 #include "./monolish_solver.hpp"
10 #include <functional>
11 
12 namespace monolish {
13 namespace 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  int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
36 
44  std::string name() const { return "monolish::equation::none"; }
45 };
46 
62 template <typename MATRIX, typename Float>
63 class CG : public monolish::solver::solver<MATRIX, Float> {
64 private:
65  int monolish_CG(MATRIX &A, vector<Float> &x, vector<Float> &b);
66 
67 public:
75  int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
76 
77  void create_precond(MATRIX &A) {
78  throw std::runtime_error("this precond. is not impl.");
79  }
80 
82  throw std::runtime_error("this precond. is not impl.");
83  }
84 
92  std::string name() const { return "monolish::equation::CG"; }
93 };
94 
110 template <typename MATRIX, typename Float>
111 class BiCGSTAB : public monolish::solver::solver<MATRIX, Float> {
112 private:
113  int monolish_BiCGSTAB(MATRIX &A, vector<Float> &x, vector<Float> &b);
114 
115 public:
123  int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
124 
125  void create_precond(MATRIX &A) {
126  throw std::runtime_error("this precond. is not impl.");
127  }
128 
130  throw std::runtime_error("this precond. is not impl.");
131  }
132 
140  std::string name() const { return "monolish::equation::BiCGSTAB"; }
141 };
142 
158 template <typename MATRIX, typename Float>
159 class Jacobi : public monolish::solver::solver<MATRIX, Float> {
160 private:
161  int monolish_Jacobi(MATRIX &A, vector<Float> &x, vector<Float> &b);
162 
163 public:
171  int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
172  void create_precond(MATRIX &A);
173  void apply_precond(const vector<Float> &r, vector<Float> &z);
174 
182  std::string name() const { return "monolish::equation::Jacobi"; }
183 };
184 
200 template <typename MATRIX, typename Float>
201 class LU : public monolish::solver::solver<MATRIX, Float> {
202 private:
203  int lib = 1; // lib is 1
204  int mumps_LU(MATRIX &A, vector<double> &x, vector<double> &b);
205  int cusolver_LU(MATRIX &A, vector<double> &x, vector<double> &b);
207  int reorder = 3;
208 
209 public:
210  void set_reorder(int r) { reorder = r; }
211  int get_sigularity() { return singularity; }
212  int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
213  int solve(MATRIX &A, vector<Float> &xb);
214  void create_precond(MATRIX &A) {
215  throw std::runtime_error("this precond. is not impl.");
216  }
218  throw std::runtime_error("this precond. is not impl.");
219  }
220 
228  std::string name() const { return "monolish::equation::LU"; }
229 };
230 
247 template <typename MATRIX, typename Float>
248 class QR : public monolish::solver::solver<MATRIX, Float> {
249 private:
250  int lib = 1; // lib is 1
251  int cusolver_QR(MATRIX &A, vector<double> &x, vector<double> &b);
252  int cusolver_QR(MATRIX &A, vector<float> &x, vector<float> &b);
254  int reorder = 3;
255 
256 public:
261  void set_reorder(int r) { reorder = r; }
262 
267  int get_sigularity() { return singularity; }
268 
272  int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
273  void create_precond(MATRIX &A) {
274  throw std::runtime_error("this precond. is not impl.");
275  }
277  throw std::runtime_error("this precond. is not impl.");
278  }
279 
287  std::string name() const { return "monolish::equation::QR"; }
288 };
289 
306 template <typename MATRIX, typename Float>
307 class Cholesky : public monolish::solver::solver<MATRIX, Float> {
308 private:
309  int lib = 1; // lib is 1
310  int cusolver_Cholesky(MATRIX &A, vector<float> &x, vector<float> &b);
311  int cusolver_Cholesky(MATRIX &A, vector<double> &x, vector<double> &b);
313  int reorder = 3;
314 
315 public:
321  void set_reorder(int r) { reorder = r; }
322 
326  int get_sigularity() { return singularity; }
327 
331  int solve(MATRIX &A, vector<Float> &x, vector<Float> &b);
332  int solve(MATRIX &A, vector<Float> &xb);
333 
335  throw std::runtime_error("this precond. is not impl.");
336  }
338  throw std::runtime_error("this precond. is not impl.");
339  }
340 
348  std::string name() const { return "monolish::equation::Cholesky"; }
349 };
350 } // namespace equation
351 } // namespace monolish
monolish::equation::BiCGSTAB
BiCGSTAB solver class.
Definition: monolish_equation.hpp:111
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::Jacobi::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by jacobi method(lib=0: monolish)
Definition: jacobi.cpp:137
monolish::equation::CG::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by BiCGSTAB method(lib=0: monolish)
Definition: cg.cpp:98
monolish::equation::Jacobi::name
std::string name() const
get solver name "monolish::equation::Jacobi"
Definition: monolish_equation.hpp:182
monolish::equation::Cholesky::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax=b
monolish::equation::QR::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:273
monolish::equation::CG::monolish_CG
int monolish_CG(MATRIX &A, vector< Float > &x, vector< Float > &b)
Definition: cg.cpp:13
monolish::equation::Cholesky
Cholesky solver class. It can use set_tol(), get_tol(), set_reorder(), get_singularity().
Definition: monolish_equation.hpp:307
monolish::equation::LU::singularity
int singularity
Definition: monolish_equation.hpp:206
monolish::equation::none::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
Definition: none.cpp:68
monolish::equation::Cholesky::name
std::string name() const
get solver name "monolish::equation::Cholesky"
Definition: monolish_equation.hpp:348
monolish::equation::QR::reorder
int reorder
Definition: monolish_equation.hpp:254
monolish::equation::BiCGSTAB::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:129
monolish::equation::Cholesky::cusolver_Cholesky
int cusolver_Cholesky(MATRIX &A, vector< float > &x, vector< float > &b)
monolish::equation::LU::get_sigularity
int get_sigularity()
Definition: monolish_equation.hpp:211
monolish_common.hpp
monolish::equation::none::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: none.cpp:40
monolish::equation::LU::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:214
monolish::equation::BiCGSTAB::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:125
monolish::solver::solver
solver base class
Definition: monolish_solver.hpp:33
monolish::equation::CG
CG solver class.
Definition: monolish_equation.hpp:63
monolish::equation::LU
LU solver class (Dense, CPU only now)
Definition: monolish_equation.hpp:201
monolish::equation::LU::set_reorder
void set_reorder(int r)
Definition: monolish_equation.hpp:210
monolish::equation::Cholesky::singularity
int singularity
Definition: monolish_equation.hpp:312
monolish::equation::LU::reorder
int reorder
Definition: monolish_equation.hpp:207
monolish::equation::Cholesky::lib
int lib
Definition: monolish_equation.hpp:309
monolish::equation::LU::mumps_LU
int mumps_LU(MATRIX &A, vector< double > &x, vector< double > &b)
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::equation::Jacobi::create_precond
void create_precond(MATRIX &A)
Definition: jacobi.cpp:12
monolish::equation::QR::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax=b
Definition: qr.cpp:6
monolish::equation::Jacobi::monolish_Jacobi
int monolish_Jacobi(MATRIX &A, vector< Float > &x, vector< Float > &b)
Definition: jacobi.cpp:66
monolish::equation::CG::name
std::string name() const
get solver name "monolish::equation::CG"
Definition: monolish_equation.hpp:92
monolish::equation::BiCGSTAB::monolish_BiCGSTAB
int monolish_BiCGSTAB(MATRIX &A, vector< Float > &x, vector< Float > &b)
Definition: bicgstab.cpp:13
monolish::equation::Jacobi::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: jacobi.cpp:42
monolish::equation::BiCGSTAB::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax = b by BiCGSTAB method (lib=0: monolish)
Definition: bicgstab.cpp:143
monolish::equation::none::create_precond
void create_precond(MATRIX &A)
Definition: none.cpp:11
monolish_solver.hpp
monolish::equation::QR
QR solver class (Dense, GPU only now). can use set_tol(), get_tol(), set_reorder(),...
Definition: monolish_equation.hpp:248
monolish::equation::CG::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:81
monolish::equation::Cholesky::reorder
int reorder
Definition: monolish_equation.hpp:313
monolish::equation::LU::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:217
monolish::equation::Cholesky::get_sigularity
int get_sigularity()
-1 if A is symmetric postive definite.
Definition: monolish_equation.hpp:326
monolish::equation::QR::get_sigularity
int get_sigularity()
-1 if A is symmetric postive definite. default reorder algorithm is csrmetisnd
Definition: monolish_equation.hpp:267
monolish::equation::BiCGSTAB::name
std::string name() const
get solver name "monolish::equation::BiCGSTAB"
Definition: monolish_equation.hpp:140
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:337
monolish::equation::QR::singularity
int singularity
Definition: monolish_equation.hpp:253
monolish::equation::LU::name
std::string name() const
get solver name "monolish::equation::LU"
Definition: monolish_equation.hpp:228
monolish::equation::QR::apply_precond
void apply_precond(const vector< Float > &r, vector< Float > &z)
Definition: monolish_equation.hpp:276
monolish::equation::QR::name
std::string name() const
get solver name "monolish::equation::QR"
Definition: monolish_equation.hpp:287
monolish::equation::LU::lib
int lib
Definition: monolish_equation.hpp:203
monolish::equation::CG::create_precond
void create_precond(MATRIX &A)
Definition: monolish_equation.hpp:77
monolish::equation::none
none solver class(nothing to do)
Definition: monolish_equation.hpp:31
monolish::equation::Jacobi
Jacobi solver class.
Definition: monolish_equation.hpp:159
monolish::equation::Cholesky::set_reorder
void set_reorder(int r)
0: no ordering 1: symrcm, 2: symamd, 3: csrmetisnd is used to reduce zero fill-in....
Definition: monolish_equation.hpp:321
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::QR::set_reorder
void set_reorder(int r)
0: no ordering 1: symrcm, 2: symamd, 3: csrmetisnd is used to reduce zero fill-in.
Definition: monolish_equation.hpp:261
monolish::equation::Cholesky::create_precond
void create_precond(matrix::CRS< Float > &A)
Definition: monolish_equation.hpp:334
monolish::equation::QR::lib
int lib
Definition: monolish_equation.hpp:250