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