monolish  0.14.2
MONOlithic LIner equation Solvers for Highly-parallel architecture
nrm1.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace monolish {
4 
5 namespace {
6 template <typename F1> double Dnrm1_core(const F1 &x) {
7  Logger &logger = Logger::get_instance();
8  logger.func_in(monolish_func);
9 
10  double ans = 0;
11  const double *xd = x.data();
12  size_t size = x.size();
13  const size_t xoffset = x.get_offset();
14 
15  if (x.get_device_mem_stat() == true) {
16 #if MONOLISH_USE_NVIDIA_GPU
17 #pragma omp target teams distribute parallel for reduction(+ : ans) map (tofrom: ans)
18  for (size_t i = 0; i < size; i++) {
19  ans += std::abs(xd[i + xoffset]);
20  }
21 #else
22  throw std::runtime_error(
23  "error USE_GPU is false, but get_device_mem_stat() == true");
24 #endif
25  } else {
26 #pragma omp parallel for reduction(+ : ans)
27  for (size_t i = 0; i < size; i++) {
28  ans += std::abs(xd[i + xoffset]);
29  }
30  }
31 
32 #if MONOLISH_USE_MPI
33  mpi::comm &comm = mpi::comm::get_instance();
34  ans = comm.Allreduce(ans);
35 #endif
36 
37  logger.func_out();
38  return ans;
39 }
40 
41 template <typename F1> float Snrm1_core(const F1 &x) {
42  Logger &logger = Logger::get_instance();
43  logger.func_in(monolish_func);
44 
45  float ans = 0;
46  const float *xd = x.data();
47  size_t size = x.size();
48  const size_t xoffset = x.get_offset();
49 
50  if (x.get_device_mem_stat() == true) {
51 #if MONOLISH_USE_NVIDIA_GPU
52 #pragma omp target teams distribute parallel for reduction(+ : ans) map (tofrom: ans)
53  for (size_t i = 0; i < size; i++) {
54  ans += std::abs(xd[i + xoffset]);
55  }
56 #else
57  throw std::runtime_error(
58  "error USE_GPU is false, but get_device_mem_stat() == true");
59 #endif
60  } else {
61 #pragma omp parallel for reduction(+ : ans)
62  for (size_t i = 0; i < size; i++) {
63  ans += std::abs(xd[i + xoffset]);
64  }
65  }
66 
67 #if MONOLISH_USE_MPI
68  mpi::comm &comm = mpi::comm::get_instance();
69  ans = comm.Allreduce(ans);
70 #endif
71 
72  logger.func_out();
73  return ans;
74 }
75 
76 } // namespace
77 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish
Definition: monolish_matrix_blas.hpp:10
monolish::mpi::comm::get_instance
static comm & get_instance()
Definition: monolish_mpi_core.hpp:33
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42