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
36namespace 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 typedef Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> map_t;
68
69 private:
71
72 public:
73 typedef typename super_t::global_size_t global_size_t;
74
76
77 // subclasses should override these typedef's in case of specialization
80 typedef MatrixTraits<Epetra_RowMatrix>::major_access major_access;
81
82 AbstractConcreteMatrixAdapter(RCP<matrix_t> m);
83
84 public: // these functions should technically be private
85
86 // implementation functions
87 void getGlobalRowCopy_impl(global_ordinal_t row,
88 const Teuchos::ArrayView<global_ordinal_t>& indices,
89 const Teuchos::ArrayView<scalar_t>& vals,
90 size_t& nnz) const;
91
92 void getGlobalColCopy_impl(global_ordinal_t col,
93 const Teuchos::ArrayView<global_ordinal_t>& indices,
94 const Teuchos::ArrayView<scalar_t>& vals,
95 size_t& nnz) const;
96
97 template<typename KV_GO, typename KV_S>
98 void getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
99 KV_GO & indices,
100 KV_S & vals,
101 size_t& nnz) const;
102
103 global_size_t getGlobalNNZ_impl() const;
104
105 size_t getLocalNNZ_impl() const;
106
107 global_size_t getGlobalNumRows_impl() const;
108
109 global_size_t getGlobalNumCols_impl() const;
110
111 size_t getMaxRowNNZ_impl() const;
112
113 size_t getMaxColNNZ_impl() const;
114
115 size_t getGlobalRowNNZ_impl(global_ordinal_t row) const;
116
117 size_t getLocalRowNNZ_impl(local_ordinal_t row) const;
118
119 size_t getGlobalColNNZ_impl(global_ordinal_t col) const;
120
121 size_t getLocalColNNZ_impl(local_ordinal_t col) const;
122
123 // Brunt of the work is put on the implementation for converting
124 // their maps to a Tpetra::Map
125 const RCP<const map_t>
126 getMap_impl() const;
127
128 const RCP<const map_t>
129 getRowMap_impl() const;
130
131 const RCP<const map_t>
132 getColMap_impl() const;
133
134 const RCP<const Teuchos::Comm<int> > getComm_impl() const;
135
136 bool isLocallyIndexed_impl() const;
137
138 bool isGloballyIndexed_impl() const;
139
140 // Because instantiation of the subclasses could be wildly
141 // different (cf subclasses of Epetra_RowMatrix), this method
142 // hands off implementation to the adapter for the subclass
143 RCP<const super_t> get_impl(const Teuchos::Ptr<const map_t> map, EDistribution distribution = ROOTED) const;
144 RCP<const super_t> reindex_impl(Teuchos::RCP<const map_t> &contigRowMap,
145 Teuchos::RCP<const map_t> &contigColMap,
146 const EPhase current_phase) const;
147 template<typename KV_S, typename KV_GO, typename KV_GS, typename host_ordinal_type_array, typename host_scalar_type_array>
148 local_ordinal_t gather_impl(KV_S& nzvals, KV_GO& indices, KV_GS& pointers,
149 host_ordinal_type_array &perm_g2l,
150 host_ordinal_type_array &recvCountRows, host_ordinal_type_array &recvDisplRows,
151 host_ordinal_type_array &recvCounts, host_ordinal_type_array &recvDispls,
152 host_ordinal_type_array &transpose_map, host_scalar_type_array &nzvals_t,
153 bool column_major, EPhase current_phase) const;
154
155 using spmtx_ptr_t = typename MatrixTraits<DerivedMat>::sparse_ptr_type;
156 using spmtx_idx_t = typename MatrixTraits<DerivedMat>::sparse_idx_type;
157 using spmtx_val_t = typename MatrixTraits<DerivedMat>::sparse_values_type;
158
159 spmtx_ptr_t getSparseRowPtr() const;
160
161 spmtx_idx_t getSparseColInd() const;
162
163 spmtx_val_t getSparseValues() const;
164
165 template<class KV>
166 void getSparseRowPtr_kokkos_view(KV & view) const {
167 Kokkos::View<spmtx_ptr_t, Kokkos::HostSpace> src(
168 getSparseRowPtr(), getGlobalNumRows_impl()+1);
169 deep_copy_or_assign_view(view, src);
170 }
171
172 template<class KV>
173 void getSparseColInd_kokkos_view(KV & view) const {
174 Kokkos::View<spmtx_idx_t, Kokkos::HostSpace> src(
175 getSparseColInd(), getGlobalNNZ_impl());
176 deep_copy_or_assign_view(view, src);
177 }
178
179 template<class KV>
180 void getSparseValues_kokkos_view(KV & view) const {
181 Kokkos::View<spmtx_val_t, Kokkos::HostSpace> src(
182 getSparseValues(), getGlobalNNZ_impl());
183 deep_copy_or_assign_view(view, src);
184 }
185
186 };
187
188} // end namespace Amesos2
189
190#endif // AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
Copy or assign views based on memory spaces.
EDistribution
Definition Amesos2_TypeDecl.hpp:89
@ ROOTED
Definition Amesos2_TypeDecl.hpp:93
Utility functions for Amesos2.
Definition Amesos2_AbstractConcreteMatrixAdapter.hpp:55
A Matrix adapter interface for Amesos2.
Definition Amesos2_MatrixAdapter_decl.hpp:42
EPhase
Used to indicate a phase in the direct solution.
Definition Amesos2_TypeDecl.hpp:31
Indicates that the concrete class can use the generic getC{c|r}s methods implemented in MatrixAdapter...
Definition Amesos2_TypeDecl.hpp:57