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  typedef typename MatrixTraits<Matrix>::local_matrix_t local_matrix_t;
91  typedef typename MatrixTraits<Matrix>::sparse_ptr_type spmtx_ptr_t;
92  typedef typename MatrixTraits<Matrix>::sparse_idx_type spmtx_idx_t;
93  typedef typename MatrixTraits<Matrix>::sparse_values_type spmtx_vals_t;
94 
95  // template<typename S, typename GO, typename GS, typename Op>
96  // friend class Util::get_cxs_helper<MatrixAdapter<Matrix>,S,GO,GS,Op>;
97  // template<class M, typename S, typename GO, typename GS, typename Op>
98  // friend class Util::get_cxs_helper;
99 
100  MatrixAdapter(Teuchos::RCP<Matrix> m);
101 
102 
134  void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
135  const Teuchos::ArrayView<global_ordinal_t> colind,
136  const Teuchos::ArrayView<global_size_t> rowptr,
137  global_size_t& nnz,
138  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
139  EStorage_Ordering ordering=ARBITRARY,
140  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
141 
142  template<typename KV_S, typename KV_GO, typename KV_GS>
143  void getCrs_kokkos_view(KV_S & nzval,
144  KV_GO & colind,
145  KV_GS & rowptr,
146  global_size_t& nnz,
147  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
148  EStorage_Ordering ordering=ARBITRARY,
149  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
150 
151 
157  void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
158  const Teuchos::ArrayView<global_ordinal_t> colind,
159  const Teuchos::ArrayView<global_size_t> rowptr,
160  global_size_t& nnz,
161  EDistribution distribution,
162  EStorage_Ordering ordering=ARBITRARY) const;
163 
192  void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
193  const Teuchos::ArrayView<global_ordinal_t> rowind,
194  const Teuchos::ArrayView<global_size_t> colptr,
195  global_size_t& nnz,
196  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
197  EStorage_Ordering ordering=ARBITRARY,
198  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
199 
200  template<typename KV_S, typename KV_GO, typename KV_GS>
201  void getCcs_kokkos_view(KV_S & nzval,
202  KV_GO & colind,
203  KV_GS & rowptr,
204  global_size_t& nnz,
205  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
206  EStorage_Ordering ordering=ARBITRARY,
207  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
208 
214  void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
215  const Teuchos::ArrayView<global_ordinal_t> rowind,
216  const Teuchos::ArrayView<global_size_t> colptr,
217  global_size_t& nnz,
218  EDistribution distribution,
219  EStorage_Ordering ordering=ARBITRARY) const;
220 
221 
223  const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
224  {
225  return comm_;
226  }
227 
229  global_size_t getGlobalNumRows() const;
230 
232  global_size_t getGlobalNumCols() const;
233 
235  global_size_t getRowIndexBase() const;
236 
238  global_size_t getColumnIndexBase() const;
239 
241  global_size_t getGlobalNNZ() const;
242 
244  size_t getLocalNumRows() const;
245 
247  size_t getLocalNumCols() const;
248 
250  size_t getLocalNNZ() const;
251 
252  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
253  getMap() const {
254  return static_cast<const adapter_t*>(this)->getMap_impl();
255  }
256 
257  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
258  getRowMap() const {
259  return row_map_;
260  }
261 
262  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
263  getColMap() const {
264  return col_map_;
265  }
266 
267  Teuchos::RCP<const type> get(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution = ROOTED) const;
268 
270  std::string description() const;
271 
273  void describe(Teuchos::FancyOStream &out,
274  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
275 
277  spmtx_ptr_t returnRowPtr() const;
278 
280  spmtx_idx_t returnColInd() const;
281 
283  spmtx_vals_t returnValues() const;
284 
286  template<typename KV>
287  void returnRowPtr_kokkos_view(KV & view) const;
288 
290  template<typename KV>
291  void returnColInd_kokkos_view(KV & view) const;
292 
294  template<typename KV>
295  void returnValues_kokkos_view(KV & view) const;
296 
297 
298  private:
299 
300  void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
301  const Teuchos::ArrayView<global_ordinal_t> colind,
302  const Teuchos::ArrayView<global_size_t> rowptr,
303  global_size_t& nnz,
304  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
305  EDistribution distribution,
306  EStorage_Ordering ordering,
307  has_special_impl hsi) const;
308 
309  void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
310  const Teuchos::ArrayView<global_ordinal_t> colind,
311  const Teuchos::ArrayView<global_size_t> rowptr,
312  global_size_t& nnz,
313  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
314  EDistribution distribution,
315  EStorage_Ordering ordering,
316  no_special_impl nsi) const;
317 
318  template<typename KV_S, typename KV_GO, typename KV_GS>
319  void help_getCrs_kokkos_view(KV_S & nzval,
320  KV_GO & colind,
321  KV_GS & rowptr,
322  global_size_t& nnz,
323  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
324  EDistribution distribution,
325  EStorage_Ordering ordering,
326  no_special_impl nsi) const;
327 
328  void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
329  const Teuchos::ArrayView<global_ordinal_t> colind,
330  const Teuchos::ArrayView<global_size_t> rowptr,
331  global_size_t& nnz,
332  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
333  EDistribution distribution,
334  EStorage_Ordering ordering,
335  row_access ra) const;
336 
337  void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
338  const Teuchos::ArrayView<global_ordinal_t> colind,
339  const Teuchos::ArrayView<global_size_t> rowptr,
340  global_size_t& nnz,
341  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
342  EDistribution distribution,
343  EStorage_Ordering ordering,
344  col_access ca) const;
345 
346  template<typename KV_S, typename KV_GO, typename KV_GS>
347  void do_getCrs_kokkos_view(KV_S & nzval,
348  KV_GO & colind,
349  KV_GS & rowptr,
350  global_size_t& nnz,
351  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
352  EDistribution distribution,
353  EStorage_Ordering ordering,
354  row_access ra) const;
355 
356  void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
357  const Teuchos::ArrayView<global_ordinal_t> rowind,
358  const Teuchos::ArrayView<global_size_t> colptr,
359  global_size_t& nnz,
360  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
361  EDistribution distribution,
362  EStorage_Ordering ordering,
363  has_special_impl hsi) const;
364 
365  void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
366  const Teuchos::ArrayView<global_ordinal_t> rowind,
367  const Teuchos::ArrayView<global_size_t> colptr,
368  global_size_t& nnz,
369  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
370  EDistribution distribution,
371  EStorage_Ordering ordering,
372  no_special_impl nsi) const;
373 
374  template<typename KV_S, typename KV_GO, typename KV_GS>
375  void help_getCcs_kokkos_view(KV_S & nzval,
376  KV_GO & colind,
377  KV_GS & rowptr,
378  global_size_t& nnz,
379  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
380  EDistribution distribution,
381  EStorage_Ordering ordering,
382  no_special_impl nsi) const;
383 
384  void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
385  const Teuchos::ArrayView<global_ordinal_t> rowind,
386  const Teuchos::ArrayView<global_size_t> colptr,
387  global_size_t& nnz,
388  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
389  EDistribution distribution,
390  EStorage_Ordering ordering,
391  row_access ra) const;
392 
393  void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
394  const Teuchos::ArrayView<global_ordinal_t> rowind,
395  const Teuchos::ArrayView<global_size_t> colptr,
396  global_size_t& nnz,
397  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
398  EDistribution distribution,
399  EStorage_Ordering ordering,
400  col_access ca) const;
401 
402  template<typename KV_S, typename KV_GO, typename KV_GS>
403  void do_getCcs_kokkos_view(KV_S & nzval,
404  KV_GO & rowind,
405  KV_GS & colptr,
406  global_size_t& nnz,
407  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
408  EDistribution distribution,
409  EStorage_Ordering ordering,
410  row_access ra) const;
411 
412  protected:
413  // These methods will link to concrete implementations, and may
414  // also be used by them
415 
422  void getGlobalRowCopy(global_ordinal_t row,
423  const Teuchos::ArrayView<global_ordinal_t>& indices,
424  const Teuchos::ArrayView<scalar_t>& vals,
425  size_t& nnz) const;
426 
433  void getGlobalColCopy(global_ordinal_t col,
434  const Teuchos::ArrayView<global_ordinal_t>& indices,
435  const Teuchos::ArrayView<scalar_t>& vals,
436  size_t& nnz) const;
437 
438  size_t getMaxRowNNZ() const;
439 
440  size_t getMaxColNNZ() const;
441 
442  size_t getGlobalRowNNZ(global_ordinal_t row) const;
443 
444  size_t getLocalRowNNZ(local_ordinal_t row) const;
445 
446  size_t getGlobalColNNZ(global_ordinal_t col) const;
447 
448  size_t getLocalColNNZ(local_ordinal_t col) const;
449 
450  bool isLocallyIndexed() const;
451 
452  bool isGloballyIndexed() const;
453 
454  protected:
455  const Teuchos::RCP<const Matrix> mat_;
456 
457  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > row_map_;
458 
459  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > col_map_;
460 
461  mutable Teuchos::RCP<const Teuchos::Comm<int> > comm_;
462  }; // end class MatrixAdapter
463 
464 
465  // Factory creation method
466  template <class Matrix>
467  Teuchos::RCP<MatrixAdapter<Matrix> >
468  createMatrixAdapter(Teuchos::RCP<Matrix> m);
469 
470  template <class Matrix>
471  Teuchos::RCP<const MatrixAdapter<Matrix> >
472  createConstMatrixAdapter(Teuchos::RCP<const Matrix> m);
473 
474 } // end namespace Amesos2
475 
476 #endif // AMESOS2_MATRIXADAPTER_DECL_HPP
spmtx_vals_t returnValues() const
Return raw pointer from CRS values of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:252
global_size_t getGlobalNumRows() const
Get the number of rows in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:161
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this matrix.
Definition: Amesos2_MatrixAdapter_decl.hpp:223
void returnRowPtr_kokkos_view(KV &view) const
Return kokkos view of CRS row pointer of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:259
spmtx_ptr_t returnRowPtr() const
Return raw pointer from CRS row pointer of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:238
global_size_t getGlobalNNZ() const
Get the global number of non-zeros in this sparse matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:193
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:232
size_t getLocalNumRows() const
Get the number of rows local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:200
void getCcs(const Teuchos::ArrayView< scalar_t > nzval, const Teuchos::ArrayView< global_ordinal_t > rowind, const Teuchos::ArrayView< global_size_t > 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.
void getCrs(const Teuchos::ArrayView< scalar_t > nzval, const Teuchos::ArrayView< global_ordinal_t > colind, const Teuchos::ArrayView< global_size_t > 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.
Utility functions for Amesos2.
EStorage_Ordering
Definition: Amesos2_TypeDecl.hpp:141
void getGlobalColCopy(global_ordinal_t col, const Teuchos::ArrayView< global_ordinal_t > &indices, const Teuchos::ArrayView< scalar_t > &vals, size_t &nnz) const
Definition: Amesos2_MatrixAdapter_def.hpp:725
size_t getLocalNumCols() const
Get the number of columns local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:207
spmtx_idx_t returnColInd() const
Return raw pointer from CRS column indices of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:245
size_t getLocalNNZ() const
Get the local number of non-zeros on this processor.
Definition: Amesos2_MatrixAdapter_def.hpp:214
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_MatrixAdapter_def.hpp:222
global_size_t getColumnIndexBase() const
Get the indexbase for the column map.
Definition: Amesos2_MatrixAdapter_def.hpp:184
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
global_size_t getGlobalNumCols() const
Get the number of columns in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:168
void returnColInd_kokkos_view(KV &view) const
Return kokkos view of CRS column indices of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:266
void getGlobalRowCopy(global_ordinal_t row, const Teuchos::ArrayView< global_ordinal_t > &indices, const Teuchos::ArrayView< scalar_t > &vals, size_t &nnz) const
Definition: Amesos2_MatrixAdapter_def.hpp:715
global_size_t getRowIndexBase() const
Get the indexbase for the row map.
Definition: Amesos2_MatrixAdapter_def.hpp:175
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
void returnValues_kokkos_view(KV &view) const
Return kokkos view of CRS values of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:273