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(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution) const
106  {
107  TEUCHOS_TEST_FOR_EXCEPTION( true,
108  std::runtime_error,
109  "get_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
110  "Please contact the Amesos2 developers." );
111  }
112 
113  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
114  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
115  ConcreteMatrixAdapter<
116  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNumRows_impl() const
117  {
118  return this->mat_->numRows();
119  }
120 
121  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
122  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
123  ConcreteMatrixAdapter<
124  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNumCols_impl() const
125  {
126  return this->mat_->numCols();
127  }
128 
129  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
130  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_size_t
131  ConcreteMatrixAdapter<
132  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalNNZ_impl() const
133  {
134  return this->mat_->nnz();
135  }
136 
137  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
138  const Teuchos::RCP<const Tpetra::Map<typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::local_ordinal_t,
139  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::global_ordinal_t,
140  typename MatrixTraits<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::node_t> >
141  ConcreteMatrixAdapter<
142  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getMap_impl() const
143  {
144  return( Teuchos::null );
145  }
146 
147  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
148  size_t
149  ConcreteMatrixAdapter<
150  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalRowNNZ_impl(global_ordinal_t row) const
151  {
152  TEUCHOS_TEST_FOR_EXCEPTION( true,
153  std::runtime_error,
154  "getGlobalRowNNZ_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
155  "Please contact the Amesos2 developers." );
156  }
157 
158  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
159  size_t
160  ConcreteMatrixAdapter<
161  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getLocalRowNNZ_impl(local_ordinal_t row) const
162  {
163  TEUCHOS_TEST_FOR_EXCEPTION( true,
164  std::runtime_error,
165  "getLocalRowNNZ_impl() not implemented for the Kokkos CrsMatrix adapter yet. "
166  "Please contact the Amesos2 developers." );
167  }
168 
169  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
170  size_t
171  ConcreteMatrixAdapter<
172  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalColNNZ_impl(global_ordinal_t col) const
173  {
174  TEUCHOS_TEST_FOR_EXCEPTION( true,
175  std::runtime_error,
176  "Column access to row-based object not yet supported. "
177  "Please contact the Amesos2 developers." );
178  }
179 
180  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
181  size_t
182  ConcreteMatrixAdapter<
183  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getLocalColNNZ_impl(local_ordinal_t col) const
184  {
185  TEUCHOS_TEST_FOR_EXCEPTION( true,
186  std::runtime_error,
187  "Column access to row-based object not yet supported. "
188  "Please contact the Amesos2 developers." );
189  }
190 
191  // implementation functions
192  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
193  void
194  ConcreteMatrixAdapter<
195  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalRowCopy_impl(global_ordinal_t row,
196  const ArrayView<global_ordinal_t>& indices,
197  const ArrayView<scalar_t>& vals,
198  size_t& nnz) const
199  {
200  TEUCHOS_TEST_FOR_EXCEPTION( true,
201  std::runtime_error,
202  "getGlobalRowCopy_impl not implemented for Kokkos CrsMatrix yet. "
203  "Please contact the Amesos2 developers." );
204  }
205 
206  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
207  void
208  ConcreteMatrixAdapter<
209  KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getGlobalColCopy_impl(global_ordinal_t col,
210  const ArrayView<global_ordinal_t>& indices,
211  const ArrayView<scalar_t>& vals,
212  size_t& nnz) const
213  {
214  TEUCHOS_TEST_FOR_EXCEPTION( true,
215  std::runtime_error,
216  "Column access to row-based object not yet supported. "
217  "Please contact the Amesos2 developers." );
218  }
219 
220  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
221  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::spmtx_ptr_t
222  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getSparseRowPtr() const
223  {
224  return this->mat_->graph.row_map.data();
225  }
226 
227  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
228  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::spmtx_idx_t
229  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getSparseColInd() const
230  {
231  return this->mat_->graph.entries.data();
232  }
233 
234  template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
235  typename ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::spmtx_vals_t
236  ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar,LocalOrdinal,ExecutionSpace>>::getSparseValues() const
237  {
238  return this->mat_->values.data();
239  }
240 
241 } // end namespace Amesos2
242 
243 #endif // AMESOS2_KOKKOS_CRSMATRIX_MATRIXADAPTER_DEF_HPP
Specialization of the ConcreteMatrixAdapter for KokkosSparse::CrsMatrix.
EDistribution
Definition: Amesos2_TypeDecl.hpp:123