Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Csr/Kokkos/Morpheus_MatrixOperations_Impl.hpp
1
24#ifndef MORPHEUS_CSR_KOKKOS_MATRIXOPERATIONS_IMPL_HPP
25#define MORPHEUS_CSR_KOKKOS_MATRIXOPERATIONS_IMPL_HPP
26
27#include <Morpheus_Exceptions.hpp>
28#include <Morpheus_SpaceTraits.hpp>
29#include <Morpheus_FormatTraits.hpp>
30#include <Morpheus_FormatTags.hpp>
31#include <Morpheus_Spaces.hpp>
32
33namespace Morpheus {
34namespace Impl {
35
36template <typename ExecSpace, typename Matrix, typename Vector>
37void update_diagonal(
38 Matrix& A, const Vector& diagonal,
39 typename std::enable_if_t<
40 Morpheus::is_csr_matrix_format_container_v<Matrix> &&
41 Morpheus::is_dense_vector_format_container_v<Vector> &&
42 Morpheus::has_generic_backend_v<ExecSpace> &&
43 Morpheus::has_access_v<ExecSpace, Matrix, Vector>>* = nullptr) {
44 using execution_space = typename ExecSpace::execution_space;
45 using size_type = typename Matrix::size_type;
46 using index_type = typename Matrix::index_type;
47 using value_array = typename Matrix::value_array_type::value_array_type;
48 using index_array = typename Matrix::index_array_type::value_array_type;
49
50 using range_policy =
51 Kokkos::RangePolicy<Kokkos::IndexType<size_type>, execution_space>;
52
53 value_array values = A.values().view();
54 index_array column_indices = A.column_indices().view();
55 index_array row_offsets = A.row_offsets().view();
56 const value_array diagonal_view = diagonal.const_view();
57
58 range_policy policy(0, A.nrows());
59
60 Kokkos::parallel_for(
61 policy, KOKKOS_LAMBDA(const size_type i) {
62 for (index_type jj = row_offsets[i]; jj < row_offsets[i + 1]; jj++) {
63 if (column_indices[jj] == (index_type)i) {
64 values[jj] = diagonal_view[i];
65 break;
66 }
67 }
68 });
69}
70
71template <typename ExecSpace, typename Matrix, typename Vector>
72void get_diagonal(
73 Matrix&, const Vector&,
74 typename std::enable_if_t<
75 Morpheus::is_csr_matrix_format_container_v<Matrix> &&
76 Morpheus::is_dense_vector_format_container_v<Vector> &&
77 Morpheus::has_generic_backend_v<ExecSpace> &&
78 Morpheus::has_access_v<ExecSpace, Matrix, Vector>>* = nullptr) {
79 throw Morpheus::NotImplementedException("get_diagonal not implemented yet");
80}
81
82template <typename ExecSpace, typename Matrix, typename SizeType,
83 typename ValueType>
84void set_value(Matrix&, SizeType, SizeType, ValueType,
85 typename std::enable_if_t<
86 Morpheus::is_csr_matrix_format_container_v<Matrix> &&
87 Morpheus::has_generic_backend_v<ExecSpace> &&
88 Morpheus::has_access_v<ExecSpace, Matrix>>* = nullptr) {
89 throw Morpheus::NotImplementedException("set_value not implemented yet");
90}
91
92template <typename ExecSpace, typename Matrix, typename IndexVector,
93 typename ValueVector>
94void set_values(
95 Matrix&, typename IndexVector::value_type, const IndexVector,
96 typename IndexVector::value_type, const IndexVector, const ValueVector,
97 typename std::enable_if_t<
98 Morpheus::is_csr_matrix_format_container_v<Matrix> &&
99 Morpheus::is_dense_vector_format_container_v<IndexVector> &&
100 Morpheus::is_dense_vector_format_container_v<ValueVector> &&
101 Morpheus::has_generic_backend_v<ExecSpace> &&
102 Morpheus::has_access_v<ExecSpace, Matrix, IndexVector, ValueVector>>* =
103 nullptr) {
104 throw Morpheus::NotImplementedException("set_values not implemented yet");
105}
106
107template <typename ExecSpace, typename Matrix, typename TransposeMatrix>
108void transpose(
109 const Matrix&, TransposeMatrix&,
110 typename std::enable_if_t<
111 Morpheus::is_csr_matrix_format_container_v<Matrix> &&
112 Morpheus::is_csr_matrix_format_container_v<TransposeMatrix> &&
113 Morpheus::has_generic_backend_v<ExecSpace> &&
114 Morpheus::has_access_v<ExecSpace, Matrix, TransposeMatrix>>* =
115 nullptr) {
116 throw Morpheus::NotImplementedException("transpose not implemented yet");
117}
118
119} // namespace Impl
120} // namespace Morpheus
121
122#endif // MORPHEUS_CSR_KOKKOS_MATRIXOPERATIONS_IMPL_HPP
Definition: Morpheus_Exceptions.hpp:43
Generic Morpheus interfaces.
Definition: dummy.cpp:24