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  // template<typename S, typename GO, typename GS, typename Op>
91  // friend class Util::get_cxs_helper<MatrixAdapter<Matrix>,S,GO,GS,Op>;
92  // template<class M, typename S, typename GO, typename GS, typename Op>
93  // friend class Util::get_cxs_helper;
94 
95  MatrixAdapter(Teuchos::RCP<Matrix> m);
96 
97 
127  void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
128  const Teuchos::ArrayView<global_ordinal_t> colind,
129  const Teuchos::ArrayView<global_size_t> rowptr,
130  global_size_t& nnz,
131  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
132  EStorage_Ordering ordering=ARBITRARY) const;
133 
139  void getCrs(const Teuchos::ArrayView<scalar_t> nzval,
140  const Teuchos::ArrayView<global_ordinal_t> colind,
141  const Teuchos::ArrayView<global_size_t> rowptr,
142  global_size_t& nnz,
143  EDistribution distribution,
144  EStorage_Ordering ordering=ARBITRARY) const;
145 
172  void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
173  const Teuchos::ArrayView<global_ordinal_t> rowind,
174  const Teuchos::ArrayView<global_size_t> colptr,
175  global_size_t& nnz,
176  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
177  EStorage_Ordering ordering=ARBITRARY) const;
178 
184  void getCcs(const Teuchos::ArrayView<scalar_t> nzval,
185  const Teuchos::ArrayView<global_ordinal_t> rowind,
186  const Teuchos::ArrayView<global_size_t> colptr,
187  global_size_t& nnz,
188  EDistribution distribution,
189  EStorage_Ordering ordering=ARBITRARY) const;
190 
191 
193  const Teuchos::RCP<const Teuchos::Comm<int> > getComm() const
194  {
195  return comm_;
196  }
197 
199  global_size_t getGlobalNumRows() const;
200 
202  global_size_t getGlobalNumCols() const;
203 
205  global_size_t getRowIndexBase() const;
206 
208  global_size_t getColumnIndexBase() const;
209 
211  global_size_t getGlobalNNZ() const;
212 
214  size_t getLocalNumRows() const;
215 
217  size_t getLocalNumCols() const;
218 
220  size_t getLocalNNZ() const;
221 
222  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
223  getRowMap() const {
224  return row_map_;
225  }
226 
227  Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> >
228  getColMap() const {
229  return col_map_;
230  }
231 
232  Teuchos::RCP<const type> get(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map) const;
233 
235  std::string description() const;
236 
238  void describe(Teuchos::FancyOStream &out,
239  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
240 
241 
242  private:
243 
244  void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
245  const Teuchos::ArrayView<global_ordinal_t> colind,
246  const Teuchos::ArrayView<global_size_t> rowptr,
247  global_size_t& nnz,
248  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
249  EStorage_Ordering ordering,
250  has_special_impl hsi) const;
251 
252  void help_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
253  const Teuchos::ArrayView<global_ordinal_t> colind,
254  const Teuchos::ArrayView<global_size_t> rowptr,
255  global_size_t& nnz,
256  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
257  EStorage_Ordering ordering,
258  no_special_impl nsi) const;
259 
260  void do_getCrs(const Teuchos::ArrayView<scalar_t> nzval,
261  const Teuchos::ArrayView<global_ordinal_t> colind,
262  const Teuchos::ArrayView<global_size_t> rowptr,
263  global_size_t& nnz,
264  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > rowmap,
265  EStorage_Ordering ordering,
266  row_access ra) const;
267 
268  void do_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  EStorage_Ordering ordering,
274  col_access ca) const;
275 
276  void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
277  const Teuchos::ArrayView<global_ordinal_t> rowind,
278  const Teuchos::ArrayView<global_size_t> colptr,
279  global_size_t& nnz,
280  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
281  EStorage_Ordering ordering,
282  has_special_impl hsi) const;
283 
284  void help_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
285  const Teuchos::ArrayView<global_ordinal_t> rowind,
286  const Teuchos::ArrayView<global_size_t> colptr,
287  global_size_t& nnz,
288  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
289  EStorage_Ordering ordering,
290  no_special_impl nsi) const;
291 
292  void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
293  const Teuchos::ArrayView<global_ordinal_t> rowind,
294  const Teuchos::ArrayView<global_size_t> colptr,
295  global_size_t& nnz,
296  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
297  EStorage_Ordering ordering,
298  row_access ra) const;
299 
300  void do_getCcs(const Teuchos::ArrayView<scalar_t> nzval,
301  const Teuchos::ArrayView<global_ordinal_t> rowind,
302  const Teuchos::ArrayView<global_size_t> colptr,
303  global_size_t& nnz,
304  const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > colmap,
305  EStorage_Ordering ordering,
306  col_access ca) const;
307 
308  protected:
309  // These methods will link to concrete implementations, and may
310  // also be used by them
311 
318  void getGlobalRowCopy(global_ordinal_t row,
319  const Teuchos::ArrayView<global_ordinal_t>& indices,
320  const Teuchos::ArrayView<scalar_t>& vals,
321  size_t& nnz) const;
322 
329  void getGlobalColCopy(global_ordinal_t col,
330  const Teuchos::ArrayView<global_ordinal_t>& indices,
331  const Teuchos::ArrayView<scalar_t>& vals,
332  size_t& nnz) const;
333 
334  size_t getMaxRowNNZ() const;
335 
336  size_t getMaxColNNZ() const;
337 
338  size_t getGlobalRowNNZ(global_ordinal_t row) const;
339 
340  size_t getLocalRowNNZ(local_ordinal_t row) const;
341 
342  size_t getGlobalColNNZ(global_ordinal_t col) const;
343 
344  size_t getLocalColNNZ(local_ordinal_t col) const;
345 
346  bool isLocallyIndexed() const;
347 
348  bool isGloballyIndexed() const;
349 
350  protected:
351  const Teuchos::RCP<const Matrix> mat_;
352 
353  // only need to be mutable for the initial assignment, is there
354  // another way to do this?
355  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > row_map_;
356 
357  mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > col_map_;
358 
359  mutable Teuchos::RCP<const Teuchos::Comm<int> > comm_;
360 
361  }; // end class MatrixAdapter
362 
363 
364  // Factory creation method
365  template <class Matrix>
366  Teuchos::RCP<MatrixAdapter<Matrix> >
367  createMatrixAdapter(Teuchos::RCP<Matrix> m);
368 
369  template <class Matrix>
370  Teuchos::RCP<const MatrixAdapter<Matrix> >
371  createConstMatrixAdapter(Teuchos::RCP<const Matrix> m);
372 
373 } // end namespace Amesos2
374 
375 #endif // AMESOS2_MATRIXADAPTER_DECL_HPP
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) const
Gets a compressed-column storage summary of this.
global_size_t getGlobalNNZ() const
Get the global number of non-zeros in this sparse matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:155
Definition: Amesos2_TypeDecl.hpp:142
Utility functions for Amesos2.
EStorage_Ordering
Definition: Amesos2_TypeDecl.hpp:140
global_size_t getColumnIndexBase() const
Get the indexbase for the column map.
Definition: Amesos2_MatrixAdapter_def.hpp:148
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:458
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:193
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
size_t getLocalNumCols() const
Get the number of columns local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:169
size_t getLocalNumRows() const
Get the number of rows local to the calling process.
Definition: Amesos2_MatrixAdapter_def.hpp:162
const Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the Teuchos::Comm object associated with this matrix.
Definition: Amesos2_MatrixAdapter_decl.hpp:193
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:176
std::string description() const
Returns a short description of this Solver.
Definition: Amesos2_MatrixAdapter_def.hpp:183
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) const
Gets a compressed-row storage summary of this.
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:448
global_size_t getGlobalNumRows() const
Get the number of rows in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:127
global_size_t getGlobalNumCols() const
Get the number of columns in this matrix.
Definition: Amesos2_MatrixAdapter_def.hpp:134
EDistribution
Definition: Amesos2_TypeDecl.hpp:123
global_size_t getRowIndexBase() const
Get the indexbase for the row map.
Definition: Amesos2_MatrixAdapter_def.hpp:141