15#ifndef dealii_cuda_sparse_matrix_h
16#define dealii_cuda_sparse_matrix_h
24#ifdef DEAL_II_WITH_CUDA
46 template <
typename Number>
85 const ::SparseMatrix<Number> &sparse_matrix_host);
122 const ::SparseMatrix<Number> &sparse_matrix_host);
161 template <
typename StreamType>
163 print(StreamType &out,
164 const bool across =
false,
165 const bool diagonal_first =
true)
const;
191 const unsigned int precision = 3,
192 const bool scientific =
true,
193 const unsigned int width = 0,
194 const char *zero_string =
" ",
195 const double denominator = 1.,
196 const char *separator =
" ")
const;
328 std::tuple<Number *, int *, int *, cusparseMatDescr_t, cusparseSpMatDescr_t>
356 std::unique_ptr<Number[], void (*)(Number *)>
val_dev;
381 template <
typename Number>
390 template <
typename Number>
399 template <
typename Number>
408 template <
typename Number>
409 template <
typename StreamType>
413 const bool diagonal_first)
const
419 std::vector<int> rows(n_rows + 1);
420 std::vector<int> cols(nnz);
421 std::vector<double> val(nnz);
426 bool has_diagonal =
false;
427 Number diagonal = Number();
434 for (
size_type j = rows[i]; j < rows[i + 1] && cols[j] <= i; ++j)
441 out <<
' ' << i <<
',' << i <<
':' << diagonal;
443 out <<
'(' << i <<
',' << i <<
") " << diagonal
449 for (
size_type j = rows[i]; j < rows[i + 1]; ++j)
451 if (has_diagonal && i == cols[j])
454 out <<
' ' << i <<
',' << cols[j] <<
':' << val[j];
456 out <<
'(' << i <<
',' << cols[j] <<
") " << val[j] << std::endl;
465 template <
typename Number>
468 const unsigned int precision,
469 const bool scientific,
470 const unsigned int width_,
471 const char *zero_string,
472 const double denominator,
473 const char *separator)
const
479 std::vector<int> rows(n_rows + 1);
480 std::vector<int> cols(nnz);
481 std::vector<Number> val(nnz);
486 unsigned int width = width_;
488 std::ios::fmtflags old_flags = out.flags();
489 unsigned int old_precision = out.precision(precision);
493 out.setf(std::ios::scientific, std::ios::floatfield);
495 width = precision + 7;
499 out.setf(std::ios::fixed, std::ios::floatfield);
501 width = precision + 2;
511 out << std::setw(width) << val[j] * Number(denominator)
516 out << std::setw(width) << zero_string << separator;
523 out.precision(old_precision);
524 out.flags(old_flags);
void vmult_add(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
void print(StreamType &out, const bool across=false, const bool diagonal_first=true) const
std::tuple< Number *, int *, int *, cusparseMatDescr_t, cusparseSpMatDescr_t > get_cusparse_matrix() const
void Tvmult_add(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
std::unique_ptr< int[], void(*)(int *)> column_index_dev
cusparseHandle_t cusparse_handle
void Tvmult(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
std::unique_ptr< int[], void(*)(int *)> row_ptr_dev
void reinit(Utilities::CUDA::Handle &handle, const ::SparseMatrix< Number > &sparse_matrix_host)
Number frobenius_norm() const
Number matrix_norm_square(const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
SparseMatrix & operator*=(const Number factor)
cusparseSpMatDescr_t sp_descr
void print_formatted(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const unsigned int width=0, const char *zero_string=" ", const double denominator=1., const char *separator=" ") const
Number residual(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &x, const LinearAlgebra::CUDAWrappers::Vector< Number > &b) const
SparseMatrix & operator/=(const Number factor)
SparseMatrix & operator=(CUDAWrappers::SparseMatrix< Number > &&)
std::unique_ptr< Number[], void(*)(Number *)> val_dev
void vmult(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
SparseMatrix(const CUDAWrappers::SparseMatrix< Number > &)=delete
std::size_t n_nonzero_elements() const
Number linfty_norm() const
SparseMatrix & operator=(const CUDAWrappers::SparseMatrix< Number > &)=delete
Number matrix_scalar_product(const LinearAlgebra::CUDAWrappers::Vector< Number > &u, const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotInitialized()
#define AssertThrow(cond, exc)
void copy_to_host(const ArrayView< const T, MemorySpace::CUDA > &in, ArrayView< T, MemorySpace::Host > &out)