monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
vector_constructor.cpp
Go to the documentation of this file.
1 #include "../../include/monolish_blas.hpp"
2 #include "../../include/monolish_vml.hpp"
3 #include "../internal/monolish_internal.hpp"
4 
5 namespace monolish {
6 
8 template <typename T> vector<T>::vector(const size_t N) {
9  Logger &logger = Logger::get_instance();
10  logger.util_in(monolish_func);
11  resize(N);
12  logger.util_out();
13 }
14 template vector<double>::vector(const size_t N);
15 template vector<float>::vector(const size_t N);
16 
17 template <typename T> vector<T>::vector(const size_t N, const T value) {
18  Logger &logger = Logger::get_instance();
19  logger.util_in(monolish_func);
20  resize(N);
21 
22 #pragma omp parallel for
23  for (size_t i = 0; i < val.size(); i++) {
24  val[i] = value;
25  }
26 
27  logger.util_out();
28 }
29 template vector<double>::vector(const size_t N, const double value);
30 template vector<float>::vector(const size_t N, const float value);
31 
32 template <typename T> vector<T>::vector(const T *start, const T *end) {
33  Logger &logger = Logger::get_instance();
34  logger.util_in(monolish_func);
35  size_t size = (end - start);
36  resize(size);
37  std::copy(start, end, val.begin());
38  logger.util_out();
39 }
40 template vector<double>::vector(const double *start, const double *end);
41 template vector<float>::vector(const float *start, const float *end);
42 
43 template <typename T>
44 vector<T>::vector(const size_t N, const T min, const T max) {
45  Logger &logger = Logger::get_instance();
46  logger.util_in(monolish_func);
47  resize(N);
48  std::random_device random;
49  std::mt19937 mt(random());
50  std::uniform_real_distribution<> rand(min, max);
51 
52 #pragma omp parallel for
53  for (size_t i = 0; i < val.size(); i++) {
54  val[i] = rand(mt);
55  }
56  logger.util_out();
57 }
58 template vector<double>::vector(const size_t N, const double min,
59  const double max);
60 template vector<float>::vector(const size_t N, const float min,
61  const float max);
62 
63 // copy constructor
64 template <typename T> vector<T>::vector(const std::vector<T> &vec) {
65  Logger &logger = Logger::get_instance();
66  logger.util_in(monolish_func);
67  resize(vec.size());
68  std::copy(vec.begin(), vec.end(), val.begin());
69  logger.util_out();
70 }
71 
72 template vector<double>::vector(const std::vector<double> &vec);
73 template vector<float>::vector(const std::vector<float> &vec);
74 
75 // copy constructor
76 template <typename T> vector<T>::vector(const std::initializer_list<T> &list) {
77  Logger &logger = Logger::get_instance();
78  logger.util_in(monolish_func);
79  resize(list.size());
80  std::copy(list.begin(), list.end(), val.begin());
81  logger.util_out();
82 }
83 
84 template vector<double>::vector(const std::initializer_list<double> &list);
85 template vector<float>::vector(const std::initializer_list<float> &list);
86 
87 template <typename T> vector<T>::vector(const monolish::vector<T> &vec) {
88  Logger &logger = Logger::get_instance();
89  logger.util_in(monolish_func);
90 
91  resize(vec.size());
92 
93  // gpu copy and recv
94 #if MONOLISH_USE_GPU
95  if (vec.get_device_mem_stat()) {
96  send();
97  internal::vcopy(vec.val.size(), vec.val.data(), val.data(), true);
98  }
99 #endif
100  internal::vcopy(vec.val.size(), vec.val.data(), val.data(), false);
101 
102  logger.util_out();
103 }
104 
105 template vector<double>::vector(const vector<double> &vec);
106 template vector<float>::vector(const vector<float> &vec);
107 
108 template <typename T>
110  Logger &logger = Logger::get_instance();
111  logger.util_in(monolish_func);
112 
113  resize(vec.size());
114 
115  // gpu copy and recv
116 #if MONOLISH_USE_GPU
117  if (vec.get_device_mem_stat()) {
118  send();
119  internal::vcopy(vec.size(), vec.data() + vec.get_offset(), val.data(),
120  true);
121  }
122 #endif
123  internal::vcopy(vec.size(), vec.data() + vec.get_offset(), val.data(), false);
124 
125  logger.util_out();
126 }
127 
128 template vector<double>::vector(const view1D<vector<double>, double> &vec);
129 template vector<float>::vector(const view1D<vector<float>, float> &vec);
130 
131 template <typename T>
133  Logger &logger = Logger::get_instance();
134  logger.util_in(monolish_func);
135 
136  resize(vec.size());
137 
138  // gpu copy and recv
139 #if MONOLISH_USE_GPU
140  if (vec.get_device_mem_stat()) {
141  send();
142  internal::vcopy(vec.size(), vec.data() + vec.get_offset(), val.data(),
143  true);
144  }
145 #endif
146  internal::vcopy(vec.size(), vec.data() + vec.get_offset(), val.data(), false);
147 
148  logger.util_out();
149 }
150 
151 template vector<double>::vector(
152  const view1D<matrix::Dense<double>, double> &vec);
153 template vector<float>::vector(const view1D<matrix::Dense<float>, float> &vec);
154 
155 } // namespace monolish
monolish::vector::vector
vector()
Definition: monolish_vector.hpp:49
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::vml::min
void min(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
Create a new CRS matrix with smallest elements of two matrices (C[0:nnz] = min(A[0:nnz],...
Definition: matrix_vml.cpp:390
monolish::vector::val
std::vector< Float > val
size N vector data
Definition: monolish_vector.hpp:41
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::vector::get_offset
size_t get_offset() const
Definition: monolish_vector.hpp:219
monolish::vml::max
void max(const matrix::CRS< double > &A, const matrix::CRS< double > &B, matrix::CRS< double > &C)
Create a new CRS matrix with greatest elements of two matrices (C[0:nnz] = max(A[0:nnz],...
Definition: matrix_vml.cpp:382
monolish::matrix::Dense
Dense format Matrix.
Definition: monolish_coo.hpp:28
monolish::vector::size
auto size() const
get vector size
Definition: monolish_vector.hpp:306
monolish::Logger::util_out
void util_out()
Definition: logger_utils.cpp:123
monolish::vector::data
const Float * data() const
returns a direct pointer to the vector
Definition: monolish_vector.hpp:230
monolish::Logger::util_in
void util_in(const std::string func_name)
Definition: logger_utils.cpp:113
monolish::blas::copy
void copy(const matrix::Dense< double > &A, matrix::Dense< double > &C)
Dense matrix copy (C=A)
Definition: dense_copy.cpp:25
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::vector::get_device_mem_stat
bool get_device_mem_stat() const
true: sended, false: not send
Definition: monolish_vector.hpp:204
monolish::view1D
1D view class
Definition: monolish_coo.hpp:26
monolish::vector
vector class
Definition: monolish_coo.hpp:25
monolish::util::send
auto send(T &x)
send data to GPU
Definition: monolish_common.hpp:598
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42