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 
147  void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
148  const Teuchos::ArrayView<global_ordinal_t> colind,
149  const Teuchos::ArrayView<global_size_t> rowptr,
150  global_size_t& nnz,
151  EDistribution distribution,
152  EStorage_Ordering ordering=ARBITRARY) const;
153 
182  void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
183  const Teuchos::ArrayView<global_ordinal_t> rowind,
184  const Teuchos::ArrayView<global_size_t> colptr,
185  global_size_t& nnz,
186  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
187  EStorage_Ordering ordering=ARBITRARY,
188  EDistribution distribution=ROOTED) const; // This was placed as last argument to preserve API
189 
195  void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
196  const Teuchos::ArrayView<global_ordinal_t> rowind,
197  const Teuchos::ArrayView<global_size_t> colptr,
198  global_size_t& nnz,
199  EDistribution distribution,
200  EStorage_Ordering ordering=ARBITRARY) const;
201 
202 
204  const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
205  {
206  return comm_;
207  }
208 
210  global_size_t getGlobalNumRows() const;
211 
213  global_size_t getGlobalNumCols() const;
214 
216  global_size_t getRowIndexBase() const;
217 
219  global_size_t getColumnIndexBase() const;
220 
222  global_size_t getGlobalNNZ() const;
223 
225  size_t getLocalNumRows() const;
226 
228  size_t getLocalNumCols() const;
229 
231  size_t getLocalNNZ() const;
232 
233  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
234  getMap() const {
235  return static_cast<const adapter_t*>(this)->getMap_impl();
236  }
237 
238  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
239  getRowMap() const {
240  return row_map_;
241  }
242 
243  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
244  getColMap() const {
245  return col_map_;
246  }
247 
248  Teuchos::RCP<const type> get(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution = ROOTED) const;
249 
251  std::string description() const;
252 
254  void describe(Teuchos::FancyOStream &out,
255  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
256 
258  spmtx_ptr_t returnRowPtr() const;
259 
261  spmtx_idx_t returnColInd() const;
262 
264  spmtx_vals_t returnValues() const;
265 
266  private:
267 
268  void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
269  const Teuchos::ArrayView<global_ordinal_t> colind,
270  const Teuchos::ArrayView<global_size_t> rowptr,
271  global_size_t& nnz,
272  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
273  EDistribution distribution,
274  EStorage_Ordering ordering,
275  has_special_impl hsi) const;
276 
277  void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
278  const Teuchos::ArrayView<global_ordinal_t> colind,
279  const Teuchos::ArrayView<global_size_t> rowptr,
280  global_size_t& nnz,
281  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
282  EDistribution distribution,
283  EStorage_Ordering ordering,
284  no_special_impl nsi) const;
285 
286  void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
287  const Teuchos::ArrayView<global_ordinal_t> colind,
288  const Teuchos::ArrayView<global_size_t> rowptr,
289  global_size_t& nnz,
290  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
291  EDistribution distribution,
292  EStorage_Ordering ordering,
293  row_access ra) const;
294 
295  void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
296  const Teuchos::ArrayView<global_ordinal_t> colind,
297  const Teuchos::ArrayView<global_size_t> 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  col_access ca) const;
303 
304  void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
305  const Teuchos::ArrayView<global_ordinal_t> rowind,
306  const Teuchos::ArrayView<global_size_t> colptr,
307  global_size_t& nnz,
308  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
309  EDistribution distribution,
310  EStorage_Ordering ordering,
311  has_special_impl hsi) const;
312 
313  void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
314  const Teuchos::ArrayView<global_ordinal_t> rowind,
315  const Teuchos::ArrayView<global_size_t> colptr,
316  global_size_t& nnz,
317  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
318  EDistribution distribution,
319  EStorage_Ordering ordering,
320  no_special_impl nsi) const;
321 
322  void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
323  const Teuchos::ArrayView<global_ordinal_t> rowind,
324  const Teuchos::ArrayView<global_size_t> colptr,
325  global_size_t& nnz,
326  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
327  EDistribution distribution,
328  EStorage_Ordering ordering,
329  row_access ra) const;
330 
331  void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
332  const Teuchos::ArrayView<global_ordinal_t> rowind,
333  const Teuchos::ArrayView<global_size_t> colptr,
334  global_size_t& nnz,
335  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
336  EDistribution distribution,
337  EStorage_Ordering ordering,
338  col_access ca) const;
339 
340  protected:
341  // These methods will link to concrete implementations, and may
342  // also be used by them
343 
350  void getGlobalRowCopy(global_ordinal_t row,
351  const Teuchos::ArrayView<global_ordinal_t>& indices,
352  const Teuchos::ArrayView<scalar_t>& vals,
353  size_t& nnz) const;
354 
361  void getGlobalColCopy(global_ordinal_t col,
362  const Teuchos::ArrayView<global_ordinal_t>& indices,
363  const Teuchos::ArrayView<scalar_t>& vals,
364  size_t& nnz) const;
365 
366  size_t getMaxRowNNZ() const;
367 
368  size_t getMaxColNNZ() const;
369 
370  size_t getGlobalRowNNZ(global_ordinal_t row) const;
371 
372  size_t getLocalRowNNZ(local_ordinal_t row) const;
373 
374  size_t getGlobalColNNZ(global_ordinal_t col) const;
375 
376  size_t getLocalColNNZ(local_ordinal_t col) const;
377 
378  bool isLocallyIndexed() const;
379 
380  bool isGloballyIndexed() const;
381 
382  protected:
383  const Teuchos::RCP<const Matrix> mat_;
384 
385  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > row_map_;
386 
387  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > col_map_;
388 
389  mutable Teuchos::RCP<const Teuchos::Comm<int> > comm_;
390  }; // end class MatrixAdapter
391 
392 
393  // Factory creation method
394  template <class Matrix>
395  Teuchos::RCP<MatrixAdapter<Matrix> >
396  createMatrixAdapter(Teuchos::RCP<Matrix> m);
397 
398  template <class Matrix>
399  Teuchos::RCP<const MatrixAdapter<Matrix> >
400  createConstMatrixAdapter(Teuchos::RCP<const Matrix> m);
401 
402 } // end namespace Amesos2
403 
404 #endif // AMESOS2_MATRIXADAPTER_DECL_HPP
spmtx_vals_t returnValues() const
Return raw pointer from CRS values of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:216
global_size_t getGlobalNumRows() const
Get the number of rows in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:129
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this matrix.
Definition: Amesos2_MatrixAdapter_decl.hpp:204
spmtx_ptr_t returnRowPtr() const
Return raw pointer from CRS row pointer of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:202
global_size_t getGlobalNNZ() const
Get the global number of non-zeros in this sparse matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:157
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:196
size_t getLocalNumRows() const
Get the number of rows local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:164
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:488
size_t getLocalNumCols() const
Get the number of columns local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:171
spmtx_idx_t returnColInd() const
Return raw pointer from CRS column indices of matrixA_.
Definition: Amesos2_MatrixAdapter_def.hpp:209
size_t getLocalNNZ() const
Get the local number of non-zeros on this processor.
Definition: Amesos2_MatrixAdapter_def.hpp:178
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_MatrixAdapter_def.hpp:186
global_size_t getColumnIndexBase() const
Get the indexbase for the column map.
Definition: Amesos2_MatrixAdapter_def.hpp:150
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:136
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:478
global_size_t getRowIndexBase() const
Get the indexbase for the row map.
Definition: Amesos2_MatrixAdapter_def.hpp:143
EDistribution
Definition: Amesos2_TypeDecl.hpp:123