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