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  typedef Tpetra::Map<local_ordinal_t, global_ordinal_t, node_t> map_t;
56 
57  typedef typename MatrixTraits<Matrix>::global_host_idx_type global_host_idx_t;
58  typedef typename MatrixTraits<Matrix>::global_host_val_type global_host_val_t;
59 
60  // template<typename S, typename GO, typename GS, typename Op>
61  // friend class Util::get_cxs_helper<MatrixAdapter<Matrix>,S,GO,GS,Op>;
62  // template<class M, typename S, typename GO, typename GS, typename Op>
63  // friend class Util::get_cxs_helper;
64 
65  MatrixAdapter(Teuchos::RCP<Matrix> m);
66 
67 
99  template<typename KV_S, typename KV_GO, typename KV_GS>
100  void getCrs_kokkos_view(KV_S & nzval,
101  KV_GO & colind,
102  KV_GS & rowptr,
103  global_size_t& nnz,
104  const Teuchos::Ptr<const map_t> rowmap,
105  EStorage_Ordering ordering=ARBITRARY,
106  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
107 
108 
114  template<typename KV_S, typename KV_GO, typename KV_GS>
115  void getCrs_kokkos_view(KV_S & nzval,
116  KV_GO & colind,
117  KV_GS & rowptr,
118  global_size_t& nnz,
119  EDistribution distribution=ROOTED,
120  EStorage_Ordering ordering=ARBITRARY) const; // This was placed as last argument to preserve API
121 
150  template<typename KV_S, typename KV_GO, typename KV_GS>
151  void getCcs_kokkos_view(KV_S & nzval,
152  KV_GO & rowind,
153  KV_GS & colptr,
154  global_size_t& nnz,
155  const Teuchos::Ptr<const map_t> colmap,
156  EStorage_Ordering ordering=ARBITRARY,
157  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
158 
164  template<typename KV_S, typename KV_GO, typename KV_GS>
165  void getCcs_kokkos_view(KV_S & nzval,
166  KV_GO & rowind,
167  KV_GS & colptr,
168  global_size_t& nnz,
169  EDistribution distribution=ROOTED,
170  EStorage_Ordering ordering=ARBITRARY) const; // This was placed as last argument to preserve API
171 
172 
174  const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
175  {
176  return comm_;
177  }
178 
180  global_size_t getGlobalNumRows() const;
181 
183  global_size_t getGlobalNumCols() const;
184 
186  global_size_t getRowIndexBase() const;
187 
189  global_size_t getColumnIndexBase() const;
190 
192  global_size_t getGlobalNNZ() const;
193 
195  size_t getLocalNumRows() const;
196 
198  size_t getLocalNumCols() const;
199 
201  size_t getLocalNNZ() const;
202 
203  Teuchos::RCP<const map_t>
204  getMap() const {
205  return static_cast<const adapter_t*>(this)->getMap_impl();
206  }
207 
208  Teuchos::RCP<const map_t>
209  getRowMap() const {
210  return row_map_;
211  }
212 
213  Teuchos::RCP<const map_t>
214  getColMap() const {
215  return col_map_;
216  }
217 
218  Teuchos::RCP<const type> get(const Teuchos::Ptr<const map_t> map, EDistribution distribution = ROOTED) const;
219 
222  Teuchos::RCP<const type> reindex(Teuchos::RCP<const map_t> &contigRowMap, Teuchos::RCP<const map_t> &contigColMap, const EPhase current_phase) const;
223 
225  template<typename KV_S, typename KV_GO, typename KV_GS, typename host_ordinal_type_array, typename host_scalar_type_array>
226  local_ordinal_t gather(KV_S& nzvals, KV_GO& indices, KV_GS& pointers,
227  host_ordinal_type_array &recvCounts, host_ordinal_type_array &recvDispls,
228  host_ordinal_type_array &transpose_map, host_scalar_type_array &nzvals_t,
229  bool column_major, EPhase current_phase) const;
230 
232  std::string description() const;
233 
235  void describe(Teuchos::FancyOStream &out,
236  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
237 
239  template<typename KV>
240  void returnRowPtr_kokkos_view(KV & view) const;
241 
243  template<typename KV>
244  void returnColInd_kokkos_view(KV & view) const;
245 
247  template<typename KV>
248  void returnValues_kokkos_view(KV & view) const;
249 
250 
251  private:
252  template<typename KV_S, typename KV_GO, typename KV_GS>
253  void help_getCrs_kokkos_view(KV_S & nzval,
254  KV_GO & colind,
255  KV_GS & rowptr,
256  global_size_t& nnz,
257  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
258  EDistribution distribution,
259  EStorage_Ordering ordering,
260  no_special_impl nsi) const;
261 
262  template<typename KV_S, typename KV_GO, typename KV_GS>
263  void do_getCrs_kokkos_view(KV_S & nzval,
264  KV_GO & colind,
265  KV_GS & rowptr,
266  global_size_t& nnz,
267  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
268  EDistribution distribution,
269  EStorage_Ordering ordering,
270  row_access ra) const;
271 
272  template<typename KV_S, typename KV_GO, typename KV_GS>
273  void help_getCcs_kokkos_view(KV_S & nzval,
274  KV_GO & colind,
275  KV_GS & rowptr,
276  global_size_t& nnz,
277  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
278  EDistribution distribution,
279  EStorage_Ordering ordering,
280  no_special_impl nsi) const;
281 
282  template<typename KV_S, typename KV_GO, typename KV_GS>
283  void do_getCcs_kokkos_view(KV_S & nzval,
284  KV_GO & rowind,
285  KV_GS & colptr,
286  global_size_t& nnz,
287  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
288  EDistribution distribution,
289  EStorage_Ordering ordering,
290  row_access ra) const;
291 
292  protected:
293  // These methods will link to concrete implementations, and may
294  // also be used by them
295 
302  template<typename KV_GO, typename KV_S>
303  void getGlobalRowCopy_kokkos_view(global_ordinal_t row,
304  KV_GO & indices,
305  KV_S & vals,
306  size_t& nnz) const;
307 
308  size_t getMaxRowNNZ() const;
309 
310  size_t getMaxColNNZ() const;
311 
312  size_t getGlobalRowNNZ(global_ordinal_t row) const;
313 
314  size_t getLocalRowNNZ(local_ordinal_t row) const;
315 
316  size_t getGlobalColNNZ(global_ordinal_t col) const;
317 
318  size_t getLocalColNNZ(local_ordinal_t col) const;
319 
320  bool isLocallyIndexed() const;
321 
322  bool isGloballyIndexed() const;
323 
324  protected:
325  const Teuchos::RCP<const Matrix> mat_;
326 
327  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > row_map_;
328 
329  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > col_map_;
330 
331  mutable Teuchos::RCP<const Teuchos::Comm<int> > comm_;
332  }; // end class MatrixAdapter
333 
334 
335  // Factory creation method
336  template <class Matrix>
337  Teuchos::RCP<MatrixAdapter<Matrix> >
338  createMatrixAdapter(Teuchos::RCP<Matrix> m);
339 
340  template <class Matrix>
341  Teuchos::RCP<const MatrixAdapter<Matrix> >
342  createConstMatrixAdapter(Teuchos::RCP<const Matrix> m);
343 
344 } // end namespace Amesos2
345 
346 #endif // AMESOS2_MATRIXADAPTER_DECL_HPP
global_size_t getGlobalNumRows() const
Get the number of rows in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:106
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this matrix.
Definition: Amesos2_MatrixAdapter_decl.hpp:174
void returnRowPtr_kokkos_view(KV &view) const
Return kokkos view of CRS row pointer of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:186
EPhase
Used to indicate a phase in the direct solution.
Definition: Amesos2_TypeDecl.hpp:31
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:444
local_ordinal_t gather(KV_S &nzvals, KV_GO &indices, KV_GS &pointers, host_ordinal_type_array &recvCounts, host_ordinal_type_array &recvDispls, host_ordinal_type_array &transpose_map, host_scalar_type_array &nzvals_t, bool column_major, EPhase current_phase) const
Gather matrix to MPI-0.
void getCcs_kokkos_view(KV_S &nzval, KV_GO &rowind, KV_GS &colptr, global_size_t &nnz, const Teuchos::Ptr< const map_t > colmap, EStorage_Ordering ordering=ARBITRARY, EDistribution distribution=ROOTED) const
Gets a compressed-column storage summary of this.
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
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:193
global_size_t getRowIndexBase() const
Get the indexbase for the row map.
Definition: Amesos2_MatrixAdapter_def.hpp:120
void getCrs_kokkos_view(KV_S &nzval, KV_GO &colind, KV_GS &rowptr, global_size_t &nnz, const Teuchos::Ptr< const map_t > rowmap, EStorage_Ordering ordering=ARBITRARY, EDistribution distribution=ROOTED) const
Gets a compressed-row storage summary of this.
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:200
Teuchos::RCP< const type > reindex(Teuchos::RCP< const map_t > &contigRowMap, Teuchos::RCP< const map_t > &contigColMap, const EPhase current_phase) const
Definition: Amesos2_MatrixAdapter_def.hpp:519