Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_KokkosCrsMatrix_MatrixAdapter_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Amesos2: Templated Direct Sparse Solver Package
4 //
5 // Copyright 2011 NTESS and the Amesos2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 
11 #ifndef AMESOS2_KOKKOS_CRSMATRIX_MATRIXADAPTER_DEF_HPP
12 #define AMESOS2_KOKKOS_CRSMATRIX_MATRIXADAPTER_DEF_HPP
13 
15 #include "Amesos2_MatrixAdapter_def.hpp"
16 #include "KokkosSparse_CrsMatrix.hpp"
17 #include <Tpetra_Core.hpp>
18 
19 namespace Amesos2 {
20 
21  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
22  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::ConcreteMatrixAdapter(Teuchos::RCP<matrix_t> m)
23  : MatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>(m)
24  {
25 
26  }
27 
28  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
29  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
30  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getRowIndexBase() const
31  {
32  return 0;
33  }
34 
35  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
36  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
37  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getColumnIndexBase() const
38  {
39  return 0;
40  }
41 
42  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
43  const Teuchos::RCP<const Teuchos::Comm<int> >
44  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getComm_impl() const
45  {
46  return Tpetra::getDefaultComm(); // Kokkos CrsMatrix currently is just serial
47  }
48 
49  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
50  const RCP<const Tpetra::Map<typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::local_ordinal_t,
51  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_ordinal_t,
52  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::node_t> >
53  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getRowMap_impl() const
54  {
55  return Teuchos::null; // not going to use this right now - serial
56  }
57 
58  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
59  const RCP<const Tpetra::Map<typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::local_ordinal_t,
60  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_ordinal_t,
61  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::node_t> >
62  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getColMap_impl() const
63  {
64  return Teuchos::null; // not going to use this right now - serial
65  }
66 
67  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
68  Teuchos::RCP<const MatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace> > >
69  ConcreteMatrixAdapter<
70  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>
71  >::get_impl(
72  [[maybe_unused]] const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map,
73  [[maybe_unused]] EDistribution distribution
74  ) const {
75  TEUCHOS_TEST_FOR_EXCEPTION( true,
76  std::runtime_error,
77  "get_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
78  "Please contact the Amesos2 developers." );
79  }
80 
81  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
82  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
83  ConcreteMatrixAdapter<
84  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNumRows_impl() const
85  {
86  return this->mat_->numRows();
87  }
88 
89  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
90  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
91  ConcreteMatrixAdapter<
92  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNumCols_impl() const
93  {
94  return this->mat_->numCols();
95  }
96 
97  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
98  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
99  ConcreteMatrixAdapter<
100  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNNZ_impl() const
101  {
102  return this->mat_->nnz();
103  }
104 
105  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
106  const Teuchos::RCP<const Tpetra::Map<typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::local_ordinal_t,
107  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_ordinal_t,
108  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::node_t> >
109  ConcreteMatrixAdapter<
110  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getMap_impl() const
111  {
112  return( Teuchos::null );
113  }
114 
115  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
116  size_t
117  ConcreteMatrixAdapter<
118  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>
119  >::getGlobalRowNNZ_impl(
120  [[maybe_unused]] global_ordinal_t row
121  ) const {
122  TEUCHOS_TEST_FOR_EXCEPTION( true,
123  std::runtime_error,
124  "getGlobalRowNNZ_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
125  "Please contact the Amesos2 developers." );
126  }
127 
128  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
129  size_t
130  ConcreteMatrixAdapter<
131  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getLocalRowNNZ_impl(local_ordinal_t row) const
132  {
133  TEUCHOS_TEST_FOR_EXCEPTION( true,
134  std::runtime_error,
135  "getLocalRowNNZ_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
136  "Please contact the Amesos2 developers." );
137  }
138 
139  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
140  size_t
141  ConcreteMatrixAdapter<
142  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalColNNZ_impl(global_ordinal_t col) const
143  {
144  TEUCHOS_TEST_FOR_EXCEPTION( true,
145  std::runtime_error,
146  "Column access to row-based object not yet supported. "
147  "Please contact the Amesos2 developers." );
148  }
149 
150  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
151  size_t
152  ConcreteMatrixAdapter<
153  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getLocalColNNZ_impl(local_ordinal_t col) const
154  {
155  TEUCHOS_TEST_FOR_EXCEPTION( true,
156  std::runtime_error,
157  "Column access to row-based object not yet supported. "
158  "Please contact the Amesos2 developers." );
159  }
160 
161  // implementation functions
162  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
163  template <typename KV_GO, typename KV_S>
164  void
165  ConcreteMatrixAdapter<
166  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>
167  >::getGlobalRowCopy_kokkos_view_impl(
168  [[maybe_unused]] global_ordinal_t row,
169  [[maybe_unused]] KV_GO & indices,
170  [[maybe_unused]] KV_S & vals,
171  [[maybe_unused]] size_t& nnz
172  ) const {
173  TEUCHOS_TEST_FOR_EXCEPTION( true,
174  std::runtime_error,
175  "getGlobalRowCopy_kokkos_view_impl not implemented for Kokkos CrsMatrix yet. "
176  "Please contact the Amesos2 developers." );
177  }
178 
179 } // end namespace Amesos2
180 
181 #endif // AMESOS2_KOKKOS_CRSMATRIX_MATRIXADAPTER_DEF_HPP
Specialization of the ConcreteMatrixAdapter for KokkosSparse::CrsMatrix.
EDistribution
Definition: Amesos2_TypeDecl.hpp:89