monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
float_linearoperator_linearoperator.cpp
Go to the documentation of this file.
1 #include "../../../include/monolish_blas.hpp"
2 #include "../../../include/monolish_vml.hpp"
3 #include "../../internal/monolish_internal.hpp"
4 
5 namespace monolish {
6 
8 // LinearOperator /////////////////////////
10 
14  Logger &logger = Logger::get_instance();
15  logger.func_in(monolish_func);
16 
17  // err
18  assert(util::is_same_size(A, B, C));
19  assert(util::is_same_device_mem_stat(A, B, C));
20 
21  assert(A.get_matvec_init_flag() == B.get_matvec_init_flag());
23 
24  if (A.get_matvec_init_flag()) {
25  C.set_matvec([&](const vector<float> &VEC) {
26  vector<float> vec(A.get_row(), 0.0), vec_tmp(A.get_row(), 0.0);
27  if (A.get_device_mem_stat()) {
28  util::send(vec, vec_tmp);
29  }
30  blas::matvec(A, VEC, vec);
31  blas::matvec(B, VEC, vec_tmp);
32  blas::axpy(1.0, vec_tmp, vec);
33  if (A.get_device_mem_stat()) {
34  util::device_free(vec_tmp);
35  }
36  return vec;
37  });
38  }
39 
40  if (A.get_rmatvec_init_flag()) {
41  C.set_rmatvec([&](const vector<float> &VEC) {
42  vector<float> vec(A.get_col(), 0.0), vec_tmp(A.get_col(), 0.0);
43  if (A.get_device_mem_stat()) {
44  util::send(vec, vec_tmp);
45  }
46  blas::rmatvec(A, VEC, vec);
47  blas::rmatvec(B, VEC, vec_tmp);
48  blas::axpy(1.0, vec_tmp, vec);
49  if (A.get_device_mem_stat()) {
50  util::device_free(vec_tmp);
51  }
52  return vec;
53  });
54  }
55 
56  logger.func_out();
57 }
58 
62  Logger &logger = Logger::get_instance();
63  logger.func_in(monolish_func);
64 
65  // err
66  assert(util::is_same_size(A, B, C));
67  assert(util::is_same_device_mem_stat(A, B, C));
68 
69  if (A.get_matvec_init_flag()) {
70  C.set_matvec([&](const vector<float> &VEC) {
71  vector<float> vec(A.get_row(), 0.0), vec_tmp(A.get_row(), 0.0);
72  if (A.get_device_mem_stat()) {
73  util::send(vec, vec_tmp);
74  }
75  blas::matvec(A, VEC, vec);
76  blas::matvec(B, VEC, vec_tmp);
77  blas::axpy(-1.0, vec_tmp, vec);
78  if (A.get_device_mem_stat()) {
79  util::device_free(vec_tmp);
80  }
81  return vec;
82  });
83  }
84 
85  if (A.get_rmatvec_init_flag()) {
86  C.set_rmatvec([&](const vector<float> &VEC) {
87  vector<float> vec(A.get_col(), 0.0), vec_tmp(A.get_col(), 0.0);
88  if (A.get_device_mem_stat()) {
89  util::send(vec, vec_tmp);
90  }
91  blas::rmatvec(A, VEC, vec);
92  blas::rmatvec(B, VEC, vec_tmp);
93  blas::axpy(-1.0, vec_tmp, vec);
94  if (A.get_device_mem_stat()) {
95  util::device_free(vec_tmp);
96  }
97  return vec;
98  });
99  }
100 
101  logger.func_out();
102 }
103 
104 } // namespace monolish
monolish::util::is_same_size
bool is_same_size(const T &x, const U &y)
compare size of vector or 1Dview (same as is_same_structure())
Definition: monolish_common.hpp:358
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::blas::axpy
void axpy(const double alpha, const vector< double > &x, vector< double > &y)
axpy: y = ax + y
Definition: vector_blas.cpp:595
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::vml::sub
void sub(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
element by element subtract CRS matrix A and CRS matrix B.
Definition: matrix_vml.cpp:228
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::vml::add
void add(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
element by element addition CRS matrix A and CRS matrix B.
Definition: matrix_vml.cpp:220
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::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