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>::global_host_idx_type global_host_idx_t;
91  typedef typename MatrixTraits<Matrix>::global_host_val_type global_host_val_t;
92 
93  // template<typename S, typename GO, typename GS, typename Op>
94  // friend class Util::get_cxs_helper<MatrixAdapter<Matrix>,S,GO,GS,Op>;
95  // template<class M, typename S, typename GO, typename GS, typename Op>
96  // friend class Util::get_cxs_helper;
97 
98  MatrixAdapter(Teuchos::RCP<Matrix> m);
99 
100 
132  template<typename KV_S, typename KV_GO, typename KV_GS>
133  void getCrs_kokkos_view(KV_S & nzval,
134  KV_GO & colind,
135  KV_GS & rowptr,
136  global_size_t& nnz,
137  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
138  EStorage_Ordering ordering=ARBITRARY,
139  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
140 
141 
147  template<typename KV_S, typename KV_GO, typename KV_GS>
148  void getCrs_kokkos_view(KV_S & nzval,
149  KV_GO & colind,
150  KV_GS & rowptr,
151  global_size_t& nnz,
152  EDistribution distribution=ROOTED,
153  EStorage_Ordering ordering=ARBITRARY) const; // This was placed as last argument to preserve API
154 
183  template<typename KV_S, typename KV_GO, typename KV_GS>
184  void getCcs_kokkos_view(KV_S & nzval,
185  KV_GO & rowind,
186  KV_GS & colptr,
187  global_size_t& nnz,
188  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
189  EStorage_Ordering ordering=ARBITRARY,
190  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
191 
197  template<typename KV_S, typename KV_GO, typename KV_GS>
198  void getCcs_kokkos_view(KV_S & nzval,
199  KV_GO & rowind,
200  KV_GS & colptr,
201  global_size_t& nnz,
202  EDistribution distribution=ROOTED,
203  EStorage_Ordering ordering=ARBITRARY) const; // This was placed as last argument to preserve API
204 
205 
207  const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
208  {
209  return comm_;
210  }
211 
213  global_size_t getGlobalNumRows() const;
214 
216  global_size_t getGlobalNumCols() const;
217 
219  global_size_t getRowIndexBase() const;
220 
222  global_size_t getColumnIndexBase() const;
223 
225  global_size_t getGlobalNNZ() const;
226 
228  size_t getLocalNumRows() const;
229 
231  size_t getLocalNumCols() const;
232 
234  size_t getLocalNNZ() const;
235 
236  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
237  getMap() const {
238  return static_cast<const adapter_t*>(this)->getMap_impl();
239  }
240 
241  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
242  getRowMap() const {
243  return row_map_;
244  }
245 
246  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
247  getColMap() const {
248  return col_map_;
249  }
250 
251  Teuchos::RCP<const type> get(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution = ROOTED) const;
252 
254  std::string description() const;
255 
257  void describe(Teuchos::FancyOStream &out,
258  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
259 
261  template<typename KV>
262  void returnRowPtr_kokkos_view(KV & view) const;
263 
265  template<typename KV>
266  void returnColInd_kokkos_view(KV & view) const;
267 
269  template<typename KV>
270  void returnValues_kokkos_view(KV & view) const;
271 
272 
273  private:
274  template<typename KV_S, typename KV_GO, typename KV_GS>
275  void help_getCrs_kokkos_view(KV_S & nzval,
276  KV_GO & colind,
277  KV_GS & rowptr,
278  global_size_t& nnz,
279  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
280  EDistribution distribution,
281  EStorage_Ordering ordering,
282  no_special_impl nsi) const;
283 
284  template<typename KV_S, typename KV_GO, typename KV_GS>
285  void do_getCrs_kokkos_view(KV_S & nzval,
286  KV_GO & colind,
287  KV_GS & rowptr,
288  global_size_t& nnz,
289  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
290  EDistribution distribution,
291  EStorage_Ordering ordering,
292  row_access ra) const;
293 
294  template<typename KV_S, typename KV_GO, typename KV_GS>
295  void help_getCcs_kokkos_view(KV_S & nzval,
296  KV_GO & colind,
297  KV_GS & rowptr,
298  global_size_t& nnz,
299  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
300  EDistribution distribution,
301  EStorage_Ordering ordering,
302  no_special_impl nsi) const;
303 
304  template<typename KV_S, typename KV_GO, typename KV_GS>
305  void do_getCcs_kokkos_view(KV_S & nzval,
306  KV_GO & rowind,
307  KV_GS & colptr,
308  global_size_t& nnz,
309  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
310  EDistribution distribution,
311  EStorage_Ordering ordering,
312  row_access ra) const;
313 
314  protected:
315  // These methods will link to concrete implementations, and may
316  // also be used by them
317 
324  template<typename KV_GO, typename KV_S>
325  void getGlobalRowCopy_kokkos_view(global_ordinal_t row,
326  KV_GO & indices,
327  KV_S & vals,
328  size_t& nnz) const;
329 
330  size_t getMaxRowNNZ() const;
331 
332  size_t getMaxColNNZ() const;
333 
334  size_t getGlobalRowNNZ(global_ordinal_t row) const;
335 
336  size_t getLocalRowNNZ(local_ordinal_t row) const;
337 
338  size_t getGlobalColNNZ(global_ordinal_t col) const;
339 
340  size_t getLocalColNNZ(local_ordinal_t col) const;
341 
342  bool isLocallyIndexed() const;
343 
344  bool isGloballyIndexed() const;
345 
346  protected:
347  const Teuchos::RCP<const Matrix> mat_;
348 
349  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > row_map_;
350 
351  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > col_map_;
352 
353  mutable Teuchos::RCP<const Teuchos::Comm<int> > comm_;
354  }; // end class MatrixAdapter
355 
356 
357  // Factory creation method
358  template <class Matrix>
359  Teuchos::RCP<MatrixAdapter<Matrix> >
360  createMatrixAdapter(Teuchos::RCP<Matrix> m);
361 
362  template <class Matrix>
363  Teuchos::RCP<const MatrixAdapter<Matrix> >
364  createConstMatrixAdapter(Teuchos::RCP<const Matrix> m);
365 
366 } // end namespace Amesos2
367 
368 #endif // AMESOS2_MATRIXADAPTER_DECL_HPP
global_size_t getGlobalNumRows() const
Get the number of rows in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:140
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:207
void returnRowPtr_kokkos_view(KV &view) const
Return kokkos view of CRS row pointer of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:217
global_size_t getGlobalNNZ() const
Get the global number of non-zeros in this sparse matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:172
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:211
size_t getLocalNumRows() const
Get the number of rows local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:179
void getGlobalRowCopy_kokkos_view(global_ordinal_t row, KV_GO &indices, KV_S &vals, size_t &nnz) const
Definition: Amesos2_MatrixAdapter_def.hpp:475
Utility functions for Amesos2.
EStorage_Ordering
Definition: Amesos2_TypeDecl.hpp:141
size_t getLocalNumCols() const
Get the number of columns local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:186
size_t getLocalNNZ() const
Get the local number of non-zeros on this processor.
Definition: Amesos2_MatrixAdapter_def.hpp:193
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:201
global_size_t getColumnIndexBase() const
Get the indexbase for the column map.
Definition: Amesos2_MatrixAdapter_def.hpp:163
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:147
void returnColInd_kokkos_view(KV &view) const
Return kokkos view of CRS column indices of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:224
global_size_t getRowIndexBase() const
Get the indexbase for the row map.
Definition: Amesos2_MatrixAdapter_def.hpp:154
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:231