Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_TpetraCrsMatrix_MatrixAdapter_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Amesos2: Templated Direct Sparse Solver Package
4 //
5 // Copyright 2011 NTESS and the Amesos2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 
11 #ifndef AMESOS2_TPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
12 #define AMESOS2_TPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
13 
15 #include "Amesos2_TpetraRowMatrix_AbstractMatrixAdapter_def.hpp"
16 #include "Amesos2_MatrixAdapter_def.hpp"
17 
18 namespace Amesos2 {
19 
20  template <typename Scalar,
21  typename LocalOrdinal,
22  typename GlobalOrdinal,
23  typename Node>
24  ConcreteMatrixAdapter<
25  Tpetra::CrsMatrix<Scalar,
26  LocalOrdinal,
27  GlobalOrdinal,
28  Node>
29  >::ConcreteMatrixAdapter(Teuchos::RCP<matrix_t> m)
30  : AbstractConcreteMatrixAdapter<Tpetra::RowMatrix<Scalar,
31  LocalOrdinal,
32  GlobalOrdinal,
33  Node>,
34  Tpetra::CrsMatrix<Scalar,
35  LocalOrdinal,
36  GlobalOrdinal,
37  Node> >(m) // with implicit cast
38  {}
39 
40  template <typename Scalar,
41  typename LocalOrdinal,
42  typename GlobalOrdinal,
43  typename Node>
44  Teuchos::RCP<const MatrixAdapter<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > >
45  ConcreteMatrixAdapter<
46  Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>
47  >::get_impl(const Teuchos::Ptr<const Tpetra::Map<local_ordinal_t,global_ordinal_t,node_t> > map, EDistribution distribution) const
48  {
49  using Teuchos::RCP;
50  using Teuchos::rcp;
51  using Teuchos::rcpFromPtr;
52  typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_t;
53 
54  RCP<import_t> importer =
55  rcp (new import_t (this->getRowMap(), rcpFromPtr (map)));
56 
57  RCP<matrix_t> t_mat;
58 
59  t_mat = Tpetra::importAndFillCompleteCrsMatrix<matrix_t>( (this->mat_), *importer ); // DomainMap, RangeMap, params inputs default to Teuchos::null
60 
61  // Case for non-contiguous GIDs
62  if ( distribution == CONTIGUOUS_AND_ROOTED ) {
63 
64  auto myRank = map->getComm()->getRank();
65 
66  auto local_matrix = t_mat->getLocalMatrixDevice();
67  const size_t global_num_contiguous_entries = t_mat->getGlobalNumRows();
68  const size_t local_num_contiguous_entries = (myRank == 0) ? t_mat->getGlobalNumRows() : 0;
69 
70  //create maps
71  typedef Tpetra::Map< local_ordinal_t, global_ordinal_t, node_t> contiguous_map_type;
72  RCP<const contiguous_map_type> contiguousRowMap = rcp( new contiguous_map_type(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->getComm() ) ) );
73  RCP<const contiguous_map_type> contiguousColMap = rcp( new contiguous_map_type(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->getComm() ) ) );
74  RCP<const contiguous_map_type> contiguousDomainMap = rcp( new contiguous_map_type(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->getComm() ) ) );
75  RCP<const contiguous_map_type> contiguousRangeMap = rcp( new contiguous_map_type(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->getComm() ) ) );
76 
77  RCP<matrix_t> contiguous_t_mat = rcp( new matrix_t(contiguousRowMap, contiguousColMap, local_matrix) );
78  contiguous_t_mat->resumeFill();
79  contiguous_t_mat->expertStaticFillComplete(contiguousDomainMap, contiguousRangeMap);
80 
81  return rcp (new ConcreteMatrixAdapter<matrix_t> (contiguous_t_mat));
82  } //end if not contiguous
83 
84  return rcp (new ConcreteMatrixAdapter<matrix_t> (t_mat));
85  }
86 
87 } // end namespace Amesos2
88 
89 #endif // AMESOS2_TPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
Specialization of the ConcreteMatrixAdapter for Tpetra::CrsMatrix. Inherits all its functionality fro...
EDistribution
Definition: Amesos2_TypeDecl.hpp:89