monolish  0.14.2
MONOlithic LIner equation Solvers for Highly-parallel architecture
linearoperator_matvec.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace monolish {
4 
5 namespace {
6 template <typename T, typename VEC1, typename VEC2>
7 void matvec_core(const matrix::LinearOperator<T> &A, const VEC1 &x, VEC2 &y) {
8  Logger &logger = Logger::get_instance();
9  logger.func_in(monolish_func);
10 
11  // err, M = MN * N
12  assert(A.get_row() == y.size());
13  assert(A.get_col() == x.size());
14  assert(util::is_same_device_mem_stat(A, x, y));
15  if (A.get_matvec_init_flag()) {
16 
17  const size_t xoffset = x.get_offset();
18  const size_t yoffset = y.get_offset();
19 
20  vector<T> x_tmp(x.size(), 0);
21  if (x.get_device_mem_stat())
22  x_tmp.send();
23  vector<T> y_tmp(y.size(), 0);
24  if (y.get_device_mem_stat())
25  y_tmp.send();
26 
27  internal::vcopy(x.size(), x.data() + xoffset, x_tmp.data(),
28  x.get_device_mem_stat());
29 
30  y_tmp = A.get_matvec()(x_tmp);
31 
32  internal::vcopy(y.size(), y_tmp.data(), y.data() + yoffset,
33  y.get_device_mem_stat());
34  } else {
35  throw std::runtime_error("error matvec is not initialized");
36  }
37 
38  logger.func_out();
39 }
40 
41 template <typename T, typename VEC1, typename VEC2>
42 void rmatvec_core(const matrix::LinearOperator<T> &A, const VEC1 &x, VEC2 &y) {
43  Logger &logger = Logger::get_instance();
44  logger.func_in(monolish_func);
45 
46  // err, M = MN * N
47  assert(A.get_row() == x.size());
48  assert(A.get_col() == y.size());
49  assert(util::is_same_device_mem_stat(A, x, y));
50  if (A.get_rmatvec_init_flag()) {
51  const size_t xoffset = x.get_offset();
52  const size_t yoffset = y.get_offset();
53 
54  vector<T> x_tmp(x.size(), 0);
55  if (x.get_device_mem_stat())
56  x_tmp.send();
57  vector<T> y_tmp(y.size(), 0);
58  if (y.get_device_mem_stat())
59  y_tmp.send();
60 
61  internal::vcopy(x.size(), x.data() + xoffset, x_tmp.data(),
62  x.get_device_mem_stat());
63 
64  y_tmp = A.get_rmatvec()(x_tmp);
65 
66  internal::vcopy(y.size(), y_tmp.data(), y.data() + yoffset,
67  y.get_device_mem_stat());
68  } else {
69  throw std::runtime_error("error rmatmul is not initialized");
70  }
71 
72  logger.func_out();
73 }
74 
75 } // namespace
76 
77 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
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:454
monolish
Definition: monolish_matrix_blas.hpp:10
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42