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  using Teuchos::ArrayView;
55 
56  template <typename Scalar,
57  typename LocalOrdinal,
58  typename GlobalOrdinal,
59  typename Node,
60  class DerivedMat>
61  AbstractConcreteMatrixAdapter<
62  Tpetra::RowMatrix<Scalar,
63  LocalOrdinal,
64  GlobalOrdinal,
65  Node>,
66  DerivedMat>::AbstractConcreteMatrixAdapter(RCP<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > m)
67  : MatrixAdapter<DerivedMat>(Teuchos::rcp_static_cast<DerivedMat>(m))
68  {
69  // anything else? probs not
70  }
71 
72  // implementation functions
73  template <typename Scalar,
74  typename LocalOrdinal,
75  typename GlobalOrdinal,
76  typename Node,
77  class DerivedMat>
78  void
79  AbstractConcreteMatrixAdapter<
80  Tpetra::RowMatrix<Scalar,
81  LocalOrdinal,
82  GlobalOrdinal,
83  Node>,
84  DerivedMat>::getGlobalRowCopy_impl(global_ordinal_t row,
85  const ArrayView<global_ordinal_t>& indices,
86  const ArrayView<scalar_t>& 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  void
98  AbstractConcreteMatrixAdapter<
99  Tpetra::RowMatrix<Scalar,
100  LocalOrdinal,
101  GlobalOrdinal,
102  Node>,
103  DerivedMat>::getGlobalColCopy_impl(global_ordinal_t col,
104  const ArrayView<global_ordinal_t>& indices,
105  const ArrayView<scalar_t>& vals,
106  size_t& nnz) const
107  {
108  TEUCHOS_TEST_FOR_EXCEPTION( true,
109  std::runtime_error,
110  "Column access to row-based object not yet supported. "
111  "Please contact the Amesos2 developers." );
112  }
113 
114 
115  template <typename Scalar,
116  typename LocalOrdinal,
117  typename GlobalOrdinal,
118  typename Node,
119  class DerivedMat>
120  typename AbstractConcreteMatrixAdapter<
121  Tpetra::RowMatrix<Scalar,
122  LocalOrdinal,
123  GlobalOrdinal,
124  Node>,
125  DerivedMat>::global_size_t
126  AbstractConcreteMatrixAdapter<
127  Tpetra::RowMatrix<Scalar,
128  LocalOrdinal,
129  GlobalOrdinal,
130  Node>,
131  DerivedMat>::getGlobalNNZ_impl() const
132  {
133  return this->mat_->getGlobalNumEntries();
134  }
135 
136  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
137  size_t
138  AbstractConcreteMatrixAdapter<
139  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
140  DerivedMat>::getLocalNNZ_impl() const
141  {
142  return this->mat_->getNodeNumEntries();
143  }
144 
145  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
146  typename AbstractConcreteMatrixAdapter<
147  Tpetra::RowMatrix<Scalar,
148  LocalOrdinal,
149  GlobalOrdinal,
150  Node>,
151  DerivedMat>::global_size_t
152  AbstractConcreteMatrixAdapter<
153  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
154  DerivedMat>::getGlobalNumRows_impl() const
155  {
156  return this->mat_->getGlobalNumRows();
157  }
158 
159  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
160  typename AbstractConcreteMatrixAdapter<
161  Tpetra::RowMatrix<Scalar,
162  LocalOrdinal,
163  GlobalOrdinal,
164  Node>,
165  DerivedMat>::global_size_t
166  AbstractConcreteMatrixAdapter<
167  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
168  DerivedMat>::getGlobalNumCols_impl() const
169  {
170  return this->mat_->getGlobalNumCols();
171  }
172 
173  template <typename Scalar,
174  typename LocalOrdinal,
175  typename GlobalOrdinal,
176  typename Node,
177  class DerivedMat>
178  size_t
179  AbstractConcreteMatrixAdapter<
180  Tpetra::RowMatrix<Scalar,
181  LocalOrdinal,
182  GlobalOrdinal,
183  Node>,
184  DerivedMat>::getMaxRowNNZ_impl() const
185  {
186  return this->mat_->getGlobalMaxNumRowEntries();
187  }
188 
189  template <typename Scalar,
190  typename LocalOrdinal,
191  typename GlobalOrdinal,
192  typename Node,
193  class DerivedMat>
194  size_t
195  AbstractConcreteMatrixAdapter<
196  Tpetra::RowMatrix<Scalar,
197  LocalOrdinal,
198  GlobalOrdinal,
199  Node>,
200  DerivedMat>::getMaxColNNZ_impl() const
201  {
202  TEUCHOS_TEST_FOR_EXCEPTION( true,
203  std::runtime_error,
204  "Column access to row-based object not yet supported. "
205  "Please contact the Amesos2 developers." );
206  }
207 
208  template <typename Scalar,
209  typename LocalOrdinal,
210  typename GlobalOrdinal,
211  typename Node,
212  class DerivedMat>
213  size_t
214  AbstractConcreteMatrixAdapter<
215  Tpetra::RowMatrix<Scalar,
216  LocalOrdinal,
217  GlobalOrdinal,
218  Node>,
219  DerivedMat>::getGlobalRowNNZ_impl(global_ordinal_t row) const
220  {
221  return this->mat_->getNumEntriesInGlobalRow(row);
222  }
223 
224 
225  template <typename Scalar,
226  typename LocalOrdinal,
227  typename GlobalOrdinal,
228  typename Node,
229  class DerivedMat>
230  typename
231  AbstractConcreteMatrixAdapter<
232  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>, DerivedMat>
233  ::super_t::spmtx_ptr_t
234  AbstractConcreteMatrixAdapter<
235  Tpetra::RowMatrix<Scalar,
236  LocalOrdinal,
237  GlobalOrdinal,
238  Node>,
239  DerivedMat>::getSparseRowPtr() const
240  {
241  typename super_t::local_matrix_t lm = this->mat_->getLocalMatrix();
242  return lm.graph.row_map.data();
243  }
244 
245  template <typename Scalar,
246  typename LocalOrdinal,
247  typename GlobalOrdinal,
248  typename Node,
249  class DerivedMat>
250  typename
251  AbstractConcreteMatrixAdapter<
252  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>, DerivedMat>
253  ::super_t::spmtx_idx_t
254  AbstractConcreteMatrixAdapter<
255  Tpetra::RowMatrix<Scalar,
256  LocalOrdinal,
257  GlobalOrdinal,
258  Node>,
259  DerivedMat>::getSparseColInd() const
260  {
261  typename super_t::local_matrix_t lm = this->mat_->getLocalMatrix();
262  return lm.graph.entries.data();
263  }
264 
265  template <typename Scalar,
266  typename LocalOrdinal,
267  typename GlobalOrdinal,
268  typename Node,
269  class DerivedMat>
270  typename
271  AbstractConcreteMatrixAdapter<
272  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>, DerivedMat>
273  ::super_t::spmtx_vals_t
274  AbstractConcreteMatrixAdapter<
275  Tpetra::RowMatrix<Scalar,
276  LocalOrdinal,
277  GlobalOrdinal,
278  Node>,
279  DerivedMat>::getSparseValues() const
280  {
281  typename super_t::local_matrix_t lm = this->mat_->getLocalMatrix();
282  return lm.values.data();
283  }
284 
285 
286  template <typename Scalar,
287  typename LocalOrdinal,
288  typename GlobalOrdinal,
289  typename Node,
290  class DerivedMat>
291  size_t
292  AbstractConcreteMatrixAdapter<
293  Tpetra::RowMatrix<Scalar,
294  LocalOrdinal,
295  GlobalOrdinal,
296  Node>,
297  DerivedMat>::getLocalRowNNZ_impl(local_ordinal_t row) const
298  {
299  return this->mat_->getNumEntriesInLocalRow(row);
300  }
301 
302  template <typename Scalar,
303  typename LocalOrdinal,
304  typename GlobalOrdinal,
305  typename Node,
306  class DerivedMat>
307  size_t
308  AbstractConcreteMatrixAdapter<
309  Tpetra::RowMatrix<Scalar,
310  LocalOrdinal,
311  GlobalOrdinal,
312  Node>,
313  DerivedMat>::getGlobalColNNZ_impl(global_ordinal_t col) const
314  {
315  TEUCHOS_TEST_FOR_EXCEPTION( true,
316  std::runtime_error,
317  "Column access to row-based object not yet supported. "
318  "Please contact the Amesos2 developers." );
319  }
320 
321  template <typename Scalar,
322  typename LocalOrdinal,
323  typename GlobalOrdinal,
324  typename Node,
325  class DerivedMat>
326  size_t
327  AbstractConcreteMatrixAdapter<
328  Tpetra::RowMatrix<Scalar,
329  LocalOrdinal,
330  GlobalOrdinal,
331  Node>,
332  DerivedMat>::getLocalColNNZ_impl(local_ordinal_t col) const
333  {
334  TEUCHOS_TEST_FOR_EXCEPTION( true,
335  std::runtime_error,
336  "Column access to row-based object not yet supported. "
337  "Please contact the Amesos2 developers." );
338  }
339 
340  template <typename Scalar,
341  typename LocalOrdinal,
342  typename GlobalOrdinal,
343  typename Node,
344  class DerivedMat>
345  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
346  AbstractConcreteMatrixAdapter<
347  Tpetra::RowMatrix<Scalar,
348  LocalOrdinal,
349  GlobalOrdinal,
350  Node>,
351  DerivedMat>:: getMap_impl() const
352  {
353  return this->mat_->getMap();
354  }
355 
356  template <typename Scalar,
357  typename LocalOrdinal,
358  typename GlobalOrdinal,
359  typename Node,
360  class DerivedMat>
361  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
362  AbstractConcreteMatrixAdapter<
363  Tpetra::RowMatrix<Scalar,
364  LocalOrdinal,
365  GlobalOrdinal,
366  Node>,
367  DerivedMat>:: getRowMap_impl() const
368  {
369  return this->mat_->getRowMap();
370  }
371 
372  template <typename Scalar,
373  typename LocalOrdinal,
374  typename GlobalOrdinal,
375  typename Node,
376  class DerivedMat>
377  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
378  AbstractConcreteMatrixAdapter<
379  Tpetra::RowMatrix<Scalar,
380  LocalOrdinal,
381  GlobalOrdinal,
382  Node>,
383  DerivedMat>::getColMap_impl() const
384  {
385  return this->mat_->getColMap();
386  }
387 
388  template <typename Scalar,
389  typename LocalOrdinal,
390  typename GlobalOrdinal,
391  typename Node,
392  class DerivedMat>
393  const RCP<const Teuchos::Comm<int> >
394  AbstractConcreteMatrixAdapter<
395  Tpetra::RowMatrix<Scalar,
396  LocalOrdinal,
397  GlobalOrdinal,
398  Node>,
399  DerivedMat>::getComm_impl() const
400  {
401  return this->mat_->getComm();
402  }
403 
404  template <typename Scalar,
405  typename LocalOrdinal,
406  typename GlobalOrdinal,
407  typename Node,
408  class DerivedMat>
409  bool
410  AbstractConcreteMatrixAdapter<
411  Tpetra::RowMatrix<Scalar,
412  LocalOrdinal,
413  GlobalOrdinal,
414  Node>,
415  DerivedMat>::isLocallyIndexed_impl() const
416  {
417  return this->mat_->isLocallyIndexed();
418  }
419 
420  template <typename Scalar,
421  typename LocalOrdinal,
422  typename GlobalOrdinal,
423  typename Node,
424  class DerivedMat>
425  bool
426  AbstractConcreteMatrixAdapter<
427  Tpetra::RowMatrix<Scalar,
428  LocalOrdinal,
429  GlobalOrdinal,
430  Node>,
431  DerivedMat>::isGloballyIndexed_impl() const
432  {
433  return this->mat_->isGloballyIndexed();
434  }
435 
436 
437  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
438  RCP<const MatrixAdapter<DerivedMat> >
439  AbstractConcreteMatrixAdapter<
440  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>, DerivedMat
441  >::get_impl(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution) const
442  {
443 #ifdef __CUDACC__
444  // NVCC doesn't seem to like the static_cast, even though it is valid
445  return dynamic_cast<ConcreteMatrixAdapter<DerivedMat>*>(this)->get_impl(map, distribution);
446 #else
447  return static_cast<ConcreteMatrixAdapter<DerivedMat>*>(this)->get_impl(map, distribution);
448 #endif
449  }
450 
451 } // end namespace Amesos2
452 
453 #endif // AMESOS2_TPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
EDistribution
Definition: Amesos2_TypeDecl.hpp:123