Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_TpetraRowMatrix_AbstractMatrixAdapter_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Amesos2: Templated Direct Sparse Solver Package
4 //
5 // Copyright 2011 NTESS and the Amesos2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 
11 #ifndef AMESOS2_TPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
12 #define AMESOS2_TPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
13 
14 #include "Amesos2_ConcreteMatrixAdapter_decl.hpp"
15 #include "Amesos2_TpetraRowMatrix_AbstractMatrixAdapter_decl.hpp"
16 
17 namespace Amesos2 {
18 
19  using Teuchos::RCP;
20 
21  template <typename Scalar,
22  typename LocalOrdinal,
23  typename GlobalOrdinal,
24  typename Node,
25  class DerivedMat>
26  AbstractConcreteMatrixAdapter<
27  Tpetra::RowMatrix<Scalar,
28  LocalOrdinal,
29  GlobalOrdinal,
30  Node>,
31  DerivedMat>::AbstractConcreteMatrixAdapter(RCP<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > m)
32  : MatrixAdapter<DerivedMat>(Teuchos::rcp_static_cast<DerivedMat>(m))
33  {
34  // anything else? probs not
35  }
36 
37  // implementation functions
38  template <typename Scalar,
39  typename LocalOrdinal,
40  typename GlobalOrdinal,
41  typename Node,
42  class DerivedMat>
43  template <typename KV_GO, typename KV_S>
44  void
45  AbstractConcreteMatrixAdapter<
46  Tpetra::RowMatrix<Scalar,
47  LocalOrdinal,
48  GlobalOrdinal,
49  Node>,
50  DerivedMat>::getGlobalRowCopy_kokkos_view_impl(global_ordinal_t row,
51  KV_GO & indices,
52  KV_S & vals,
53  size_t& nnz) const
54  {
55  this->mat_->getGlobalRowCopy(row, indices, vals, nnz);
56  }
57 
58  template <typename Scalar,
59  typename LocalOrdinal,
60  typename GlobalOrdinal,
61  typename Node,
62  class DerivedMat>
63  typename AbstractConcreteMatrixAdapter<
64  Tpetra::RowMatrix<Scalar,
65  LocalOrdinal,
66  GlobalOrdinal,
67  Node>,
68  DerivedMat>::global_size_t
69  AbstractConcreteMatrixAdapter<
70  Tpetra::RowMatrix<Scalar,
71  LocalOrdinal,
72  GlobalOrdinal,
73  Node>,
74  DerivedMat>::getGlobalNNZ_impl() const
75  {
76  return this->mat_->getGlobalNumEntries();
77  }
78 
79  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
80  size_t
81  AbstractConcreteMatrixAdapter<
82  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
83  DerivedMat>::getLocalNNZ_impl() const
84  {
85  return this->mat_->getLocalNumEntries();
86  }
87 
88  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
89  typename AbstractConcreteMatrixAdapter<
90  Tpetra::RowMatrix<Scalar,
91  LocalOrdinal,
92  GlobalOrdinal,
93  Node>,
94  DerivedMat>::global_size_t
95  AbstractConcreteMatrixAdapter<
96  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
97  DerivedMat>::getGlobalNumRows_impl() const
98  {
99  return this->mat_->getGlobalNumRows();
100  }
101 
102  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
103  typename AbstractConcreteMatrixAdapter<
104  Tpetra::RowMatrix<Scalar,
105  LocalOrdinal,
106  GlobalOrdinal,
107  Node>,
108  DerivedMat>::global_size_t
109  AbstractConcreteMatrixAdapter<
110  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
111  DerivedMat>::getGlobalNumCols_impl() const
112  {
113  return this->mat_->getGlobalNumCols();
114  }
115 
116  template <typename Scalar,
117  typename LocalOrdinal,
118  typename GlobalOrdinal,
119  typename Node,
120  class DerivedMat>
121  size_t
122  AbstractConcreteMatrixAdapter<
123  Tpetra::RowMatrix<Scalar,
124  LocalOrdinal,
125  GlobalOrdinal,
126  Node>,
127  DerivedMat>::getMaxRowNNZ_impl() const
128  {
129  return this->mat_->getGlobalMaxNumRowEntries();
130  }
131 
132  template <typename Scalar,
133  typename LocalOrdinal,
134  typename GlobalOrdinal,
135  typename Node,
136  class DerivedMat>
137  size_t
138  AbstractConcreteMatrixAdapter<
139  Tpetra::RowMatrix<Scalar,
140  LocalOrdinal,
141  GlobalOrdinal,
142  Node>,
143  DerivedMat>::getMaxColNNZ_impl() const
144  {
145  TEUCHOS_TEST_FOR_EXCEPTION( true,
146  std::runtime_error,
147  "Column access to row-based object not yet supported. "
148  "Please contact the Amesos2 developers." );
149  }
150 
151  template <typename Scalar,
152  typename LocalOrdinal,
153  typename GlobalOrdinal,
154  typename Node,
155  class DerivedMat>
156  size_t
157  AbstractConcreteMatrixAdapter<
158  Tpetra::RowMatrix<Scalar,
159  LocalOrdinal,
160  GlobalOrdinal,
161  Node>,
162  DerivedMat>::getGlobalRowNNZ_impl(global_ordinal_t row) const
163  {
164  return this->mat_->getNumEntriesInGlobalRow(row);
165  }
166 
167  template <typename Scalar,
168  typename LocalOrdinal,
169  typename GlobalOrdinal,
170  typename Node,
171  class DerivedMat>
172  size_t
173  AbstractConcreteMatrixAdapter<
174  Tpetra::RowMatrix<Scalar,
175  LocalOrdinal,
176  GlobalOrdinal,
177  Node>,
178  DerivedMat>::getLocalRowNNZ_impl(local_ordinal_t row) const
179  {
180  return this->mat_->getNumEntriesInLocalRow(row);
181  }
182 
183  template <typename Scalar,
184  typename LocalOrdinal,
185  typename GlobalOrdinal,
186  typename Node,
187  class DerivedMat>
188  size_t
189  AbstractConcreteMatrixAdapter<
190  Tpetra::RowMatrix<Scalar,
191  LocalOrdinal,
192  GlobalOrdinal,
193  Node>,
194  DerivedMat>::getGlobalColNNZ_impl(global_ordinal_t col) const
195  {
196  TEUCHOS_TEST_FOR_EXCEPTION( true,
197  std::runtime_error,
198  "Column access to row-based object not yet supported. "
199  "Please contact the Amesos2 developers." );
200  }
201 
202  template <typename Scalar,
203  typename LocalOrdinal,
204  typename GlobalOrdinal,
205  typename Node,
206  class DerivedMat>
207  size_t
208  AbstractConcreteMatrixAdapter<
209  Tpetra::RowMatrix<Scalar,
210  LocalOrdinal,
211  GlobalOrdinal,
212  Node>,
213  DerivedMat>::getLocalColNNZ_impl(local_ordinal_t col) const
214  {
215  TEUCHOS_TEST_FOR_EXCEPTION( true,
216  std::runtime_error,
217  "Column access to row-based object not yet supported. "
218  "Please contact the Amesos2 developers." );
219  }
220 
221  template <typename Scalar,
222  typename LocalOrdinal,
223  typename GlobalOrdinal,
224  typename Node,
225  class DerivedMat>
226  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
227  AbstractConcreteMatrixAdapter<
228  Tpetra::RowMatrix<Scalar,
229  LocalOrdinal,
230  GlobalOrdinal,
231  Node>,
232  DerivedMat>:: getMap_impl() const
233  {
234  return this->mat_->getMap();
235  }
236 
237  template <typename Scalar,
238  typename LocalOrdinal,
239  typename GlobalOrdinal,
240  typename Node,
241  class DerivedMat>
242  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
243  AbstractConcreteMatrixAdapter<
244  Tpetra::RowMatrix<Scalar,
245  LocalOrdinal,
246  GlobalOrdinal,
247  Node>,
248  DerivedMat>:: getRowMap_impl() const
249  {
250  return this->mat_->getRowMap();
251  }
252 
253  template <typename Scalar,
254  typename LocalOrdinal,
255  typename GlobalOrdinal,
256  typename Node,
257  class DerivedMat>
258  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
259  AbstractConcreteMatrixAdapter<
260  Tpetra::RowMatrix<Scalar,
261  LocalOrdinal,
262  GlobalOrdinal,
263  Node>,
264  DerivedMat>::getColMap_impl() const
265  {
266  return this->mat_->getColMap();
267  }
268 
269  template <typename Scalar,
270  typename LocalOrdinal,
271  typename GlobalOrdinal,
272  typename Node,
273  class DerivedMat>
274  const RCP<const Teuchos::Comm<int> >
275  AbstractConcreteMatrixAdapter<
276  Tpetra::RowMatrix<Scalar,
277  LocalOrdinal,
278  GlobalOrdinal,
279  Node>,
280  DerivedMat>::getComm_impl() const
281  {
282  return this->mat_->getComm();
283  }
284 
285  template <typename Scalar,
286  typename LocalOrdinal,
287  typename GlobalOrdinal,
288  typename Node,
289  class DerivedMat>
290  bool
291  AbstractConcreteMatrixAdapter<
292  Tpetra::RowMatrix<Scalar,
293  LocalOrdinal,
294  GlobalOrdinal,
295  Node>,
296  DerivedMat>::isLocallyIndexed_impl() const
297  {
298  return this->mat_->isLocallyIndexed();
299  }
300 
301  template <typename Scalar,
302  typename LocalOrdinal,
303  typename GlobalOrdinal,
304  typename Node,
305  class DerivedMat>
306  bool
307  AbstractConcreteMatrixAdapter<
308  Tpetra::RowMatrix<Scalar,
309  LocalOrdinal,
310  GlobalOrdinal,
311  Node>,
312  DerivedMat>::isGloballyIndexed_impl() const
313  {
314  return this->mat_->isGloballyIndexed();
315  }
316 
317 
318  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
319  RCP<const MatrixAdapter<DerivedMat> >
320  AbstractConcreteMatrixAdapter<
321  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>, DerivedMat
322  >::get_impl(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution) const
323  {
324 #ifdef __CUDACC__
325  // NVCC doesn't seem to like the static_cast, even though it is valid
326  return dynamic_cast<ConcreteMatrixAdapter<DerivedMat>*>(this)->get_impl(map, distribution);
327 #else
328  return static_cast<ConcreteMatrixAdapter<DerivedMat>*>(this)->get_impl(map, distribution);
329 #endif
330  }
331 
332 } // end namespace Amesos2
333 
334 #endif // AMESOS2_TPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
EDistribution
Definition: Amesos2_TypeDecl.hpp:89