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
57namespace 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 template<typename KV_GO, typename KV_S>
121 void getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
122 KV_GO & indices,
123 KV_S & vals,
124 size_t& nnz) const;
125
126 void getGlobalRowCopy_impl(global_ordinal_t row,
127 const Teuchos::ArrayView<global_ordinal_t>& indices,
128 const Teuchos::ArrayView<scalar_t>& vals,
129 size_t& nnz) const;
130
131 void getGlobalColCopy_impl(global_ordinal_t col,
132 const Teuchos::ArrayView<global_ordinal_t>& indices,
133 const Teuchos::ArrayView<scalar_t>& vals,
134 size_t& nnz) const;
135
136 global_size_t getGlobalNNZ_impl() const;
137
138 size_t getLocalNNZ_impl() const;
139
140 size_t getMaxRowNNZ_impl() const;
141
142 size_t getMaxColNNZ_impl() const;
143
144 size_t getGlobalRowNNZ_impl(global_ordinal_t row) const;
145
146 size_t getLocalRowNNZ_impl(local_ordinal_t row) const;
147
148 size_t getGlobalColNNZ_impl(global_ordinal_t col) const;
149
150 size_t getLocalColNNZ_impl(local_ordinal_t col) const;
151
152 global_size_t getGlobalNumRows_impl() const;
153
154 global_size_t getGlobalNumCols_impl() const;
155
156 // Brunt of the work is put on the implementation for converting
157 // their maps to a Tpetra::Map
158 const RCP<const Tpetra::Map<local_ordinal_t,
159 global_ordinal_t,
160 node_t> >
161 getMap_impl() const;
162
163 const RCP<const Tpetra::Map<local_ordinal_t,
164 global_ordinal_t,
165 node_t> >
166 getRowMap_impl() const;
167
168 const RCP<const Tpetra::Map<local_ordinal_t,
169 global_ordinal_t,
170 node_t> >
171 getColMap_impl() const;
172
173 const RCP<const Teuchos::Comm<int> > getComm_impl() const;
174
175 bool isLocallyIndexed_impl() const;
176
177 bool isGloballyIndexed_impl() const;
178
179 // Because instantiation of the subclasses could be wildly
180 // different (cf subclasses of Tpetra::CrsMatrix), this method
181 // hands off implementation to the adapter for the subclass
182 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;
183
184 template<class KV>
185 void getSparseRowPtr_kokkos_view(KV & view) const {
186 deep_copy_or_assign_view(view, this->mat_->getLocalMatrixDevice().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_->getLocalMatrixDevice().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_->getLocalMatrixDevice().values);
197 }
198
199 };
200
201} // end namespace Amesos2
202
203#endif // AMESOS2_TPETRAROWMATRIX_MATRIXADAPTER_DECL_HPP
Copy or assign views based on memory spaces.
@ ROOTED
Definition Amesos2_TypeDecl.hpp:127
Utility functions for Amesos2.
Definition Amesos2_AbstractConcreteMatrixAdapter.hpp:89
A Matrix adapter interface for Amesos2.
Definition Amesos2_MatrixAdapter_decl.hpp:76
EDistribution
Definition Amesos2_TypeDecl.hpp:123
Indicates that the concrete class can use the generic getC{c|r}s methods implemented in MatrixAdapter...
Definition Amesos2_TypeDecl.hpp:91
Indicates that the object of an adapter provides row access to its data.
Definition Amesos2_TypeDecl.hpp:100