monolish  0.14.2
MONOlithic LIner equation Solvers for Highly-parallel architecture
copy_crs.cpp
Go to the documentation of this file.
1 #include "../../../include/common/monolish_common.hpp"
2 #include "../../../include/common/monolish_dense.hpp"
3 #include "../../../include/common/monolish_logger.hpp"
4 #include "../../../include/common/monolish_matrix.hpp"
5 #include "../../internal/monolish_internal.hpp"
6 
7 namespace monolish {
8 namespace matrix {
9 
10 template <typename T> void CRS<T>::operator=(const CRS<T> &mat) {
11  Logger &logger = Logger::get_instance();
12  logger.util_in(monolish_func);
13 
14  // err
15  assert(monolish::util::is_same_size(*this, mat));
16  assert(monolish::util::is_same_structure(*this, mat));
17  assert(monolish::util::is_same_device_mem_stat(*this, mat));
18 
19  if (mat.get_device_mem_stat() == true) {
20 #if MONOLISH_USE_NVIDIA_GPU
21  internal::vcopy(mat.row_ptr.size(), mat.row_ptr.data(), row_ptr.data(),
22  true);
23  internal::vcopy(mat.col_ind.size(), mat.col_ind.data(), col_ind.data(),
24  true);
25  internal::vcopy(mat.val.size(), mat.val.data(), val.data(), true);
26 #endif
27  } else {
28  internal::vcopy(mat.row_ptr.size(), mat.row_ptr.data(), row_ptr.data(),
29  false);
30  internal::vcopy(mat.col_ind.size(), mat.col_ind.data(), col_ind.data(),
31  false);
32  internal::vcopy(mat.val.size(), mat.val.data(), val.data(), false);
33  }
34 
35  logger.util_out();
36 }
37 template void CRS<double>::operator=(const CRS<double> &mat);
38 template void CRS<float>::operator=(const CRS<float> &mat);
39 
40 template <typename T>
41 void CRS<T>::set_ptr(const size_t M, const size_t N,
42  const std::vector<int> &rowptr,
43  const std::vector<int> &colind,
44  const std::vector<T> &value) {
45  Logger &logger = Logger::get_instance();
46  logger.util_in(monolish_func);
47  col_ind = colind;
48  row_ptr = rowptr;
49  val = value;
50 
51  rowN = M;
52  colN = N;
53  nnz = val.size();
54  logger.util_out();
55 }
56 template void CRS<double>::set_ptr(const size_t M, const size_t N,
57  const std::vector<int> &rowptr,
58  const std::vector<int> &colind,
59  const std::vector<double> &value);
60 template void CRS<float>::set_ptr(const size_t M, const size_t N,
61  const std::vector<int> &rowptr,
62  const std::vector<int> &colind,
63  const std::vector<float> &value);
64 
65 } // namespace matrix
66 } // namespace monolish
monolish::util::is_same_size
bool is_same_size(const T &x, const U &y)
compare size of vector or 1Dview (same as is_same_structure())
Definition: monolish_common.hpp:377
monolish::matrix::CRS::val
std::vector< Float > val
CRS format value, which stores values of the non-zero elements (size nnz)
Definition: monolish_crs.hpp:68
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::matrix::CRS::operator=
void operator=(const CRS< Float > &mat)
matrix copy
Definition: copy_crs.cpp:10
monolish::util::is_same_structure
bool is_same_structure(const T A, const U B)
compare matrix structure
Definition: monolish_common.hpp:282
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::matrix::CRS::col_ind
std::vector< int > col_ind
CRS format column index, which stores column numbers of the non-zero elements (size nnz)
Definition: monolish_crs.hpp:74
monolish::util::is_same_device_mem_stat
bool is_same_device_mem_stat(const T &arg1, const U &arg2)
compare same device memory status
Definition: monolish_common.hpp:454
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:10
monolish::matrix::CRS::get_device_mem_stat
bool get_device_mem_stat() const
true: sended, false: not send
Definition: monolish_crs.hpp:330
monolish::matrix::CRS::set_ptr
void set_ptr(const size_t M, const size_t N, const std::vector< int > &rowptr, const std::vector< int > &colind, const std::vector< Float > &value)
Set CRS array from std::vector.
Definition: copy_crs.cpp:41
monolish::matrix::CRS::row_ptr
std::vector< int > row_ptr
CRS format row pointer, which stores the starting points of the rows of the arrays value and col_ind ...
Definition: monolish_crs.hpp:80
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::matrix::CRS
Compressed Row Storage (CRS) format Matrix.
Definition: monolish_coo.hpp:36