Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_KokkosCrsMatrix_MatrixAdapter_def.hpp
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
44 
45 #ifndef AMESOS2_KOKKOS_CRSMATRIX_MATRIXADAPTER_DEF_HPP
46 #define AMESOS2_KOKKOS_CRSMATRIX_MATRIXADAPTER_DEF_HPP
47 
49 #include "Amesos2_MatrixAdapter_def.hpp"
50 #include "KokkosSparse_CrsMatrix.hpp"
51 #include <Tpetra_Core.hpp>
52 
53 namespace Amesos2 {
54 
55  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
56  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::ConcreteMatrixAdapter(Teuchos::RCP<matrix_t> m)
57  : MatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>(m)
58  {
59 
60  }
61 
62  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
63  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
64  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getRowIndexBase() const
65  {
66  return 0;
67  }
68 
69  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
70  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
71  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getColumnIndexBase() const
72  {
73  return 0;
74  }
75 
76  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
77  const Teuchos::RCP<const Teuchos::Comm<int> >
78  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getComm_impl() const
79  {
80  return Tpetra::getDefaultComm(); // Kokkos CrsMatrix currently is just serial
81  }
82 
83  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
84  const RCP<const Tpetra::Map<typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::local_ordinal_t,
85  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_ordinal_t,
86  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::node_t> >
87  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getRowMap_impl() const
88  {
89  return Teuchos::null; // not going to use this right now - serial
90  }
91 
92  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
93  const RCP<const Tpetra::Map<typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::local_ordinal_t,
94  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_ordinal_t,
95  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::node_t> >
96  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getColMap_impl() const
97  {
98  return Teuchos::null; // not going to use this right now - serial
99  }
100 
101  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
102  Teuchos::RCP<const MatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace> > >
103  ConcreteMatrixAdapter<
104  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>
105  >::get_impl(
106  [[maybe_unused]] const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map,
107  [[maybe_unused]] EDistribution distribution
108  ) const {
109  TEUCHOS_TEST_FOR_EXCEPTION( true,
110  std::runtime_error,
111  "get_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
112  "Please contact the Amesos2 developers." );
113  }
114 
115  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
116  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
117  ConcreteMatrixAdapter<
118  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNumRows_impl() const
119  {
120  return this->mat_->numRows();
121  }
122 
123  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
124  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
125  ConcreteMatrixAdapter<
126  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNumCols_impl() const
127  {
128  return this->mat_->numCols();
129  }
130 
131  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
132  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
133  ConcreteMatrixAdapter<
134  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNNZ_impl() const
135  {
136  return this->mat_->nnz();
137  }
138 
139  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
140  const Teuchos::RCP<const Tpetra::Map<typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::local_ordinal_t,
141  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_ordinal_t,
142  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::node_t> >
143  ConcreteMatrixAdapter<
144  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getMap_impl() const
145  {
146  return( Teuchos::null );
147  }
148 
149  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
150  size_t
151  ConcreteMatrixAdapter<
152  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>
153  >::getGlobalRowNNZ_impl(
154  [[maybe_unused]] global_ordinal_t row
155  ) const {
156  TEUCHOS_TEST_FOR_EXCEPTION( true,
157  std::runtime_error,
158  "getGlobalRowNNZ_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
159  "Please contact the Amesos2 developers." );
160  }
161 
162  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
163  size_t
164  ConcreteMatrixAdapter<
165  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getLocalRowNNZ_impl(local_ordinal_t row) const
166  {
167  TEUCHOS_TEST_FOR_EXCEPTION( true,
168  std::runtime_error,
169  "getLocalRowNNZ_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
170  "Please contact the Amesos2 developers." );
171  }
172 
173  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
174  size_t
175  ConcreteMatrixAdapter<
176  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalColNNZ_impl(global_ordinal_t col) const
177  {
178  TEUCHOS_TEST_FOR_EXCEPTION( true,
179  std::runtime_error,
180  "Column access to row-based object not yet supported. "
181  "Please contact the Amesos2 developers." );
182  }
183 
184  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
185  size_t
186  ConcreteMatrixAdapter<
187  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getLocalColNNZ_impl(local_ordinal_t col) const
188  {
189  TEUCHOS_TEST_FOR_EXCEPTION( true,
190  std::runtime_error,
191  "Column access to row-based object not yet supported. "
192  "Please contact the Amesos2 developers." );
193  }
194 
195  // implementation functions
196  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
197  template <typename KV_GO, typename KV_S>
198  void
199  ConcreteMatrixAdapter<
200  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>
201  >::getGlobalRowCopy_kokkos_view_impl(
202  [[maybe_unused]] global_ordinal_t row,
203  [[maybe_unused]] KV_GO & indices,
204  [[maybe_unused]] KV_S & vals,
205  [[maybe_unused]] size_t& nnz
206  ) const {
207  TEUCHOS_TEST_FOR_EXCEPTION( true,
208  std::runtime_error,
209  "getGlobalRowCopy_kokkos_view_impl not implemented for Kokkos CrsMatrix yet. "
210  "Please contact the Amesos2 developers." );
211  }
212 
213 } // end namespace Amesos2
214 
215 #endif // AMESOS2_KOKKOS_CRSMATRIX_MATRIXADAPTER_DEF_HPP
Specialization of the ConcreteMatrixAdapter for KokkosSparse::CrsMatrix.
EDistribution
Definition: Amesos2_TypeDecl.hpp:123