Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_MatrixAdapter_decl.hpp
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 
11 #ifndef AMESOS2_MATRIXADAPTER_DECL_HPP
12 #define AMESOS2_MATRIXADAPTER_DECL_HPP
13 
14 #include "Amesos2_config.h"
15 
16 #include <Teuchos_Comm.hpp>
17 #include <Teuchos_ArrayView.hpp>
18 #include <Teuchos_VerbosityLevel.hpp>
19 #include <Teuchos_FancyOStream.hpp>
20 
21 #include <Tpetra_ConfigDefs.hpp> // for global_size_t
22 
23 // #include "Amesos2_ConcreteMatrixAdapter_decl.hpp"
24 #include "Amesos2_Util.hpp"
25 #include "Amesos2_MatrixTraits.hpp"
26 
27 namespace Amesos2 {
28 
29  template <class M> class ConcreteMatrixAdapter;
30 
41  template < class Matrix >
42  class MatrixAdapter {
43 
44  public:
45 
46  typedef typename MatrixTraits<Matrix>::scalar_t scalar_t;
47  typedef typename MatrixTraits<Matrix>::local_ordinal_t local_ordinal_t;
48  typedef typename MatrixTraits<Matrix>::global_ordinal_t global_ordinal_t;
49  typedef typename MatrixTraits<Matrix>::node_t node_t;
50  typedef Tpetra::global_size_t global_size_t;
51 
52  typedef Matrix matrix_t;
54  typedef ConcreteMatrixAdapter<Matrix> adapter_t;
55 
56  typedef typename MatrixTraits<Matrix>::global_host_idx_type global_host_idx_t;
57  typedef typename MatrixTraits<Matrix>::global_host_val_type global_host_val_t;
58 
59  // template<typename S, typename GO, typename GS, typename Op>
60  // friend class Util::get_cxs_helper<MatrixAdapter<Matrix>,S,GO,GS,Op>;
61  // template<class M, typename S, typename GO, typename GS, typename Op>
62  // friend class Util::get_cxs_helper;
63 
64  MatrixAdapter(Teuchos::RCP<Matrix> m);
65 
66 
98  template<typename KV_S, typename KV_GO, typename KV_GS>
99  void getCrs_kokkos_view(KV_S & nzval,
100  KV_GO & colind,
101  KV_GS & rowptr,
102  global_size_t& nnz,
103  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
104  EStorage_Ordering ordering=ARBITRARY,
105  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
106 
107 
113  template<typename KV_S, typename KV_GO, typename KV_GS>
114  void getCrs_kokkos_view(KV_S & nzval,
115  KV_GO & colind,
116  KV_GS & rowptr,
117  global_size_t& nnz,
118  EDistribution distribution=ROOTED,
119  EStorage_Ordering ordering=ARBITRARY) const; // This was placed as last argument to preserve API
120 
149  template<typename KV_S, typename KV_GO, typename KV_GS>
150  void getCcs_kokkos_view(KV_S & nzval,
151  KV_GO & rowind,
152  KV_GS & colptr,
153  global_size_t& nnz,
154  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
155  EStorage_Ordering ordering=ARBITRARY,
156  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
157 
163  template<typename KV_S, typename KV_GO, typename KV_GS>
164  void getCcs_kokkos_view(KV_S & nzval,
165  KV_GO & rowind,
166  KV_GS & colptr,
167  global_size_t& nnz,
168  EDistribution distribution=ROOTED,
169  EStorage_Ordering ordering=ARBITRARY) const; // This was placed as last argument to preserve API
170 
171 
173  const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
174  {
175  return comm_;
176  }
177 
179  global_size_t getGlobalNumRows() const;
180 
182  global_size_t getGlobalNumCols() const;
183 
185  global_size_t getRowIndexBase() const;
186 
188  global_size_t getColumnIndexBase() const;
189 
191  global_size_t getGlobalNNZ() const;
192 
194  size_t getLocalNumRows() const;
195 
197  size_t getLocalNumCols() const;
198 
200  size_t getLocalNNZ() const;
201 
202  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
203  getMap() const {
204  return static_cast<const adapter_t*>(this)->getMap_impl();
205  }
206 
207  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
208  getRowMap() const {
209  return row_map_;
210  }
211 
212  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
213  getColMap() const {
214  return col_map_;
215  }
216 
217  Teuchos::RCP<const type> get(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution = ROOTED) const;
218 
220  std::string description() const;
221 
223  void describe(Teuchos::FancyOStream &out,
224  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
225 
227  template<typename KV>
228  void returnRowPtr_kokkos_view(KV & view) const;
229 
231  template<typename KV>
232  void returnColInd_kokkos_view(KV & view) const;
233 
235  template<typename KV>
236  void returnValues_kokkos_view(KV & view) const;
237 
238 
239  private:
240  template<typename KV_S, typename KV_GO, typename KV_GS>
241  void help_getCrs_kokkos_view(KV_S & nzval,
242  KV_GO & colind,
243  KV_GS & rowptr,
244  global_size_t& nnz,
245  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
246  EDistribution distribution,
247  EStorage_Ordering ordering,
248  no_special_impl nsi) const;
249 
250  template<typename KV_S, typename KV_GO, typename KV_GS>
251  void do_getCrs_kokkos_view(KV_S & nzval,
252  KV_GO & colind,
253  KV_GS & rowptr,
254  global_size_t& nnz,
255  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
256  EDistribution distribution,
257  EStorage_Ordering ordering,
258  row_access ra) const;
259 
260  template<typename KV_S, typename KV_GO, typename KV_GS>
261  void help_getCcs_kokkos_view(KV_S & nzval,
262  KV_GO & colind,
263  KV_GS & rowptr,
264  global_size_t& nnz,
265  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
266  EDistribution distribution,
267  EStorage_Ordering ordering,
268  no_special_impl nsi) const;
269 
270  template<typename KV_S, typename KV_GO, typename KV_GS>
271  void do_getCcs_kokkos_view(KV_S & nzval,
272  KV_GO & rowind,
273  KV_GS & colptr,
274  global_size_t& nnz,
275  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
276  EDistribution distribution,
277  EStorage_Ordering ordering,
278  row_access ra) const;
279 
280  protected:
281  // These methods will link to concrete implementations, and may
282  // also be used by them
283 
290  template<typename KV_GO, typename KV_S>
291  void getGlobalRowCopy_kokkos_view(global_ordinal_t row,
292  KV_GO & indices,
293  KV_S & vals,
294  size_t& nnz) const;
295 
296  size_t getMaxRowNNZ() const;
297 
298  size_t getMaxColNNZ() const;
299 
300  size_t getGlobalRowNNZ(global_ordinal_t row) const;
301 
302  size_t getLocalRowNNZ(local_ordinal_t row) const;
303 
304  size_t getGlobalColNNZ(global_ordinal_t col) const;
305 
306  size_t getLocalColNNZ(local_ordinal_t col) const;
307 
308  bool isLocallyIndexed() const;
309 
310  bool isGloballyIndexed() const;
311 
312  protected:
313  const Teuchos::RCP<const Matrix> mat_;
314 
315  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > row_map_;
316 
317  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > col_map_;
318 
319  mutable Teuchos::RCP<const Teuchos::Comm<int> > comm_;
320  }; // end class MatrixAdapter
321 
322 
323  // Factory creation method
324  template <class Matrix>
325  Teuchos::RCP<MatrixAdapter<Matrix> >
326  createMatrixAdapter(Teuchos::RCP<Matrix> m);
327 
328  template <class Matrix>
329  Teuchos::RCP<const MatrixAdapter<Matrix> >
330  createConstMatrixAdapter(Teuchos::RCP<const Matrix> m);
331 
332 } // end namespace Amesos2
333 
334 #endif // AMESOS2_MATRIXADAPTER_DECL_HPP
global_size_t getGlobalNumRows() const
Get the number of rows in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:106
void getCcs_kokkos_view(KV_S &nzval, KV_GO &rowind, KV_GS &colptr, global_size_t &nnz, const Teuchos::Ptr< const Tpetra::Map< local_ordinal_t, global_ordinal_t, node_t > > colmap, EStorage_Ordering ordering=ARBITRARY, EDistribution distribution=ROOTED) const
Gets a compressed-column storage summary of this.
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this matrix.
Definition: Amesos2_MatrixAdapter_decl.hpp:173
void returnRowPtr_kokkos_view(KV &view) const
Return kokkos view of CRS row pointer of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:183
global_size_t getGlobalNNZ() const
Get the global number of non-zeros in this sparse matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:138
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describes of this matrix adapter with some level of verbosity.
Definition: Amesos2_MatrixAdapter_def.hpp:177
size_t getLocalNumRows() const
Get the number of rows local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:145
void getGlobalRowCopy_kokkos_view(global_ordinal_t row, KV_GO &indices, KV_S &vals, size_t &nnz) const
Definition: Amesos2_MatrixAdapter_def.hpp:441
Utility functions for Amesos2.
EStorage_Ordering
Definition: Amesos2_TypeDecl.hpp:107
size_t getLocalNumCols() const
Get the number of columns local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:152
size_t getLocalNNZ() const
Get the local number of non-zeros on this processor.
Definition: Amesos2_MatrixAdapter_def.hpp:159
void getCrs_kokkos_view(KV_S &nzval, KV_GO &colind, KV_GS &rowptr, global_size_t &nnz, const Teuchos::Ptr< const Tpetra::Map< local_ordinal_t, global_ordinal_t, node_t > > rowmap, EStorage_Ordering ordering=ARBITRARY, EDistribution distribution=ROOTED) const
Gets a compressed-row storage summary of this.
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_MatrixAdapter_def.hpp:167
global_size_t getColumnIndexBase() const
Get the indexbase for the column map.
Definition: Amesos2_MatrixAdapter_def.hpp:129
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:42
global_size_t getGlobalNumCols() const
Get the number of columns in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:113
void returnColInd_kokkos_view(KV &view) const
Return kokkos view of CRS column indices of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:190
global_size_t getRowIndexBase() const
Get the indexbase for the row map.
Definition: Amesos2_MatrixAdapter_def.hpp:120
EDistribution
Definition: Amesos2_TypeDecl.hpp:89
void returnValues_kokkos_view(KV &view) const
Return kokkos view of CRS values of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:197