Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_TpetraRowMatrix_AbstractMatrixAdapter_decl.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_TPETRAROWMATRIX_MATRIXADAPTER_DECL_HPP
46 #define AMESOS2_TPETRAROWMATRIX_MATRIXADAPTER_DECL_HPP
47 
48 #include "Amesos2_config.h"
49 
50 #include <Teuchos_ArrayView.hpp>
51 #include <Tpetra_CrsMatrix.hpp>
52 
53 #include "Amesos2_AbstractConcreteMatrixAdapter.hpp"
54 #include "Amesos2_Util.hpp"
56 
57 namespace Amesos2 {
58 
59  template <class Matrix> class MatrixAdapter;
60 
61  using Teuchos::RCP;
62 
77  template <typename Scalar,
78  typename LocalOrdinal,
79  typename GlobalOrdinal,
80  typename Node,
81  class DerivedMat >
82  class AbstractConcreteMatrixAdapter< Tpetra::RowMatrix<Scalar,
83  LocalOrdinal,
84  GlobalOrdinal,
85  Node >,
86  DerivedMat >
87  : public MatrixAdapter< DerivedMat > {
88  public:
89  // Give our base class access to our private implementation functions
90  friend class MatrixAdapter< DerivedMat >;
91 
92  typedef Tpetra::RowMatrix<Scalar,
93  LocalOrdinal,
94  GlobalOrdinal,
95  Node > matrix_t;
96 
97  typedef Scalar scalar_t;
98  typedef LocalOrdinal local_ordinal_t;
99  typedef GlobalOrdinal global_ordinal_t;
100  typedef Node node_t;
101 
102  private:
104 
105  public:
106  typedef typename super_t::global_size_t global_size_t;
107 
108  typedef AbstractConcreteMatrixAdapter<matrix_t,
109  DerivedMat> type;
110 
113  typedef row_access major_access;
114 
115  AbstractConcreteMatrixAdapter(RCP<matrix_t> m);
116 
117  public: // these functions should technically be private
118 
119  // implementation functions
120  void getGlobalRowCopy_impl(global_ordinal_t row,
121  const Teuchos::ArrayView<global_ordinal_t>& indices,
122  const Teuchos::ArrayView<scalar_t>& vals,
123  size_t& nnz) const;
124 
125  void getGlobalColCopy_impl(global_ordinal_t col,
126  const Teuchos::ArrayView<global_ordinal_t>& indices,
127  const Teuchos::ArrayView<scalar_t>& vals,
128  size_t& nnz) const;
129 
130  global_size_t getGlobalNNZ_impl() const;
131 
132  size_t getLocalNNZ_impl() const;
133 
134  size_t getMaxRowNNZ_impl() const;
135 
136  size_t getMaxColNNZ_impl() const;
137 
138  size_t getGlobalRowNNZ_impl(global_ordinal_t row) const;
139 
140  size_t getLocalRowNNZ_impl(local_ordinal_t row) const;
141 
142  size_t getGlobalColNNZ_impl(global_ordinal_t col) const;
143 
144  size_t getLocalColNNZ_impl(local_ordinal_t col) const;
145 
146  global_size_t getGlobalNumRows_impl() const;
147 
148  global_size_t getGlobalNumCols_impl() const;
149 
150  // Brunt of the work is put on the implementation for converting
151  // their maps to a Tpetra::Map
152  const RCP<const Tpetra::Map<local_ordinal_t,
153  global_ordinal_t,
154  node_t> >
155  getMap_impl() const;
156 
157  const RCP<const Tpetra::Map<local_ordinal_t,
158  global_ordinal_t,
159  node_t> >
160  getRowMap_impl() const;
161 
162  const RCP<const Tpetra::Map<local_ordinal_t,
163  global_ordinal_t,
164  node_t> >
165  getColMap_impl() const;
166 
167  const RCP<const Teuchos::Comm<int> > getComm_impl() const;
168 
169  bool isLocallyIndexed_impl() const;
170 
171  bool isGloballyIndexed_impl() const;
172 
173  // Because instantiation of the subclasses could be wildly
174  // different (cf subclasses of Tpetra::CrsMatrix), this method
175  // hands off implementation to the adapter for the subclass
176  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;
177 
178  typename super_t::spmtx_ptr_t getSparseRowPtr() const;
179 
180  typename super_t::spmtx_idx_t getSparseColInd() const;
181 
182  typename super_t::spmtx_vals_t getSparseValues() const;
183 
184  template<class KV>
185  void getSparseRowPtr_kokkos_view(KV & view) const {
186  deep_copy_or_assign_view(view, this->mat_->getLocalMatrix().graph.row_map);
187  }
188 
189  template<class KV>
190  void getSparseColInd_kokkos_view(KV & view) const {
191  deep_copy_or_assign_view(view, this->mat_->getLocalMatrix().graph.entries);
192  }
193 
194  template<class KV>
195  void getSparseValues_kokkos_view(KV & view) const {
196  deep_copy_or_assign_view(view, this->mat_->getLocalMatrix().values);
197  }
198 
199  };
200 
201 } // end namespace Amesos2
202 
203 #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:100
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:89
Indicates that the concrete class can use the generic getC{c|r}s methods implemented in MatrixAdapter...
Definition: Amesos2_TypeDecl.hpp:91
EDistribution
Definition: Amesos2_TypeDecl.hpp:123