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,
65 static_assert(is_crs_matrix_v<LocalMatrix> == is_crs_matrix_v<IntLocalMatrix>,
"Expected both to be CrsMatrix or BlockCrsMatrix");
67 using Rowptrs =
typename LocalMatrix::row_map_type;
68 using IntRowptrs =
typename IntLocalMatrix::row_map_type;
70 IntRowPtrHelper(
size_t nnz,
const typename LocalMatrix::row_map_type& rowptrs)
73 if(shouldUseIntRowptrs())
74 fillRowptrsInt(rowptrs);
78 bool shouldUseIntRowptrs()
const
83 return nnz_ <= size_t(INT_MAX) && !std::is_same_v<int, typename Rowptrs::non_const_value_type>;
86 void fillRowptrsInt(
const Rowptrs& rowptrs)
90 typename IntRowptrs::non_const_type rowptrs_temp(
91 Kokkos::view_alloc(Kokkos::WithoutInitializing,
"rowptrs_int"), rowptrs.extent(0));
92 Kokkos::parallel_for(Kokkos::RangePolicy<typename LocalMatrix::execution_space>(0, rowptrs.extent(0)),
95 rowptrs_temp(i) = int(rowptrs(i));
97 rowptrs_int_ = rowptrs_temp;
100 IntLocalMatrix getIntRowptrMatrix(
const LocalMatrix& A)
102 if constexpr(KokkosSparse::is_crs_matrix_v<LocalMatrix>)
104 return IntLocalMatrix(
"", A.numRows(), A.numCols(), A.nnz(),
105 A.values, rowptrs_int_, A.graph.entries);
109 return IntLocalMatrix(
"", A.numRows(), A.numCols(), A.nnz(),
110 A.values, rowptrs_int_, A.graph.entries, A.blockDim());
115 IntRowptrs rowptrs_int_;
120 #endif // TPETRA_INTROWPTR_HELPER_HPP
Forward declaration of Tpetra::CrsMatrix.