monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
IO_vector.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 "../../../include/monolish_vml.hpp"
5 #include "../../internal/monolish_internal.hpp"
6 
7 #include <cassert>
8 #include <fstream>
9 #include <iomanip>
10 #include <limits>
11 #include <sstream>
12 #include <stdexcept>
13 #include <string>
14 
15 namespace monolish {
16 
17 template <typename T> void vector<T>::print_all(bool force_cpu) const {
18  Logger &logger = Logger::get_instance();
19  logger.util_in(monolish_func);
20 
21  const T *vald = val.data();
22 
23  if (get_device_mem_stat() == true && force_cpu == false) {
24 #if MONOLISH_USE_GPU
25  const size_t N = val.size();
26 #pragma omp target
27  for (size_t i = 0; i < N; i++) {
28  printf("%f\n", vald[i]);
29  }
30 #else
31  throw std::runtime_error(
32  "error USE_GPU is false, but get_device_mem_stat() == true");
33 #endif
34  } else {
35  for (size_t i = 0; i < val.size(); i++) {
36  std::cout << vald[i] << std::endl;
37  }
38  }
39 
40  logger.util_out();
41 }
42 template void vector<double>::print_all(bool force_cpu) const;
43 template void vector<float>::print_all(bool force_cpu) const;
44 
45 template <typename T> void vector<T>::print_all(std::string filename) const {
46  Logger &logger = Logger::get_instance();
47  logger.util_in(monolish_func);
48  std::ofstream ofs(filename);
49  if (!ofs) {
50  throw std::runtime_error("error file cant open");
51  }
52  for (const auto v : val) {
53  ofs << v << std::endl;
54  }
55  logger.util_out();
56 }
57 template void vector<double>::print_all(std::string filename) const;
58 template void vector<float>::print_all(std::string filename) const;
59 
60 } // 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::Logger::util_in
void util_in(const std::string func_name)
Definition: logger_utils.cpp:113
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::vector::print_all
void print_all(bool force_cpu=false) const
print all elements to standart I/O
Definition: IO_vector.cpp:17
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42