Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_KokkosCrsMatrix_MatrixAdapter_decl.hpp
Go to the documentation of this file.
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 
54 #ifndef AMESOS2_KOKKOSCRSMATRIX_MATRIXADAPTER_DECL_HPP
55 #define AMESOS2_KOKKOSCRSMATRIX_MATRIXADAPTER_DECL_HPP
56 
57 #include "Amesos2_config.h"
58 
59 #include "Amesos2_MatrixAdapter_decl.hpp"
60 #include "KokkosSparse_CrsMatrix.hpp"
62 
63 namespace Amesos2 {
64 
73  template <typename Scalar,
74  typename LocalOrdinal,
75  typename ExecutionSpace>
76  class ConcreteMatrixAdapter<KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> :
77  public MatrixAdapter<KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>>
78  {
79  public:
80  typedef KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace> matrix_t;
81 
82  public:
83  typedef typename MatrixTraits<matrix_t>::scalar_t scalar_t;
84  typedef typename MatrixTraits<matrix_t>::local_ordinal_t local_ordinal_t;
85  typedef typename MatrixTraits<matrix_t>::global_ordinal_t global_ordinal_t;
86  typedef typename MatrixTraits<matrix_t>::node_t node_t;
87  typedef typename MatrixTraits<matrix_t>::global_size_t global_size_t;
88  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
89  typedef typename MatrixTraits<matrix_t>::sparse_ptr_type spmtx_ptr_t;
90  typedef typename MatrixTraits<matrix_t>::sparse_idx_type spmtx_idx_t;
91  typedef typename MatrixTraits<matrix_t>::sparse_values_type spmtx_vals_t;
92  #endif
95  typedef ConcreteMatrixAdapter<matrix_t> type;
96  typedef typename MatrixTraits<matrix_t>::major_access major_access;
97 
98  ConcreteMatrixAdapter(Teuchos::RCP<matrix_t> m);
99 
100  Teuchos::RCP<const MatrixAdapter<matrix_t> > get_impl(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution = ROOTED) const;
101 
102  const Teuchos::RCP<const Teuchos::Comm<int> > getComm_impl() const;
103  global_size_t getGlobalNumRows_impl() const;
104  global_size_t getGlobalNumCols_impl() const;
105  global_size_t getGlobalNNZ_impl() const;
106  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
107  spmtx_ptr_t getSparseRowPtr() const;
108  spmtx_idx_t getSparseColInd() const;
109  spmtx_vals_t getSparseValues() const;
110  #endif
111 
112  template<class KV>
113  void getSparseRowPtr_kokkos_view(KV & view) const {
114  deep_copy_or_assign_view(view, this->mat_->graph.row_map);
115  }
116 
117  template<class KV>
118  void getSparseColInd_kokkos_view(KV & view) const {
119  deep_copy_or_assign_view(view, this->mat_->graph.entries);
120  }
121 
122  template<class KV>
123  void getSparseValues_kokkos_view(KV & view) const {
124  deep_copy_or_assign_view(view, this->mat_->values);
125  }
126 
127  size_t getGlobalRowNNZ_impl(global_ordinal_t row) const;
128  size_t getLocalRowNNZ_impl(local_ordinal_t row) const;
129  size_t getGlobalColNNZ_impl(global_ordinal_t col) const;
130  size_t getLocalColNNZ_impl(local_ordinal_t col) const;
131 
132  global_size_t getRowIndexBase() const;
133  global_size_t getColumnIndexBase() const;
134 
135  const Teuchos::RCP<const Tpetra::Map<local_ordinal_t,
136  global_ordinal_t,
137  node_t> >
138  getMap_impl() const;
139 
140  const Teuchos::RCP<const Tpetra::Map<local_ordinal_t,
141  global_ordinal_t,
142  node_t> >
143  getRowMap_impl() const;
144 
145  const Teuchos::RCP<const Tpetra::Map<local_ordinal_t,
146  global_ordinal_t,
147  node_t> >
148  getColMap_impl() const;
149 
150  // implementation functions
151  void getGlobalRowCopy_impl(global_ordinal_t row,
152  const Teuchos::ArrayView<global_ordinal_t>& indices,
153  const Teuchos::ArrayView<scalar_t>& vals,
154  size_t& nnz) const;
155 
156  void getGlobalColCopy_impl(global_ordinal_t col,
157  const Teuchos::ArrayView<global_ordinal_t>& indices,
158  const Teuchos::ArrayView<scalar_t>& vals,
159  size_t& nnz) const;
160 
161 
162  template <typename KV_GO, typename KV_S>
163  void getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
164  KV_GO & indices,
165  KV_S & vals,
166  size_t& nnz) const;
167 
168  };
169 
170 } // end namespace Amesos2
171 
172 #endif // AMESOS2_KOKKOSCRSMATRIX_MATRIXADAPTER_DECL_HPP
Copy or assign views based on memory spaces.
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
Indicates that the concrete class can use the generic getC{c|r}s methods implemented in MatrixAdapter...
Definition: Amesos2_TypeDecl.hpp:91
Definition: Amesos2_TypeDecl.hpp:127
EDistribution
Definition: Amesos2_TypeDecl.hpp:123