monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
cholesky.cpp
Go to the documentation of this file.
1 #include "../../../include/monolish_blas.hpp"
2 #include "../../../include/monolish_equation.hpp"
3 #include "../../internal/lapack/monolish_lapack.hpp"
4 #include "../../internal/monolish_internal.hpp"
5 
6 namespace monolish {
7 
8 template <typename MATRIX, typename T>
9 int equation::Cholesky<MATRIX, T>::solve(MATRIX &A, vector<T> &x,
10  vector<T> &b) {
11  Logger &logger = Logger::get_instance();
12  logger.func_in(monolish_func);
13 
14  int ret = -1;
15 
16 #if MONOLISH_USE_GPU // gpu
17  if (lib == 1) {
18  ret = cusolver_Cholesky(A, x, b);
19  } else {
20  logger.func_out();
21  throw std::runtime_error("error solver.lib is not 1");
22  }
23  logger.func_out();
24 #else
25  (void)(&A);
26  (void)(&x);
27  (void)(&b);
28  throw std::runtime_error("error Cholesky on CPU does not impl.");
29 #endif
30  logger.func_out();
31  return ret;
32 }
33 
34 template int equation::Cholesky<matrix::CRS<double>, double>::solve(
35  matrix::CRS<double> &A, vector<double> &x, vector<double> &b);
36 template int equation::Cholesky<matrix::CRS<float>, float>::solve(
37  matrix::CRS<float> &A, vector<float> &x, vector<float> &b);
38 
39 template <>
42  Logger &logger = Logger::get_instance();
43  logger.func_in(monolish_func);
44 
45  if (A.get_device_mem_stat() == true) {
46  throw std::runtime_error("error Dense Cholesky on GPU does not impl.");
47  }
48 
49  int ret = MONOLISH_SOLVER_SUCCESS;
50 
51  if (lib == 1) {
52  std::vector<int> ipiv(std::min(A.get_row(), A.get_col()));
53 
54  if (internal::lapack::sytrf(A, ipiv) != 0) {
56  };
57 
58  A.recv();
59  XB.recv();
60 
61  if (internal::lapack::sytrs(A, XB, ipiv) != 0) {
63  }
64 
65  XB.send();
66 
67  } else {
68  logger.func_out();
69  throw std::runtime_error("error solver.lib is not 1");
70  }
71 
72  logger.func_out();
73  return ret;
74 }
75 template <>
78  Logger &logger = Logger::get_instance();
79  logger.func_in(monolish_func);
80 
81  int ret = MONOLISH_SOLVER_SUCCESS;
82 
83  if (lib == 1) {
84  std::vector<int> ipiv(std::min(A.get_row(), A.get_col()));
85 
86  if (internal::lapack::sytrf(A, ipiv) != 0) {
88  };
89 
90  A.recv();
91  XB.recv();
92 
93  if (internal::lapack::sytrs(A, XB, ipiv) != 0) {
95  }
96 
97  XB.send();
98 
99  } else {
100  logger.func_out();
101  throw std::runtime_error("error solver.lib is not 1");
102  }
103 
104  logger.func_out();
105  return ret;
106 }
107 
108 template <>
111  Logger &logger = Logger::get_instance();
112  logger.func_in(monolish_func);
113 
114  int ret = MONOLISH_SOLVER_SUCCESS;
115 
116  if (lib == 1) {
117  std::vector<int> ipiv(std::min(A.get_row(), A.get_col()));
118  monolish::blas::copy(b, x);
119 
120  if (internal::lapack::sytrf(A, ipiv) != 0) {
122  };
123 
124  A.recv();
125  x.recv();
126 
127  if (internal::lapack::sytrs(A, x, ipiv) != 0) {
129  }
130 
131  x.send();
132 
133  } else {
134  logger.func_out();
135  throw std::runtime_error("error solver.lib is not 1");
136  }
137 
138  logger.func_out();
139  return ret;
140 }
141 
142 template <>
145  Logger &logger = Logger::get_instance();
146  logger.func_in(monolish_func);
147 
148  int ret = MONOLISH_SOLVER_SUCCESS;
149 
150  if (lib == 1) {
151  std::vector<int> ipiv(std::min(A.get_row(), A.get_col()));
152  monolish::blas::copy(b, x);
153 
154  if (internal::lapack::sytrf(A, ipiv) != 0) {
156  };
157 
158  A.recv();
159  x.recv();
160 
161  if (internal::lapack::sytrs(A, x, ipiv) != 0) {
163  }
164 
165  x.send();
166 
167  } else {
168  logger.func_out();
169  throw std::runtime_error("error solver.lib is not 1");
170  }
171 
172  logger.func_out();
173  return ret;
174 }
175 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::vml::min
void min(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
Create a new CRS matrix with smallest elements of two matrices (C[0:nnz] = min(A[0:nnz],...
Definition: matrix_vml.cpp:390
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::equation::Cholesky::solve
int solve(MATRIX &A, vector< Float > &x, vector< Float > &b)
solve Ax=b
monolish::Logger::func_out
void func_out()
Definition: logger_utils.cpp:80
monolish::matrix::Dense::get_device_mem_stat
bool get_device_mem_stat() const
true: sended, false: not send
Definition: monolish_dense.hpp:377
monolish::matrix::Dense::get_row
size_t get_row() const
get # of row
Definition: monolish_dense.hpp:199
monolish::matrix::Dense
Dense format Matrix.
Definition: monolish_coo.hpp:28
MONOLISH_SOLVER_SUCCESS
#define MONOLISH_SOLVER_SUCCESS
Definition: monolish_common.hpp:10
monolish::equation::Cholesky
Cholesky solver class. It can use set_tol(), get_tol(), set_reorder(), get_singularity().
Definition: monolish_equation.hpp:307
MONOLISH_SOLVER_BREAKDOWN
#define MONOLISH_SOLVER_BREAKDOWN
Definition: monolish_common.hpp:13
monolish::blas::copy
void copy(const matrix::Dense< double > &A, matrix::Dense< double > &C)
Dense matrix copy (C=A)
Definition: dense_copy.cpp:25
monolish::matrix::Dense::recv
void recv()
recv. data to GPU, and free data on GPU
Definition: gpu_comm.cpp:205
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::matrix::Dense::get_col
size_t get_col() const
get # of col
Definition: monolish_dense.hpp:208
monolish::vector
vector class
Definition: monolish_coo.hpp:25
monolish::vector::send
void send() const
send data to GPU
Definition: gpu_comm.cpp:8
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::vector::recv
void recv()
recv data from GPU, and free data on GPU
Definition: gpu_comm.cpp:27
monolish::Logger::func_in
void func_in(const std::string func_name)
Definition: logger_utils.cpp:69