16 #ifndef dealii_cuda_sparse_matrix_h 17 #define dealii_cuda_sparse_matrix_h 19 #include <deal.II/base/config.h> 21 #include <deal.II/base/subscriptor.h> 25 #ifdef DEAL_II_COMPILER_CUDA_AWARE 26 # include <deal.II/base/cuda.h> 28 # include <deal.II/lac/cuda_vector.h> 29 # include <deal.II/lac/sparse_matrix.h> 31 # include <cusparse.h> 33 DEAL_II_NAMESPACE_OPEN
49 template <
typename Number>
88 const ::SparseMatrix<Number> &sparse_matrix_host);
125 const ::SparseMatrix<Number> &sparse_matrix_host);
164 template <
class StreamType>
166 print(StreamType &out,
167 const bool across =
false,
168 const bool diagonal_first =
true)
const;
192 const unsigned int precision = 3,
193 const bool scientific =
true,
194 const unsigned int width = 0,
195 const char * zero_string =
" ",
196 const double denominator = 1.)
const;
328 std::tuple<Number *, int *, int *, cusparseMatDescr_t>
356 std::unique_ptr<Number[], void (*)(Number *)>
val_dev;
376 template <
typename Number>
385 template <
typename Number>
394 template <
typename Number>
403 template <
typename Number>
404 template <
class StreamType>
408 const bool diagonal_first)
const 414 std::vector<int> rows(n_rows + 1);
415 std::vector<int> cols(nnz);
416 std::vector<double> val(nnz);
421 bool has_diagonal =
false;
422 Number diagonal = Number();
429 for (
size_type j = rows[i]; j < rows[i + 1] && cols[j] <= i; ++j)
436 out <<
' ' << i <<
',' << i <<
':' << diagonal;
438 out <<
'(' << i <<
',' << i <<
") " << diagonal
444 for (
size_type j = rows[i]; j < rows[i + 1]; ++j)
446 if (has_diagonal && i == cols[j])
449 out <<
' ' << i <<
',' << cols[j] <<
':' << val[j];
451 out <<
"(" << i <<
"," << cols[j] <<
") " << val[j] << std::endl;
460 template <
typename Number>
463 const unsigned int precision,
464 const bool scientific,
465 const unsigned int width_,
466 const char * zero_string,
467 const double denominator)
const 473 std::vector<int> rows(n_rows + 1);
474 std::vector<int> cols(nnz);
475 std::vector<Number> val(nnz);
480 unsigned int width = width_;
482 std::ios::fmtflags old_flags = out.flags();
483 unsigned int old_precision = out.precision(precision);
487 out.setf(std::ios::scientific, std::ios::floatfield);
489 width = precision + 7;
493 out.setf(std::ios::fixed, std::ios::floatfield);
495 width = precision + 2;
505 out << std::setw(width) << val[j] * Number(denominator) <<
' ';
509 out << std::setw(width) << zero_string <<
' ';
516 out.precision(old_precision);
517 out.flags(old_flags);
521 DEAL_II_NAMESPACE_CLOSE
Number matrix_norm_square(const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
static ::ExceptionBase & ExcIO()
std::tuple< Number *, int *, int *, cusparseMatDescr_t > get_cusparse_matrix() const
Number matrix_scalar_product(const LinearAlgebra::CUDAWrappers::Vector< Number > &u, const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
static ::ExceptionBase & ExcNotInitialized()
#define AssertThrow(cond, exc)
SparseMatrix & operator*=(const Number factor)
cusparseHandle_t cusparse_handle
Number frobenius_norm() const
SparseMatrix & operator/=(const Number factor)
std::unique_ptr< Number[], void(*)(Number *)> val_dev
std::unique_ptr< int[], void(*)(int *)> column_index_dev
Number residual(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &x, const LinearAlgebra::CUDAWrappers::Vector< Number > &b) const
void reinit(Utilities::CUDA::Handle &handle, const ::SparseMatrix< Number > &sparse_matrix_host)
Number linfty_norm() const
#define Assert(cond, exc)
std::unique_ptr< int[], void(*)(int *)> row_ptr_dev
SparseMatrix & operator=(CUDAWrappers::SparseMatrix< Number > &&)
void Tvmult_add(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
void copy_to_host(const T *pointer_dev, std::vector< T > &vector_host)
void vmult_add(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
void Tvmult(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
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
void vmult(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::size_t n_nonzero_elements() const