Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_TpetraRowMatrix_AbstractMatrixAdapter_decl.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_TPETRAROWMATRIX_MATRIXADAPTER_DECL_HPP
12 #define AMESOS2_TPETRAROWMATRIX_MATRIXADAPTER_DECL_HPP
13 
14 #include "Amesos2_config.h"
15 
16 #include <Teuchos_ArrayView.hpp>
17 #include <Tpetra_CrsMatrix.hpp>
18 
19 #include "Amesos2_AbstractConcreteMatrixAdapter.hpp"
20 #include "Amesos2_Util.hpp"
22 
23 namespace Amesos2 {
24 
25  template <class Matrix> class MatrixAdapter;
26 
27  using Teuchos::RCP;
28 
43  template <typename Scalar,
44  typename LocalOrdinal,
45  typename GlobalOrdinal,
46  typename Node,
47  class DerivedMat >
48  class AbstractConcreteMatrixAdapter< Tpetra::RowMatrix<Scalar,
49  LocalOrdinal,
50  GlobalOrdinal,
51  Node >,
52  DerivedMat >
53  : public MatrixAdapter< DerivedMat > {
54  public:
55  // Give our base class access to our private implementation functions
56  friend class MatrixAdapter< DerivedMat >;
57 
58  typedef Tpetra::RowMatrix<Scalar,
59  LocalOrdinal,
60  GlobalOrdinal,
61  Node > matrix_t;
62 
63  typedef Scalar scalar_t;
64  typedef LocalOrdinal local_ordinal_t;
65  typedef GlobalOrdinal global_ordinal_t;
66  typedef Node node_t;
67 
68  private:
70 
71  public:
72  typedef typename super_t::global_size_t global_size_t;
73 
74  typedef AbstractConcreteMatrixAdapter<matrix_t,
75  DerivedMat> type;
76 
79  typedef row_access major_access;
80 
81  AbstractConcreteMatrixAdapter(RCP<matrix_t> m);
82 
83  public: // these functions should technically be private
84 
85  // implementation functions
86  template<typename KV_GO, typename KV_S>
87  void getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
88  KV_GO & indices,
89  KV_S & vals,
90  size_t& nnz) const;
91 
92  void getGlobalRowCopy_impl(global_ordinal_t row,
93  const Teuchos::ArrayView<global_ordinal_t>& indices,
94  const Teuchos::ArrayView<scalar_t>& vals,
95  size_t& nnz) const;
96 
97  void getGlobalColCopy_impl(global_ordinal_t col,
98  const Teuchos::ArrayView<global_ordinal_t>& indices,
99  const Teuchos::ArrayView<scalar_t>& vals,
100  size_t& nnz) const;
101 
102  global_size_t getGlobalNNZ_impl() const;
103 
104  size_t getLocalNNZ_impl() const;
105 
106  size_t getMaxRowNNZ_impl() const;
107 
108  size_t getMaxColNNZ_impl() const;
109 
110  size_t getGlobalRowNNZ_impl(global_ordinal_t row) const;
111 
112  size_t getLocalRowNNZ_impl(local_ordinal_t row) const;
113 
114  size_t getGlobalColNNZ_impl(global_ordinal_t col) const;
115 
116  size_t getLocalColNNZ_impl(local_ordinal_t col) const;
117 
118  global_size_t getGlobalNumRows_impl() const;
119 
120  global_size_t getGlobalNumCols_impl() const;
121 
122  // Brunt of the work is put on the implementation for converting
123  // their maps to a Tpetra::Map
124  const RCP<const Tpetra::Map<local_ordinal_t,
125  global_ordinal_t,
126  node_t> >
127  getMap_impl() const;
128 
129  const RCP<const Tpetra::Map<local_ordinal_t,
130  global_ordinal_t,
131  node_t> >
132  getRowMap_impl() const;
133 
134  const RCP<const Tpetra::Map<local_ordinal_t,
135  global_ordinal_t,
136  node_t> >
137  getColMap_impl() const;
138 
139  const RCP<const Teuchos::Comm<int> > getComm_impl() const;
140 
141  bool isLocallyIndexed_impl() const;
142 
143  bool isGloballyIndexed_impl() const;
144 
145  // Because instantiation of the subclasses could be wildly
146  // different (cf subclasses of Tpetra::CrsMatrix), this method
147  // hands off implementation to the adapter for the subclass
148  RCP<const super_t> get_impl(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution = ROOTED) const;
149 
150  template<class KV>
151  void getSparseRowPtr_kokkos_view(KV & view) const {
152  deep_copy_or_assign_view(view, this->mat_->getLocalMatrixDevice().graph.row_map);
153  }
154 
155  template<class KV>
156  void getSparseColInd_kokkos_view(KV & view) const {
157  deep_copy_or_assign_view(view, this->mat_->getLocalMatrixDevice().graph.entries);
158  }
159 
160  template<class KV>
161  void getSparseValues_kokkos_view(KV & view) const {
162  deep_copy_or_assign_view(view, this->mat_->getLocalMatrixDevice().values);
163  }
164 
165  };
166 
167 } // end namespace Amesos2
168 
169 #endif // AMESOS2_TPETRAROWMATRIX_MATRIXADAPTER_DECL_HPP
Utility functions for Amesos2.
Copy or assign views based on memory spaces.
Indicates that the object of an adapter provides row access to its data.
Definition: Amesos2_TypeDecl.hpp:66
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:42
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:55
Indicates that the concrete class can use the generic getC{c|r}s methods implemented in MatrixAdapter...
Definition: Amesos2_TypeDecl.hpp:57
EDistribution
Definition: Amesos2_TypeDecl.hpp:89