monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
dense_diag_vector_add.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 namespace matrix {
6 
7 // add vector
8 
9 template <typename T> void Dense<T>::diag_add(const vector<T> &vec) {
10  Logger &logger = Logger::get_instance();
11  logger.func_in(monolish_func);
12 
13  const T *vecd = vec.data();
14 
15  T *vald = val.data();
16  const size_t N = get_col();
17  const size_t Len = get_row() > get_col() ? get_row() : get_col();
18 
19  assert(Len == vec.size());
20 
21  if (gpu_status == true) {
22 #if MONOLISH_USE_GPU // gpu
23 #pragma omp target teams distribute parallel for
24  for (size_t i = 0; i < Len; i++) {
25  vald[N * i + i] += vecd[i];
26  }
27 #else
28  throw std::runtime_error("error USE_GPU is false, but gpu_status == true");
29 #endif
30  } else {
31 #pragma omp parallel for
32  for (size_t i = 0; i < Len; i++) {
33  vald[N * i + i] += vecd[i];
34  }
35  }
36 
37  logger.func_out();
38 }
39 template void
40 monolish::matrix::Dense<double>::diag_add(const vector<double> &vec);
41 template void
42 monolish::matrix::Dense<float>::diag_add(const vector<float> &vec);
43 
44 template <typename T> void Dense<T>::diag_add(const view1D<vector<T>, T> &vec) {
45  Logger &logger = Logger::get_instance();
46  logger.func_in(monolish_func);
47 
48  const T *vecd = vec.data();
49 
50  T *vald = val.data();
51  const size_t N = get_col();
52  const size_t Len = get_row() > get_col() ? get_row() : get_col();
53 
54  assert(Len == vec.size());
55 
56  if (gpu_status == true) {
57 #if MONOLISH_USE_GPU // gpu
58 #pragma omp target teams distribute parallel for
59  for (size_t i = 0; i < Len; i++) {
60  vald[N * i + i] += vecd[i];
61  }
62 #else
63  throw std::runtime_error("error USE_GPU is false, but gpu_status == true");
64 #endif
65  } else {
66 #pragma omp parallel for
67  for (size_t i = 0; i < Len; i++) {
68  vald[N * i + i] += vecd[i];
69  }
70  }
71 
72  logger.func_out();
73 }
75  const view1D<vector<double>, double> &vec);
77  const view1D<vector<float>, float> &vec);
78 
79 template <typename T>
80 void Dense<T>::diag_add(const view1D<matrix::Dense<T>, T> &vec) {
81  Logger &logger = Logger::get_instance();
82  logger.func_in(monolish_func);
83 
84  const T *vecd = vec.data();
85 
86  T *vald = val.data();
87  const size_t N = get_col();
88  const size_t Len = get_row() > get_col() ? get_row() : get_col();
89 
90  assert(Len == vec.size());
91 
92  if (gpu_status == true) {
93 #if MONOLISH_USE_GPU // gpu
94 #pragma omp target teams distribute parallel for
95  for (size_t i = 0; i < Len; i++) {
96  vald[N * i + i] += vecd[i];
97  }
98 #else
99  throw std::runtime_error("error USE_GPU is false, but gpu_status == true");
100 #endif
101  } else {
102 #pragma omp parallel for
103  for (size_t i = 0; i < Len; i++) {
104  vald[N * i + i] += vecd[i];
105  }
106  }
107 
108  logger.func_out();
109 }
111  const view1D<matrix::Dense<double>, double> &vec);
113  const view1D<matrix::Dense<float>, float> &vec);
114 } // namespace matrix
115 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::matrix::Dense::diag_add
void diag_add(const Float alpha)
Scalar and diag. vector of dense matrix add.
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42