monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
IO_crs.cpp
Go to the documentation of this file.
1 #include "../../../include/common/monolish_dense.hpp"
2 #include "../../../include/common/monolish_logger.hpp"
3 #include "../../../include/common/monolish_matrix.hpp"
4 #include "../../internal/monolish_internal.hpp"
5 
6 #include <cassert>
7 #include <fstream>
8 #include <iomanip>
9 #include <limits>
10 #include <sstream>
11 #include <stdexcept>
12 #include <string>
13 
14 namespace monolish {
15 namespace matrix {
16 
17 template <typename T> void CRS<T>::print_all(bool force_cpu) const {
18  Logger &logger = Logger::get_instance();
19  logger.util_in(monolish_func);
20 
21  if (get_device_mem_stat() == true && force_cpu == false) {
22 #if MONOLISH_USE_GPU
23  const T *vald = val.data();
24  const int *indexd = col_ind.data();
25  const int *ptrd = row_ptr.data();
26 
27 #pragma omp target
28  for (size_t i = 0; i < get_row(); i++) {
29  for (size_t j = (size_t)ptrd[i]; j < (size_t)ptrd[i + 1]; j++) {
30  printf("%lu %d %f\n", i + 1, indexd[j] + 1, vald[j]);
31  }
32  }
33 #else
34  throw std::runtime_error(
35  "error USE_GPU is false, but get_device_mem_stat() == true");
36 #endif
37  } else {
38  for (size_t i = 0; i < get_row(); i++) {
39  for (size_t j = (size_t)row_ptr[i]; j < (size_t)row_ptr[i + 1]; j++) {
40  std::cout << i + 1 << " " << col_ind[j] + 1 << " " << val[j]
41  << std::endl;
42  }
43  }
44  }
45 
46  logger.util_out();
47 }
48 template void CRS<double>::print_all(bool force_cpu) const;
49 template void CRS<float>::print_all(bool force_cpu) const;
50 
51 } // namespace matrix
52 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::Logger::util_out
void util_out()
Definition: logger_utils.cpp:123
monolish::matrix::CRS::print_all
void print_all(bool force_cpu=false) const
print all elements to standard I/O
Definition: IO_crs.cpp:17
monolish::Logger::util_in
void util_in(const std::string func_name)
Definition: logger_utils.cpp:113
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42