1 #include "../../include/common/monolish_logger.hpp"
2 #include "../../include/common/monolish_matrix.hpp"
3 #include "../../include/common/monolish_vector.hpp"
4 #include "../internal/monolish_internal.hpp"
11 CRS<T>::CRS(
const size_t M,
const size_t N,
const size_t NNZ) {
18 row_ptr.resize(M + 1);
24 template CRS<float>::CRS(
const size_t M,
const size_t N,
const size_t NNZ);
27 CRS<T>::CRS(
const size_t M,
const size_t N,
const size_t NNZ,
const int *rowptr,
28 const int *colind,
const T *value) {
35 row_ptr.resize(M + 1);
38 std::copy(rowptr, rowptr + (M + 1), row_ptr.begin());
39 std::copy(colind, colind + nnz, col_ind.begin());
40 std::copy(value, value + nnz, val.begin());
45 const int *rowptr,
const int *colind,
47 template CRS<float>::CRS(
const size_t M,
const size_t N,
const size_t NNZ,
48 const int *rowptr,
const int *colind,
52 CRS<T>::CRS(
const size_t M,
const size_t N,
const size_t NNZ,
const int *rowptr,
53 const int *colind,
const T *value,
const size_t origin) {
60 row_ptr.resize(M + 1);
63 std::copy(rowptr, rowptr + (M + 1), row_ptr.begin());
64 std::copy(colind, colind + nnz, col_ind.begin());
65 std::copy(value, value + nnz, val.begin());
67 #pragma omp parallel for
68 for (
size_t i = 0; i < nnz; i++) {
76 const int *rowptr,
const int *colind,
77 const double *value,
const size_t origin);
78 template CRS<float>::CRS(
const size_t M,
const size_t N,
const size_t NNZ,
79 const int *rowptr,
const int *colind,
80 const float *value,
const size_t origin);
83 CRS<T>::CRS(
const size_t M,
const size_t N,
const std::vector<int> &rowptr,
84 const std::vector<int> &colind,
const std::vector<T> &value) {
91 row_ptr.resize(M + 1);
94 std::copy(rowptr.data(), rowptr.data() + (M + 1), row_ptr.begin());
95 std::copy(colind.data(), colind.data() + nnz, col_ind.begin());
96 std::copy(value.data(), value.data() + nnz, val.begin());
101 const std::vector<int> &rowptr,
102 const std::vector<int> &colind,
103 const std::vector<double> &value);
105 const std::vector<int> &rowptr,
106 const std::vector<int> &colind,
107 const std::vector<float> &value);
109 template <
typename T>
110 CRS<T>::CRS(
const size_t M,
const size_t N,
const std::vector<int> &rowptr,
111 const std::vector<int> &colind,
const vector<T> &value) {
118 row_ptr.resize(M + 1);
121 std::copy(rowptr.data(), rowptr.data() + (M + 1), row_ptr.begin());
122 std::copy(colind.data(), colind.data() + nnz, col_ind.begin());
123 std::copy(value.data(), value.data() + nnz, val.begin());
125 if (value.get_device_mem_stat() ==
true) {
128 const T *data = value.data();
129 T *vald = val.data();
130 #pragma omp target teams distribute parallel for
131 for (
size_t i = 0; i < get_nnz(); i++) {
135 throw std::runtime_error(
136 "error USE_GPU is false, but get_device_mem_stat() == true");
145 const std::vector<int> &rowptr,
146 const std::vector<int> &colind,
147 const vector<double> &value);
149 const std::vector<int> &rowptr,
150 const std::vector<int> &colind,
151 const vector<float> &value);
154 template <
typename T>
CRS<T>::CRS(
const CRS<T> &mat) {
158 val.resize(mat.get_nnz());
159 col_ind.resize(mat.get_nnz());
160 row_ptr.resize(mat.get_row() + 1);
162 rowN = mat.get_row();
163 colN = mat.get_col();
167 if (mat.get_device_mem_stat()) {
169 internal::vcopy(mat.row_ptr.size(), mat.row_ptr.data(), row_ptr.data(),
171 internal::vcopy(mat.col_ind.size(), mat.col_ind.data(), col_ind.data(),
173 internal::vcopy(mat.val.size(), mat.val.data(), val.data(),
true);
177 internal::vcopy(mat.row_ptr.size(), mat.row_ptr.data(), row_ptr.data(),
179 internal::vcopy(mat.col_ind.size(), mat.col_ind.data(), col_ind.data(),
181 internal::vcopy(mat.val.size(), mat.val.data(), val.data(),
false);