Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_EpetraRowMatrix_AbstractMatrixAdapter_decl.hpp
Go to the documentation of this file.
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 
21 #ifndef AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
22 #define AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
23 
24 #include "Amesos2_config.h"
25 
26 #include <Teuchos_ArrayView.hpp>
27 
28 #include <Epetra_RowMatrix.h>
29 
30 #include "Amesos2_AbstractConcreteMatrixAdapter.hpp"
31 #include "Amesos2_MatrixAdapter_decl.hpp"
32 #include "Amesos2_MatrixTraits.hpp"
33 #include "Amesos2_Util.hpp"
35 
36 namespace Amesos2 {
37 
38  using Teuchos::RCP;
39 
54  template < class DerivedMat >
55  class AbstractConcreteMatrixAdapter< Epetra_RowMatrix, DerivedMat >
56  : public MatrixAdapter< DerivedMat > {
57  public:
58  // Give our base class access to our private implementation functions
59  friend class MatrixAdapter< DerivedMat >;
60 
61  typedef MatrixTraits<Epetra_RowMatrix>::scalar_t scalar_t;
62  typedef MatrixTraits<Epetra_RowMatrix>::local_ordinal_t local_ordinal_t;
63  typedef MatrixTraits<Epetra_RowMatrix>::global_ordinal_t global_ordinal_t;
64  typedef MatrixTraits<Epetra_RowMatrix>::node_t node_t;
65 
66  typedef DerivedMat matrix_t;
67 
68  private:
70 
71  public:
72  typedef typename super_t::global_size_t global_size_t;
73 
75 
76  // subclasses should override these typedef's in case of specialization
79  typedef MatrixTraits<Epetra_RowMatrix>::major_access major_access;
80 
81  AbstractConcreteMatrixAdapter(RCP<matrix_t> m);
82 
83  public: // these functions should technically be private
84 
85  // implementation functions
86  void getGlobalRowCopy_impl(global_ordinal_t row,
87  const Teuchos::ArrayView<global_ordinal_t>& indices,
88  const Teuchos::ArrayView<scalar_t>& vals,
89  size_t& nnz) const;
90 
91  void getGlobalColCopy_impl(global_ordinal_t col,
92  const Teuchos::ArrayView<global_ordinal_t>& indices,
93  const Teuchos::ArrayView<scalar_t>& vals,
94  size_t& nnz) const;
95 
96  template<typename KV_GO, typename KV_S>
97  void getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
98  KV_GO & indices,
99  KV_S & vals,
100  size_t& nnz) const;
101 
102  global_size_t getGlobalNNZ_impl() const;
103 
104  size_t getLocalNNZ_impl() const;
105 
106  global_size_t getGlobalNumRows_impl() const;
107 
108  global_size_t getGlobalNumCols_impl() const;
109 
110  size_t getMaxRowNNZ_impl() const;
111 
112  size_t getMaxColNNZ_impl() const;
113 
114  size_t getGlobalRowNNZ_impl(global_ordinal_t row) const;
115 
116  size_t getLocalRowNNZ_impl(local_ordinal_t row) const;
117 
118  size_t getGlobalColNNZ_impl(global_ordinal_t col) const;
119 
120  size_t getLocalColNNZ_impl(local_ordinal_t col) 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 Epetra_RowMatrix), 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  using spmtx_ptr_t = typename MatrixTraits<DerivedMat>::sparse_ptr_type;
151  using spmtx_idx_t = typename MatrixTraits<DerivedMat>::sparse_idx_type;
152  using spmtx_val_t = typename MatrixTraits<DerivedMat>::sparse_values_type;
153 
154  spmtx_ptr_t getSparseRowPtr() const;
155 
156  spmtx_idx_t getSparseColInd() const;
157 
158  spmtx_val_t getSparseValues() const;
159 
160  template<class KV>
161  void getSparseRowPtr_kokkos_view(KV & view) const {
162  Kokkos::View<spmtx_ptr_t, Kokkos::HostSpace> src(
163  getSparseRowPtr(), getGlobalNumRows_impl()+1);
164  deep_copy_or_assign_view(view, src);
165  }
166 
167  template<class KV>
168  void getSparseColInd_kokkos_view(KV & view) const {
169  Kokkos::View<spmtx_idx_t, Kokkos::HostSpace> src(
170  getSparseColInd(), getGlobalNNZ_impl());
171  deep_copy_or_assign_view(view, src);
172  }
173 
174  template<class KV>
175  void getSparseValues_kokkos_view(KV & view) const {
176  Kokkos::View<spmtx_val_t, Kokkos::HostSpace> src(
177  getSparseValues(), getGlobalNNZ_impl());
178  deep_copy_or_assign_view(view, src);
179  }
180 
181  };
182 
183 } // end namespace Amesos2
184 
185 #endif // AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
Utility functions for Amesos2.
Copy or assign views based on memory spaces.
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