Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_MatrixAdapter_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_MATRIXADAPTER_DECL_HPP
46 #define AMESOS2_MATRIXADAPTER_DECL_HPP
47 
48 #include "Amesos2_config.h"
49 
50 #include <Teuchos_Comm.hpp>
51 #include <Teuchos_ArrayView.hpp>
52 #include <Teuchos_VerbosityLevel.hpp>
53 #include <Teuchos_FancyOStream.hpp>
54 
55 #include <Tpetra_ConfigDefs.hpp> // for global_size_t
56 
57 // #include "Amesos2_ConcreteMatrixAdapter_decl.hpp"
58 #include "Amesos2_Util.hpp"
59 #include "Amesos2_MatrixTraits.hpp"
60 
61 namespace Amesos2 {
62 
63  template <class M> class ConcreteMatrixAdapter;
64 
75  template < class Matrix >
76  class MatrixAdapter {
77 
78  public:
79 
80  typedef typename MatrixTraits<Matrix>::scalar_t scalar_t;
81  typedef typename MatrixTraits<Matrix>::local_ordinal_t local_ordinal_t;
82  typedef typename MatrixTraits<Matrix>::global_ordinal_t global_ordinal_t;
83  typedef typename MatrixTraits<Matrix>::node_t node_t;
84  typedef Tpetra::global_size_t global_size_t;
85 
86  typedef Matrix matrix_t;
88  typedef ConcreteMatrixAdapter<Matrix> adapter_t;
89 
90  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
91  typedef typename MatrixTraits<Matrix>::local_matrix_t local_matrix_t;
92  typedef typename MatrixTraits<Matrix>::sparse_ptr_type spmtx_ptr_t;
93  typedef typename MatrixTraits<Matrix>::sparse_idx_type spmtx_idx_t;
94  typedef typename MatrixTraits<Matrix>::sparse_values_type spmtx_vals_t;
95  #endif
96 
97  typedef typename MatrixTraits<Matrix>::global_host_idx_type global_host_idx_t;
98  typedef typename MatrixTraits<Matrix>::global_host_val_type global_host_val_t;
99 
100  // template<typename S, typename GO, typename GS, typename Op>
101  // friend class Util::get_cxs_helper<MatrixAdapter<Matrix>,S,GO,GS,Op>;
102  // template<class M, typename S, typename GO, typename GS, typename Op>
103  // friend class Util::get_cxs_helper;
104 
105  MatrixAdapter(Teuchos::RCP<Matrix> m);
106 
107 
139  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
140  void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
141  const Teuchos::ArrayView<global_ordinal_t> colind,
142  const Teuchos::ArrayView<global_size_t> rowptr,
143  global_size_t& nnz,
144  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
145  EStorage_Ordering ordering=ARBITRARY,
146  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
147  #endif
148 
149  template<typename KV_S, typename KV_GO, typename KV_GS>
150  void getCrs_kokkos_view(KV_S & nzval,
151  KV_GO & colind,
152  KV_GS & rowptr,
153  global_size_t& nnz,
154  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
155  EStorage_Ordering ordering=ARBITRARY,
156  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
157 
158 
164  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
165  void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
166  const Teuchos::ArrayView<global_ordinal_t> colind,
167  const Teuchos::ArrayView<global_size_t> rowptr,
168  global_size_t& nnz,
169  EDistribution distribution,
170  EStorage_Ordering ordering=ARBITRARY) const;
171  #endif
172 
173  template<typename KV_S, typename KV_GO, typename KV_GS>
174  void getCrs_kokkos_view(KV_S & nzval,
175  KV_GO & colind,
176  KV_GS & rowptr,
177  global_size_t& nnz,
178  EDistribution distribution=ROOTED,
179  EStorage_Ordering ordering=ARBITRARY) const; // This was placed as last argument to preserve API
180 
209  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
210  void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
211  const Teuchos::ArrayView<global_ordinal_t> rowind,
212  const Teuchos::ArrayView<global_size_t> colptr,
213  global_size_t& nnz,
214  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
215  EStorage_Ordering ordering=ARBITRARY,
216  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
217  #endif
218 
219  template<typename KV_S, typename KV_GO, typename KV_GS>
220  void getCcs_kokkos_view(KV_S & nzval,
221  KV_GO & rowind,
222  KV_GS & colptr,
223  global_size_t& nnz,
224  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
225  EStorage_Ordering ordering=ARBITRARY,
226  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
227 
233  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
234  void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
235  const Teuchos::ArrayView<global_ordinal_t> rowind,
236  const Teuchos::ArrayView<global_size_t> colptr,
237  global_size_t& nnz,
238  EDistribution distribution,
239  EStorage_Ordering ordering=ARBITRARY) const;
240  #endif
241 
242  template<typename KV_S, typename KV_GO, typename KV_GS>
243  void getCcs_kokkos_view(KV_S & nzval,
244  KV_GO & rowind,
245  KV_GS & colptr,
246  global_size_t& nnz,
247  EDistribution distribution=ROOTED,
248  EStorage_Ordering ordering=ARBITRARY) const; // This was placed as last argument to preserve API
249 
250 
252  const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
253  {
254  return comm_;
255  }
256 
258  global_size_t getGlobalNumRows() const;
259 
261  global_size_t getGlobalNumCols() const;
262 
264  global_size_t getRowIndexBase() const;
265 
267  global_size_t getColumnIndexBase() const;
268 
270  global_size_t getGlobalNNZ() const;
271 
273  size_t getLocalNumRows() const;
274 
276  size_t getLocalNumCols() const;
277 
279  size_t getLocalNNZ() const;
280 
281  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
282  getMap() const {
283  return static_cast<const adapter_t*>(this)->getMap_impl();
284  }
285 
286  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
287  getRowMap() const {
288  return row_map_;
289  }
290 
291  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
292  getColMap() const {
293  return col_map_;
294  }
295 
296  Teuchos::RCP<const type> get(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution = ROOTED) const;
297 
299  std::string description() const;
300 
302  void describe(Teuchos::FancyOStream &out,
303  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
304 
305  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
306  spmtx_ptr_t returnRowPtr() const;
308 
310  spmtx_idx_t returnColInd() const;
311 
313  spmtx_vals_t returnValues() const;
314  #endif
315 
317  template<typename KV>
318  void returnRowPtr_kokkos_view(KV & view) const;
319 
321  template<typename KV>
322  void returnColInd_kokkos_view(KV & view) const;
323 
325  template<typename KV>
326  void returnValues_kokkos_view(KV & view) const;
327 
328 
329  private:
330 
331  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
332  void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
333  const Teuchos::ArrayView<global_ordinal_t> colind,
334  const Teuchos::ArrayView<global_size_t> rowptr,
335  global_size_t& nnz,
336  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
337  EDistribution distribution,
338  EStorage_Ordering ordering,
339  has_special_impl hsi) const;
340 
341  void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
342  const Teuchos::ArrayView<global_ordinal_t> colind,
343  const Teuchos::ArrayView<global_size_t> rowptr,
344  global_size_t& nnz,
345  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
346  EDistribution distribution,
347  EStorage_Ordering ordering,
348  no_special_impl nsi) const;
349  #endif
350 
351  template<typename KV_S, typename KV_GO, typename KV_GS>
352  void help_getCrs_kokkos_view(KV_S & nzval,
353  KV_GO & colind,
354  KV_GS & rowptr,
355  global_size_t& nnz,
356  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
357  EDistribution distribution,
358  EStorage_Ordering ordering,
359  no_special_impl nsi) const;
360 
361  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
362  void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
363  const Teuchos::ArrayView<global_ordinal_t> colind,
364  const Teuchos::ArrayView<global_size_t> rowptr,
365  global_size_t& nnz,
366  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
367  EDistribution distribution,
368  EStorage_Ordering ordering,
369  row_access ra) const;
370 
371  void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
372  const Teuchos::ArrayView<global_ordinal_t> colind,
373  const Teuchos::ArrayView<global_size_t> rowptr,
374  global_size_t& nnz,
375  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
376  EDistribution distribution,
377  EStorage_Ordering ordering,
378  col_access ca) const;
379  #endif
380 
381  template<typename KV_S, typename KV_GO, typename KV_GS>
382  void do_getCrs_kokkos_view(KV_S & nzval,
383  KV_GO & colind,
384  KV_GS & rowptr,
385  global_size_t& nnz,
386  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
387  EDistribution distribution,
388  EStorage_Ordering ordering,
389  row_access ra) const;
390 
391  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
392  void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
393  const Teuchos::ArrayView<global_ordinal_t> rowind,
394  const Teuchos::ArrayView<global_size_t> colptr,
395  global_size_t& nnz,
396  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
397  EDistribution distribution,
398  EStorage_Ordering ordering,
399  has_special_impl hsi) const;
400 
401  void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
402  const Teuchos::ArrayView<global_ordinal_t> rowind,
403  const Teuchos::ArrayView<global_size_t> colptr,
404  global_size_t& nnz,
405  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
406  EDistribution distribution,
407  EStorage_Ordering ordering,
408  no_special_impl nsi) const;
409  #endif
410 
411  template<typename KV_S, typename KV_GO, typename KV_GS>
412  void help_getCcs_kokkos_view(KV_S & nzval,
413  KV_GO & colind,
414  KV_GS & rowptr,
415  global_size_t& nnz,
416  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
417  EDistribution distribution,
418  EStorage_Ordering ordering,
419  no_special_impl nsi) const;
420 
421  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
422  void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
423  const Teuchos::ArrayView<global_ordinal_t> rowind,
424  const Teuchos::ArrayView<global_size_t> colptr,
425  global_size_t& nnz,
426  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
427  EDistribution distribution,
428  EStorage_Ordering ordering,
429  row_access ra) const;
430 
431  void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
432  const Teuchos::ArrayView<global_ordinal_t> rowind,
433  const Teuchos::ArrayView<global_size_t> colptr,
434  global_size_t& nnz,
435  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
436  EDistribution distribution,
437  EStorage_Ordering ordering,
438  col_access ca) const;
439  #endif
440 
441  template<typename KV_S, typename KV_GO, typename KV_GS>
442  void do_getCcs_kokkos_view(KV_S & nzval,
443  KV_GO & rowind,
444  KV_GS & colptr,
445  global_size_t& nnz,
446  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
447  EDistribution distribution,
448  EStorage_Ordering ordering,
449  row_access ra) const;
450 
451  protected:
452  // These methods will link to concrete implementations, and may
453  // also be used by them
454 
461  template<typename KV_GO, typename KV_S>
462  void getGlobalRowCopy_kokkos_view(global_ordinal_t row,
463  KV_GO & indices,
464  KV_S & vals,
465  size_t& nnz) const;
466 
467  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
468  void getGlobalRowCopy(global_ordinal_t row,
469  const Teuchos::ArrayView<global_ordinal_t>& indices,
470  const Teuchos::ArrayView<scalar_t>& vals,
471  size_t& nnz) const;
472  #endif
473 
480  #ifdef TPETRA_ENABLE_DEPRECATED_CODE
481  void getGlobalColCopy(global_ordinal_t col,
482  const Teuchos::ArrayView<global_ordinal_t>& indices,
483  const Teuchos::ArrayView<scalar_t>& vals,
484  size_t& nnz) const;
485  #endif
486 
487  size_t getMaxRowNNZ() const;
488 
489  size_t getMaxColNNZ() const;
490 
491  size_t getGlobalRowNNZ(global_ordinal_t row) const;
492 
493  size_t getLocalRowNNZ(local_ordinal_t row) const;
494 
495  size_t getGlobalColNNZ(global_ordinal_t col) const;
496 
497  size_t getLocalColNNZ(local_ordinal_t col) const;
498 
499  bool isLocallyIndexed() const;
500 
501  bool isGloballyIndexed() const;
502 
503  protected:
504  const Teuchos::RCP<const Matrix> mat_;
505 
506  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > row_map_;
507 
508  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > col_map_;
509 
510  mutable Teuchos::RCP<const Teuchos::Comm<int> > comm_;
511  }; // end class MatrixAdapter
512 
513 
514  // Factory creation method
515  template <class Matrix>
516  Teuchos::RCP<MatrixAdapter<Matrix> >
517  createMatrixAdapter(Teuchos::RCP<Matrix> m);
518 
519  template <class Matrix>
520  Teuchos::RCP<const MatrixAdapter<Matrix> >
521  createConstMatrixAdapter(Teuchos::RCP<const Matrix> m);
522 
523 } // end namespace Amesos2
524 
525 #endif // AMESOS2_MATRIXADAPTER_DECL_HPP
global_size_t getGlobalNNZ() const
Get the global number of non-zeros in this sparse matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:240
Definition: Amesos2_TypeDecl.hpp:143
Utility functions for Amesos2.
EStorage_Ordering
Definition: Amesos2_TypeDecl.hpp:141
global_size_t getColumnIndexBase() const
Get the indexbase for the column map.
Definition: Amesos2_MatrixAdapter_def.hpp:231
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:279
size_t getMaxRowNNZ() const
Definition: Amesos2_MatrixAdapter_def.hpp:860
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
size_t getLocalNumCols() const
Get the number of columns local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:254
size_t getLocalNumRows() const
Get the number of rows local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:247
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this matrix.
Definition: Amesos2_MatrixAdapter_decl.hpp:252
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.
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
size_t getLocalNNZ() const
Get the local number of non-zeros on this processor.
Definition: Amesos2_MatrixAdapter_def.hpp:261
void returnColInd_kokkos_view(KV &view) const
Return kokkos view of CRS column indices of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:315
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_MatrixAdapter_def.hpp:269
global_size_t getGlobalNumRows() const
Get the number of rows in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:208
void returnRowPtr_kokkos_view(KV &view) const
Return kokkos view of CRS row pointer of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:308
global_size_t getGlobalNumCols() const
Get the number of columns in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:215
Definition: Amesos2_TypeDecl.hpp:127
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
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.
global_size_t getRowIndexBase() const
Get the indexbase for the row map.
Definition: Amesos2_MatrixAdapter_def.hpp:222
void getGlobalRowCopy_kokkos_view(global_ordinal_t row, KV_GO &indices, KV_S &vals, size_t &nnz) const
Definition: Amesos2_MatrixAdapter_def.hpp:828
void returnValues_kokkos_view(KV &view) const
Return kokkos view of CRS values of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:322