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  return 0;
207  }
208 
209  template <typename Scalar,
210  typename LocalOrdinal,
211  typename GlobalOrdinal,
212  typename Node,
213  class DerivedMat>
214  size_t
215  AbstractConcreteMatrixAdapter<
216  Tpetra::RowMatrix<Scalar,
217  LocalOrdinal,
218  GlobalOrdinal,
219  Node>,
220  DerivedMat>::getGlobalRowNNZ_impl(global_ordinal_t row) const
221  {
222  return this->mat_->getNumEntriesInGlobalRow(row);
223  }
224 
225  template <typename Scalar,
226  typename LocalOrdinal,
227  typename GlobalOrdinal,
228  typename Node,
229  class DerivedMat>
230  size_t
231  AbstractConcreteMatrixAdapter<
232  Tpetra::RowMatrix<Scalar,
233  LocalOrdinal,
234  GlobalOrdinal,
235  Node>,
236  DerivedMat>::getLocalRowNNZ_impl(local_ordinal_t row) const
237  {
238  return this->mat_->getNumEntriesInLocalRow(row);
239  }
240 
241  template <typename Scalar,
242  typename LocalOrdinal,
243  typename GlobalOrdinal,
244  typename Node,
245  class DerivedMat>
246  size_t
247  AbstractConcreteMatrixAdapter<
248  Tpetra::RowMatrix<Scalar,
249  LocalOrdinal,
250  GlobalOrdinal,
251  Node>,
252  DerivedMat>::getGlobalColNNZ_impl(global_ordinal_t col) const
253  {
254  TEUCHOS_TEST_FOR_EXCEPTION( true,
255  std::runtime_error,
256  "Column access to row-based object not yet supported. "
257  "Please contact the Amesos2 developers." );
258  return 0;
259  }
260 
261  template <typename Scalar,
262  typename LocalOrdinal,
263  typename GlobalOrdinal,
264  typename Node,
265  class DerivedMat>
266  size_t
267  AbstractConcreteMatrixAdapter<
268  Tpetra::RowMatrix<Scalar,
269  LocalOrdinal,
270  GlobalOrdinal,
271  Node>,
272  DerivedMat>::getLocalColNNZ_impl(local_ordinal_t col) const
273  {
274  TEUCHOS_TEST_FOR_EXCEPTION( true,
275  std::runtime_error,
276  "Column access to row-based object not yet supported. "
277  "Please contact the Amesos2 developers." );
278  return 0;
279  }
280 
281  template <typename Scalar,
282  typename LocalOrdinal,
283  typename GlobalOrdinal,
284  typename Node,
285  class DerivedMat>
286  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
287  AbstractConcreteMatrixAdapter<
288  Tpetra::RowMatrix<Scalar,
289  LocalOrdinal,
290  GlobalOrdinal,
291  Node>,
292  DerivedMat>:: getRowMap_impl() const
293  {
294  return this->mat_->getRowMap();
295  }
296 
297  template <typename Scalar,
298  typename LocalOrdinal,
299  typename GlobalOrdinal,
300  typename Node,
301  class DerivedMat>
302  const RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
303  AbstractConcreteMatrixAdapter<
304  Tpetra::RowMatrix<Scalar,
305  LocalOrdinal,
306  GlobalOrdinal,
307  Node>,
308  DerivedMat>::getColMap_impl() const
309  {
310  return this->mat_->getColMap();
311  }
312 
313  template <typename Scalar,
314  typename LocalOrdinal,
315  typename GlobalOrdinal,
316  typename Node,
317  class DerivedMat>
318  const RCP<const Teuchos::Comm<int> >
319  AbstractConcreteMatrixAdapter<
320  Tpetra::RowMatrix<Scalar,
321  LocalOrdinal,
322  GlobalOrdinal,
323  Node>,
324  DerivedMat>::getComm_impl() const
325  {
326  return this->mat_->getComm();
327  }
328 
329  template <typename Scalar,
330  typename LocalOrdinal,
331  typename GlobalOrdinal,
332  typename Node,
333  class DerivedMat>
334  bool
335  AbstractConcreteMatrixAdapter<
336  Tpetra::RowMatrix<Scalar,
337  LocalOrdinal,
338  GlobalOrdinal,
339  Node>,
340  DerivedMat>::isLocallyIndexed_impl() const
341  {
342  return this->mat_->isLocallyIndexed();
343  }
344 
345  template <typename Scalar,
346  typename LocalOrdinal,
347  typename GlobalOrdinal,
348  typename Node,
349  class DerivedMat>
350  bool
351  AbstractConcreteMatrixAdapter<
352  Tpetra::RowMatrix<Scalar,
353  LocalOrdinal,
354  GlobalOrdinal,
355  Node>,
356  DerivedMat>::isGloballyIndexed_impl() const
357  {
358  return this->mat_->isGloballyIndexed();
359  }
360 
361  template <typename Scalar, typename LocalOrdinal, typename GlobalOrdinal, typename Node, class DerivedMat>
362  RCP<const MatrixAdapter<DerivedMat> >
363  AbstractConcreteMatrixAdapter<
364  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>, DerivedMat
365  >::get_impl(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map) const
366  {
367 #ifdef __CUDACC__
368  // NVCC doesn't seem to like the static_cast, even though it is valid
369  return dynamic_cast<ConcreteMatrixAdapter<DerivedMat>*>(this)->get_impl(map);
370 #else
371  return static_cast<ConcreteMatrixAdapter<DerivedMat>*>(this)->get_impl(map);
372 #endif
373  }
374 
375 } // end namespace Amesos2
376 
377 #endif // AMESOS2_TPETRAROWMATRIX_ABSTRACTMATRIXADAPTER_DEF_HPP
Definition: Amesos2_AbstractConcreteMatrixAdapter.hpp:48
Definition: Amesos2_Cholmod_TypeMap.hpp:92