monolish  0.14.0
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  assert(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 
35  logger.func_out();
36 }
37 
38 template <typename T, typename VEC1, typename VEC2>
39 void rmatvec_core(const matrix::LinearOperator<T> &A, const VEC1 &x, VEC2 &y) {
40  Logger &logger = Logger::get_instance();
41  logger.func_in(monolish_func);
42 
43  // err, M = MN * N
44  assert(A.get_row() == x.size());
45  assert(A.get_col() == y.size());
46  assert(util::is_same_device_mem_stat(A, x, y));
47  assert(A.get_rmatvec_init_flag());
48 
49  const size_t xoffset = x.get_offset();
50  const size_t yoffset = y.get_offset();
51 
52  vector<T> x_tmp(x.size(), 0);
53  if (x.get_device_mem_stat())
54  x_tmp.send();
55  vector<T> y_tmp(y.size(), 0);
56  if (y.get_device_mem_stat())
57  y_tmp.send();
58 
59  internal::vcopy(x.size(), x.data() + xoffset, x_tmp.data(),
60  x.get_device_mem_stat());
61 
62  y_tmp = A.get_rmatvec()(x_tmp);
63 
64  internal::vcopy(y.size(), y_tmp.data(), y.data() + yoffset,
65  y.get_device_mem_stat());
66 
67  logger.func_out();
68 }
69 
70 } // namespace
71 
72 } // 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:431
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42