monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
monolish_linearoperator.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 #include <exception>
10 #include <functional>
11 #include <omp.h>
12 #include <random>
13 #include <stdexcept>
14 #include <string>
15 #include <vector>
16 
17 namespace monolish {
18 template <typename Float> class vector;
19 namespace matrix {
20 template <typename Float> class Dense;
21 template <typename Float> class COO;
22 template <typename Float> class CRS;
23 
30 template <typename Float> class LinearOperator {
31 private:
35  size_t rowN;
36 
40  size_t colN;
41 
46 
51 
55  mutable bool gpu_status = false;
56 
60  std::function<vector<Float>(const vector<Float> &)> matvec;
61 
66  std::function<vector<Float>(const vector<Float> &)> rmatvec;
67 
68 public:
70 
80  LinearOperator(const size_t M, const size_t N);
81 
93  const size_t M, const size_t N,
94  const std::function<vector<Float>(const vector<Float> &)> &MATVEC);
95 
109  const size_t M, const size_t N,
110  const std::function<vector<Float>(const vector<Float> &)> &MATVEC,
111  const std::function<vector<Float>(const vector<Float> &)> &RMATVEC);
112 
120  void convert(COO<Float> &coo);
121 
131 
132  void convert(CRS<Float> &crs);
133 
135 
136  void convert_to_Dense(Dense<Float> &dense) const;
137 
146  LinearOperator(const LinearOperator<Float> &linearoperator);
147 
155  size_t get_row() const { return rowN; }
156 
164  size_t get_col() const { return colN; }
165 
173  std::function<vector<Float>(const vector<Float> &)> get_matvec() const {
174  return matvec;
175  }
176 
185  std::function<vector<Float>(const vector<Float> &)> get_rmatvec() const {
186  return rmatvec;
187  }
188 
196  bool get_matvec_init_flag() const { return matvec_init_flag; }
197 
205  bool get_rmatvec_init_flag() const { return rmatvec_init_flag; }
206 
214  void
215  set_matvec(const std::function<vector<Float>(const vector<Float> &)> &MATVEC);
216 
225  void set_rmatvec(
226  const std::function<vector<Float>(const vector<Float> &)> &RMATVEC);
227 
235  std::string type() const { return "LinearOperator"; }
236 
243  void send() const {};
244 
251  void recv() const {};
252 
259  void nonfree_recv() const {};
260 
267  void device_free() const {};
268 
273  bool get_device_mem_stat() const { return gpu_status; };
274 
275  void set_device_mem_stat(bool status) {
276  gpu_status = status;
277  return;
278  };
279 
287 
296  void operator=(const LinearOperator<Float> &mat);
297 };
298 } // namespace matrix
299 } // 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::matrix::LinearOperator::gpu_status
bool gpu_status
true: sended, false: not send
Definition: monolish_linearoperator.hpp:55
monolish::matrix::LinearOperator::type
std::string type() const
get format name "LinearOperator"
Definition: monolish_linearoperator.hpp:235
monolish::matrix::LinearOperator::matvec
std::function< vector< Float >const vector< Float > &)> matvec
pseudo multiplication function of matrix and vector
Definition: monolish_linearoperator.hpp:60
monolish::matrix::LinearOperator::set_device_mem_stat
void set_device_mem_stat(bool status)
Definition: monolish_linearoperator.hpp:275
monolish::matrix::LinearOperator::operator=
void operator=(const LinearOperator< Float > &mat)
operator copy
Definition: copy_linearoperator.cpp:9
monolish::matrix::LinearOperator::send
void send() const
send data to GPU
Definition: monolish_linearoperator.hpp:243
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::convert_to_Dense
void convert_to_Dense(Dense< Float > &dense) const
Definition: convert_linearoperator.cpp:69
monolish::matrix::LinearOperator::get_col
size_t get_col() const
get # of col
Definition: monolish_linearoperator.hpp:164
monolish::matrix::Dense
Dense format Matrix.
Definition: monolish_coo.hpp:28
monolish::matrix::LinearOperator::LinearOperator
LinearOperator()
Definition: monolish_linearoperator.hpp:69
monolish::matrix::LinearOperator::~LinearOperator
~LinearOperator()
destructor of LinearOperator, free GPU memory
Definition: monolish_linearoperator.hpp:286
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::matrix::LinearOperator::rmatvec
std::function< vector< Float >const vector< Float > &)> rmatvec
pseudo multiplication function of (Hermitian) transposed matrix and vector
Definition: monolish_linearoperator.hpp:66
monolish::matrix::LinearOperator::LinearOperator
LinearOperator(COO< Float > &coo)
Create LinearOperator from COO.
Definition: monolish_linearoperator.hpp:130
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::matrix::LinearOperator::convert
void convert(COO< Float > &coo)
Convert LinearOperator from COO.
monolish::matrix::COO
Coodinate (COO) format Matrix (need to sort)
Definition: monolish_coo.hpp:38
monolish::matrix::LinearOperator::colN
size_t colN
# of col
Definition: monolish_linearoperator.hpp:40
monolish::matrix::LinearOperator::nonfree_recv
void nonfree_recv() const
recv. data to GPU (w/o free)
Definition: monolish_linearoperator.hpp:259
monolish::matrix::LinearOperator::LinearOperator
LinearOperator(CRS< Float > &crs)
Definition: monolish_linearoperator.hpp:134
monolish::matrix::LinearOperator::rowN
size_t rowN
# of row
Definition: monolish_linearoperator.hpp:35
monolish::vector
vector class
Definition: monolish_coo.hpp:25
monolish::matrix::LinearOperator::recv
void recv() const
recv. data to GPU, and free data on GPU
Definition: monolish_linearoperator.hpp:251
monolish::matrix::LinearOperator::get_rmatvec
std::function< vector< Float >const vector< Float > &)> get_rmatvec() const
get multiplication function of (Hermitian) transposed matrix and vector C = A;
Definition: monolish_linearoperator.hpp:185
monolish::matrix::LinearOperator::matvec_init_flag
bool matvec_init_flag
flag that shows matvec is defined or not
Definition: monolish_linearoperator.hpp:45
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::matrix::LinearOperator::device_free
void device_free() const
free data on GPU
Definition: monolish_linearoperator.hpp:267
monolish::matrix::LinearOperator::get_matvec
std::function< vector< Float >const vector< Float > &)> get_matvec() const
get multiplication function of matrix and vector
Definition: monolish_linearoperator.hpp:173
monolish::matrix::CRS
Compressed Row Storage (CRS) format Matrix.
Definition: monolish_coo.hpp:29
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::matrix::LinearOperator::rmatvec_init_flag
bool rmatvec_init_flag
flag that shows rmatvec is defined or not
Definition: monolish_linearoperator.hpp:50