Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_EpetraRowMatrix_AbstractMatrixAdapter_decl.hpp
Go to the documentation of this file.
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 
55 #ifndef AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
56 #define AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
57 
58 #include "Amesos2_config.h"
59 
60 #include <Teuchos_ArrayView.hpp>
61 
62 #include <Epetra_RowMatrix.h>
63 
64 #include "Amesos2_AbstractConcreteMatrixAdapter.hpp"
65 #include "Amesos2_MatrixAdapter_decl.hpp"
66 #include "Amesos2_MatrixTraits.hpp"
67 #include "Amesos2_Util.hpp"
69 
70 namespace Amesos2 {
71 
72  using Teuchos::RCP;
73 
88  template < class DerivedMat >
89  class AbstractConcreteMatrixAdapter< Epetra_RowMatrix, DerivedMat >
90  : public MatrixAdapter< DerivedMat > {
91  public:
92  // Give our base class access to our private implementation functions
93  friend class MatrixAdapter< DerivedMat >;
94 
95  typedef MatrixTraits<Epetra_RowMatrix>::scalar_t scalar_t;
96  typedef MatrixTraits<Epetra_RowMatrix>::local_ordinal_t local_ordinal_t;
97  typedef MatrixTraits<Epetra_RowMatrix>::global_ordinal_t global_ordinal_t;
98  typedef MatrixTraits<Epetra_RowMatrix>::node_t node_t;
99 
100  typedef DerivedMat matrix_t;
101 
102  private:
104 
105  public:
106  typedef typename super_t::global_size_t global_size_t;
107 
109 
110  // subclasses should override these typedef's in case of specialization
113  typedef MatrixTraits<Epetra_RowMatrix>::major_access major_access;
114 
115  AbstractConcreteMatrixAdapter(RCP<matrix_t> m);
116 
117  public: // these functions should technically be private
118 
119  // implementation functions
120  void getGlobalRowCopy_impl(global_ordinal_t row,
121  const Teuchos::ArrayView<global_ordinal_t>& indices,
122  const Teuchos::ArrayView<scalar_t>& vals,
123  size_t& nnz) const;
124 
125  void getGlobalColCopy_impl(global_ordinal_t col,
126  const Teuchos::ArrayView<global_ordinal_t>& indices,
127  const Teuchos::ArrayView<scalar_t>& vals,
128  size_t& nnz) const;
129 
130  global_size_t getGlobalNNZ_impl() const;
131 
132  size_t getLocalNNZ_impl() const;
133 
134  global_size_t getGlobalNumRows_impl() const;
135 
136  global_size_t getGlobalNumCols_impl() const;
137 
138  size_t getMaxRowNNZ_impl() const;
139 
140  size_t getMaxColNNZ_impl() const;
141 
142  size_t getGlobalRowNNZ_impl(global_ordinal_t row) const;
143 
144  size_t getLocalRowNNZ_impl(local_ordinal_t row) const;
145 
146  size_t getGlobalColNNZ_impl(global_ordinal_t col) const;
147 
148  size_t getLocalColNNZ_impl(local_ordinal_t col) const;
149 
150  // Brunt of the work is put on the implementation for converting
151  // their maps to a Tpetra::Map
152  const RCP<const Tpetra::Map<local_ordinal_t,
153  global_ordinal_t,
154  node_t> >
155  getMap_impl() const;
156 
157  const RCP<const Tpetra::Map<local_ordinal_t,
158  global_ordinal_t,
159  node_t> >
160  getRowMap_impl() const;
161 
162  const RCP<const Tpetra::Map<local_ordinal_t,
163  global_ordinal_t,
164  node_t> >
165  getColMap_impl() const;
166 
167  const RCP<const Teuchos::Comm<int> > getComm_impl() const;
168 
169  bool isLocallyIndexed_impl() const;
170 
171  bool isGloballyIndexed_impl() const;
172 
173  // Because instantiation of the subclasses could be wildly
174  // different (cf subclasses of Epetra_RowMatrix), this method
175  // hands off implementation to the adapter for the subclass
176  RCP<const super_t> get_impl(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution = ROOTED) const;
177 
178  typename super_t::spmtx_ptr_t getSparseRowPtr() const;
179 
180  typename super_t::spmtx_idx_t getSparseColInd() const;
181 
182  typename super_t::spmtx_vals_t getSparseValues() const;
183 
184  template<class KV>
185  void getSparseRowPtr_kokkos_view(KV & view) const {
186  Kokkos::View<typename super_t::spmtx_ptr_t, Kokkos::HostSpace> src(
187  getSparseRowPtr(), getGlobalNumRows_impl()+1);
188  deep_copy_or_assign_view(view, src);
189  }
190 
191  template<class KV>
192  void getSparseColInd_kokkos_view(KV & view) const {
193  Kokkos::View<typename super_t::spmtx_idx_t, Kokkos::HostSpace> src(
194  getSparseColInd(), getGlobalNNZ_impl());
195  deep_copy_or_assign_view(view, src);
196  }
197 
198  template<class KV>
199  void getSparseValues_kokkos_view(KV & view) const {
200  Kokkos::View<typename super_t::spmtx_vals_t, Kokkos::HostSpace> src(
201  getSparseValues(), getGlobalNNZ_impl());
202  deep_copy_or_assign_view(view, src);
203  }
204 
205  };
206 
207 } // end namespace Amesos2
208 
209 #endif // AMESOS2_EPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DECL_HPP
Utility functions for Amesos2.
Copy or assign views based on memory spaces.
A Matrix adapter interface for Amesos2.
Definition: Amesos2_MatrixAdapter_decl.hpp:76
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:89
Indicates that the concrete class can use the generic getC{c|r}s methods implemented in MatrixAdapter...
Definition: Amesos2_TypeDecl.hpp:91
EDistribution
Definition: Amesos2_TypeDecl.hpp:123