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