40 #ifndef TPETRA_INTROWPTR_HELPER_HPP
41 #define TPETRA_INTROWPTR_HELPER_HPP
44 #include "Kokkos_Core.hpp"
45 #include "KokkosSparse_spmv_handle.hpp"
58 template <
typename LocalMatrix,
59 typename IntLocalMatrix = KokkosSparse::CrsMatrix<
typename LocalMatrix::value_type,
60 typename LocalMatrix::ordinal_type,
61 typename LocalMatrix::device_type,
64 static_assert(is_crs_matrix_v<LocalMatrix> == is_crs_matrix_v<IntLocalMatrix>,
"Expected both to be CrsMatrix or BlockCrsMatrix");
66 using Rowptrs =
typename LocalMatrix::row_map_type;
67 using IntRowptrs =
typename IntLocalMatrix::row_map_type;
69 IntRowPtrHelper(
size_t nnz,
const typename LocalMatrix::row_map_type& rowptrs)
71 if (shouldUseIntRowptrs())
72 fillRowptrsInt(rowptrs);
76 bool shouldUseIntRowptrs()
const {
80 return nnz_ <= size_t(INT_MAX) && !std::is_same_v<int, typename Rowptrs::non_const_value_type>;
83 void fillRowptrsInt(
const Rowptrs& rowptrs) {
86 typename IntRowptrs::non_const_type rowptrs_temp(
87 Kokkos::view_alloc(Kokkos::WithoutInitializing,
"rowptrs_int"), rowptrs.extent(0));
89 Kokkos::RangePolicy<typename LocalMatrix::execution_space>(0, rowptrs.extent(0)),
90 KOKKOS_LAMBDA(
int i) {
91 rowptrs_temp(i) = int(rowptrs(i));
93 rowptrs_int_ = rowptrs_temp;
96 IntLocalMatrix getIntRowptrMatrix(
const LocalMatrix& A) {
97 if constexpr (KokkosSparse::is_crs_matrix_v<LocalMatrix>) {
98 return IntLocalMatrix(
"", A.numRows(), A.numCols(), A.nnz(),
99 A.values, rowptrs_int_, A.graph.entries);
101 return IntLocalMatrix(
"", A.numRows(), A.numCols(), A.nnz(),
102 A.values, rowptrs_int_, A.graph.entries, A.blockDim());
107 IntRowptrs rowptrs_int_;
112 #endif // TPETRA_INTROWPTR_HELPER_HPP
Forward declaration of Tpetra::CrsMatrix.