11 #ifndef AMESOS2_TPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
12 #define AMESOS2_TPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
15 #include "Amesos2_TpetraRowMatrix_AbstractMatrixAdapter_def.hpp"
16 #include "Amesos2_MatrixAdapter_def.hpp"
20 template <
typename Scalar,
21 typename LocalOrdinal,
22 typename GlobalOrdinal,
24 ConcreteMatrixAdapter<
25 Tpetra::CrsMatrix<Scalar,
29 >::ConcreteMatrixAdapter(Teuchos::RCP<matrix_t> m)
30 : AbstractConcreteMatrixAdapter<Tpetra::RowMatrix<Scalar,
34 Tpetra::CrsMatrix<Scalar,
40 template <
typename Scalar,
41 typename LocalOrdinal,
42 typename GlobalOrdinal,
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 map_t> map,
EDistribution distribution)
const
51 using Teuchos::rcpFromPtr;
52 typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_t;
54 RCP<import_t> importer =
55 rcp (
new import_t (this->getRowMap(), rcpFromPtr (map)));
59 t_mat = Tpetra::importAndFillCompleteCrsMatrix<matrix_t>( (this->mat_), *importer );
62 if ( distribution == CONTIGUOUS_AND_ROOTED ) {
64 auto myRank = map->getComm()->getRank();
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;
72 RCP<const map_t> contiguousRowMap = rcp(
new map_t(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->getComm() ) ) );
73 RCP<const map_t> contiguousColMap = rcp(
new map_t(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->getComm() ) ) );
74 RCP<const map_t> contiguousDomainMap = rcp(
new map_t(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->getComm() ) ) );
75 RCP<const map_t> contiguousRangeMap = rcp(
new map_t(global_num_contiguous_entries, local_num_contiguous_entries, 0, (t_mat->getComm() ) ) );
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);
81 return rcp (
new ConcreteMatrixAdapter<matrix_t> (contiguous_t_mat));
84 return rcp (
new ConcreteMatrixAdapter<matrix_t> (t_mat));
89 template <
typename Scalar,
90 typename LocalOrdinal,
91 typename GlobalOrdinal,
93 Teuchos::RCP<const MatrixAdapter<Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > >
94 ConcreteMatrixAdapter<
95 Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>
96 >::reindex_impl(Teuchos::RCP<const map_t> &contigRowMap,
97 Teuchos::RCP<const map_t> &contigColMap)
const
99 typedef Tpetra::Map< local_ordinal_t, global_ordinal_t, node_t> contiguous_map_type;
100 auto rowMap = this->mat_->getRowMap();
101 auto colMap = this->mat_->getColMap();
102 auto rowComm = rowMap->getComm();
103 auto colComm = colMap->getComm();
105 #ifdef HAVE_AMESOS2_TIMERS
106 auto reindexTimer = Teuchos::TimeMonitor::getNewTimer(
"Time to re-index matrix gids");
107 Teuchos::TimeMonitor ReindexTimer(*reindexTimer);
110 global_ordinal_t indexBase = rowMap->getIndexBase();
111 global_ordinal_t numDoFs = this->mat_->getGlobalNumRows();
112 local_ordinal_t nRows = this->mat_->getLocalNumRows();
113 local_ordinal_t nCols = colMap->getLocalNumElements();
115 RCP<matrix_t> contiguous_t_mat;
118 if (contigRowMap->getGlobalNumElements() != numDoFs || contigColMap->getGlobalNumElements() != numDoFs) {
119 auto tmpMap = rcp (
new contiguous_map_type (numDoFs, nRows, indexBase, rowComm));
120 global_ordinal_t frow = tmpMap->getMinGlobalIndex();
123 typedef Kokkos::DefaultHostExecutionSpace HostExecSpaceType;
124 Kokkos::View<global_ordinal_t*, HostExecSpaceType> rowIndexList (
"indexList", nRows);
125 for (local_ordinal_t k = 0; k < nRows; k++) {
126 rowIndexList(k) = frow+k;
129 Kokkos::View<global_ordinal_t*, HostExecSpaceType> colIndexList (
"indexList", nCols);
130 typedef Tpetra::MultiVector<global_ordinal_t,
134 Teuchos::ArrayView<const global_ordinal_t> rowIndexArray(rowIndexList.data(), nRows);
135 Teuchos::ArrayView<const global_ordinal_t> colIndexArray(colIndexList.data(), nCols);
136 gid_mv_t row_mv (rowMap, rowIndexArray, nRows, 1);
137 gid_mv_t col_mv (colMap, colIndexArray, nCols, 1);
138 typedef Tpetra::Import<local_ordinal_t, global_ordinal_t, node_t> import_t;
139 RCP<import_t> importer = rcp (
new import_t (rowMap, colMap));
140 col_mv.doImport (row_mv, *importer, Tpetra::INSERT);
142 auto col_view = col_mv.getLocalViewHost(Tpetra::Access::ReadOnly);
143 for(
int i=0; i<nCols; i++) colIndexList(i) = col_view(i,0);
146 contigRowMap = rcp (
new contiguous_map_type (numDoFs, rowIndexList.data(), nRows, indexBase, rowComm));
147 contigColMap = rcp (
new contiguous_map_type (numDoFs, colIndexList.data(), nCols, indexBase, colComm));
150 auto lclMatrix = this->mat_->getLocalMatrixDevice();
151 contiguous_t_mat = rcp(
new matrix_t(contigRowMap, contigColMap, lclMatrix));
154 auto lclMatrix = this->mat_->getLocalMatrixDevice();
155 auto importer = this->mat_->getCrsGraph()->getImporter();
156 auto exporter = this->mat_->getCrsGraph()->getExporter();
157 contiguous_t_mat = rcp(
new matrix_t(lclMatrix, contigRowMap, contigColMap, contigRowMap, contigColMap, importer,exporter));
159 return rcp (
new ConcreteMatrixAdapter<matrix_t> (contiguous_t_mat));
162 template <
typename Scalar,
163 typename LocalOrdinal,
164 typename GlobalOrdinal,
167 ConcreteMatrixAdapter<
168 Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>
169 >::describe (Teuchos::FancyOStream& os,
170 const Teuchos::EVerbosityLevel verbLevel)
const
172 this->mat_->describe(os, verbLevel);
176 #endif // AMESOS2_TPETRACRSMATRIX_MATRIXADAPTER_DEF_HPP
Specialization of the ConcreteMatrixAdapter for Tpetra::CrsMatrix. Inherits all its functionality fro...
EDistribution
Definition: Amesos2_TypeDecl.hpp:89