monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
linearoperator-linearoperator.cpp
Go to the documentation of this file.
1 #include "../../../../include/monolish_blas.hpp"
2 #include "../../../internal/monolish_internal.hpp"
3 
4 namespace monolish {
5 
6 // double ////////////////
10  Logger &logger = Logger::get_instance();
11  logger.func_in(monolish_func);
12 
13  // err
14  assert(A.get_col() == B.get_row());
15  assert(A.get_row() == C.get_row());
16  assert(B.get_col() == C.get_col());
17  assert(util::is_same_device_mem_stat(A, B, C));
18 
19  assert(A.get_matvec_init_flag() == B.get_matvec_init_flag());
21 
22  if (A.get_matvec_init_flag()) {
23  C.set_matvec([&](const vector<double> &VEC) {
24  vector<double> vec(A.get_row(), 0.0), vec_tmp(B.get_row(), 0.0);
25  if (A.get_device_mem_stat()) {
26  util::send(vec, vec_tmp);
27  }
28  blas::matvec(B, VEC, vec_tmp);
29  blas::matvec(A, vec_tmp, vec);
30  if (A.get_device_mem_stat()) {
31  util::device_free(vec_tmp);
32  }
33  return vec;
34  });
35  }
36  if (A.get_rmatvec_init_flag()) {
37  C.set_rmatvec([&](const vector<double> &VEC) {
38  vector<double> vec(B.get_col(), 0.0), vec_tmp(A.get_col(), 0.0);
39  if (A.get_device_mem_stat()) {
40  util::send(vec, vec_tmp);
41  }
42  blas::rmatvec(A, VEC, vec_tmp);
43  blas::rmatvec(B, vec_tmp, vec);
44  if (A.get_device_mem_stat()) {
45  util::device_free(vec_tmp);
46  }
47  return vec;
48  });
49  }
50 
51  logger.func_out();
52 }
53 
54 // float ////////////////
58  Logger &logger = Logger::get_instance();
59  logger.func_in(monolish_func);
60 
61  // err
62  assert(A.get_col() == B.get_row());
63  assert(A.get_row() == C.get_row());
64  assert(B.get_col() == C.get_col());
65  assert(util::is_same_device_mem_stat(A, B, C));
66 
67  assert(A.get_matvec_init_flag() == B.get_matvec_init_flag());
69 
70  if (A.get_matvec_init_flag()) {
71  C.set_matvec([&](const vector<float> &VEC) {
72  vector<float> vec(A.get_row(), 0.0), vec_tmp(B.get_row(), 0.0);
73  if (A.get_device_mem_stat()) {
74  util::send(vec, vec_tmp);
75  }
76  blas::matvec(B, VEC, vec_tmp);
77  blas::matvec(A, vec_tmp, vec);
78  if (A.get_device_mem_stat()) {
79  util::device_free(vec_tmp);
80  }
81  return vec;
82  });
83  }
84  if (A.get_rmatvec_init_flag()) {
85  C.set_rmatvec([&](const vector<float> &VEC) {
86  vector<float> vec(B.get_col(), 0.0), vec_tmp(A.get_col(), 0.0);
87  if (A.get_device_mem_stat()) {
88  util::send(vec, vec_tmp);
89  }
90  blas::rmatvec(A, VEC, vec_tmp);
91  blas::rmatvec(B, vec_tmp, vec);
92  if (A.get_device_mem_stat()) {
93  util::device_free(vec_tmp);
94  }
95  return vec;
96  });
97  }
98 
99  logger.func_out();
100 }
101 } // namespace monolish
monolish::matrix::LinearOperator::set_rmatvec
void set_rmatvec(const std::function< vector< Float >(const vector< Float > &)> &RMATVEC)
set multiplication function of (Hermitian) transposed matrix and vector
Definition: linearoperator_constructor.cpp:114
monolish::matrix::LinearOperator
Linear Operator imitating Matrix.
Definition: monolish_coo.hpp:30
monolish::blas::rmatvec
void rmatvec(const matrix::LinearOperator< double > &A, const vector< double > &x, vector< double > &y)
matrix (LinearOperator) and vector multiplication: y = Ax
Definition: matvec_blas.cpp:251
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::Logger::func_out
void func_out()
Definition: logger_utils.cpp:80
monolish::matrix::LinearOperator::get_device_mem_stat
bool get_device_mem_stat() const
true: sended, false: not send
Definition: monolish_linearoperator.hpp:273
monolish::matrix::LinearOperator::get_col
size_t get_col() const
get # of col
Definition: monolish_linearoperator.hpp:164
monolish::util::device_free
auto device_free(T &x)
free data of GPU
Definition: monolish_common.hpp:627
monolish::util::is_same_device_mem_stat
bool is_same_device_mem_stat(const T &arg1, const U &arg2)
compare same device memory status
Definition: monolish_common.hpp:431
monolish::matrix::LinearOperator::get_matvec_init_flag
bool get_matvec_init_flag() const
get flag that shows matvec is defined or not
Definition: monolish_linearoperator.hpp:196
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::matrix::LinearOperator::get_row
size_t get_row() const
get # of row
Definition: monolish_linearoperator.hpp:155
monolish::blas::matvec
void matvec(const matrix::Dense< double > &A, const vector< double > &x, vector< double > &y)
Dense matrix and vector multiplication: y = Ax.
Definition: matvec_blas.cpp:11
monolish::vector
vector class
Definition: monolish_coo.hpp:25
monolish::matrix::LinearOperator::set_matvec
void set_matvec(const std::function< vector< Float >(const vector< Float > &)> &MATVEC)
set multiplication function of matrix and vector
Definition: linearoperator_constructor.cpp:102
monolish::blas::matmul
void matmul(const matrix::Dense< double > &A, const matrix::Dense< double > &B, matrix::Dense< double > &C)
Dense matrix multiplication: C = AB.
Definition: dense-dense_matmul.cpp:7
monolish::util::send
auto send(T &x)
send data to GPU
Definition: monolish_common.hpp:598
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::matrix::LinearOperator::get_rmatvec_init_flag
bool get_rmatvec_init_flag() const
get flag that shows rmatvec is defined or not
Definition: monolish_linearoperator.hpp:205
monolish::Logger::func_in
void func_in(const std::string func_name)
Definition: logger_utils.cpp:69