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// ***********************************************************************
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
55#ifndef AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
56#define AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
57
58#include "Amesos2_config.h"
59
60#include <Teuchos_ArrayView.hpp>
61
62#include <Epetra_RowMatrix.h>
63
64#include "Amesos2_AbstractConcreteMatrixAdapter.hpp"
65#include "Amesos2_MatrixAdapter_decl.hpp"
66#include "Amesos2_MatrixTraits.hpp"
67#include "Amesos2_Util.hpp"
69
70namespace Amesos2 {
71
72 using Teuchos::RCP;
73
88 template < class DerivedMat >
89 class AbstractConcreteMatrixAdapter< Epetra_RowMatrix, DerivedMat >
90 : public MatrixAdapter< DerivedMat > {
91 public:
92 // Give our base class access to our private implementation functions
93 friend class MatrixAdapter< DerivedMat >;
94
95 typedef MatrixTraits<Epetra_RowMatrix>::scalar_t scalar_t;
96 typedef MatrixTraits<Epetra_RowMatrix>::local_ordinal_t local_ordinal_t;
97 typedef MatrixTraits<Epetra_RowMatrix>::global_ordinal_t global_ordinal_t;
98 typedef MatrixTraits<Epetra_RowMatrix>::node_t node_t;
99
100 typedef DerivedMat matrix_t;
101
102 private:
104
105 public:
106 typedef typename super_t::global_size_t global_size_t;
107
109
110 // subclasses should override these typedef's in case of specialization
113 typedef MatrixTraits<Epetra_RowMatrix>::major_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 template<typename KV_GO, typename KV_S>
131 void getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
132 KV_GO & indices,
133 KV_S & vals,
134 size_t& nnz) const;
135
136 global_size_t getGlobalNNZ_impl() const;
137
138 size_t getLocalNNZ_impl() const;
139
140 global_size_t getGlobalNumRows_impl() const;
141
142 global_size_t getGlobalNumCols_impl() const;
143
144 size_t getMaxRowNNZ_impl() const;
145
146 size_t getMaxColNNZ_impl() const;
147
148 size_t getGlobalRowNNZ_impl(global_ordinal_t row) const;
149
150 size_t getLocalRowNNZ_impl(local_ordinal_t row) const;
151
152 size_t getGlobalColNNZ_impl(global_ordinal_t col) const;
153
154 size_t getLocalColNNZ_impl(local_ordinal_t col) 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 Epetra_RowMatrix), 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 using spmtx_ptr_t = typename MatrixTraits<DerivedMat>::sparse_ptr_type;
185 using spmtx_idx_t = typename MatrixTraits<DerivedMat>::sparse_idx_type;
186 using spmtx_val_t = typename MatrixTraits<DerivedMat>::sparse_values_type;
187
188 spmtx_ptr_t getSparseRowPtr() const;
189
190 spmtx_idx_t getSparseColInd() const;
191
192 spmtx_val_t getSparseValues() const;
193
194 template<class KV>
195 void getSparseRowPtr_kokkos_view(KV & view) const {
196 Kokkos::View<spmtx_ptr_t, Kokkos::HostSpace> src(
197 getSparseRowPtr(), getGlobalNumRows_impl()+1);
198 deep_copy_or_assign_view(view, src);
199 }
200
201 template<class KV>
202 void getSparseColInd_kokkos_view(KV & view) const {
203 Kokkos::View<spmtx_idx_t, Kokkos::HostSpace> src(
204 getSparseColInd(), getGlobalNNZ_impl());
205 deep_copy_or_assign_view(view, src);
206 }
207
208 template<class KV>
209 void getSparseValues_kokkos_view(KV & view) const {
210 Kokkos::View<spmtx_val_t, Kokkos::HostSpace> src(
211 getSparseValues(), getGlobalNNZ_impl());
212 deep_copy_or_assign_view(view, src);
213 }
214
215 };
216
217} // end namespace Amesos2
218
219#endif // AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_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