monolish  0.14.2
MONOlithic LIner equation Solvers for Highly-parallel architecture
dense_diag_scalar_sub.cpp
Go to the documentation of this file.
1 #include "../../../../include/monolish_blas.hpp"
2 #include "../../../internal/monolish_internal.hpp"
3 
4 namespace monolish::matrix {
5 
6 // sub scalar
7 template <typename T> void Dense<T>::diag_sub(const T alpha) {
8  Logger &logger = Logger::get_instance();
9  logger.func_in(monolish_func);
10 
11  T *vald = val.data();
12  const size_t N = get_col();
13  const size_t Len = get_row() > get_col() ? get_row() : get_col();
14 
15  if (gpu_status == true) {
16 #if MONOLISH_USE_NVIDIA_GPU // gpu
17 #pragma omp target teams distribute parallel for
18  for (size_t i = 0; i < Len; i++) {
19  vald[N * i + i] -= alpha;
20  }
21 #else
22  throw std::runtime_error("error USE_GPU is false, but gpu_status == true");
23 #endif
24  } else {
25 #pragma omp parallel for
26  for (size_t i = 0; i < Len; i++) {
27  vald[N * i + i] -= alpha;
28  }
29  }
30 
31  logger.func_out();
32 }
33 template void monolish::matrix::Dense<double>::diag_sub(const double alpha);
34 template void monolish::matrix::Dense<float>::diag_sub(const float alpha);
35 
36 } // namespace monolish::matrix
monolish::matrix
Declare sparse and dense matrix class.
Definition: monolish_coo.hpp:34
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::matrix::Dense::diag_sub
void diag_sub(const Float alpha)
Scalar and diag. vector of dense matrix sub.
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42