42 #ifndef TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP 43 #define TPETRA_ROWMATRIXTRANSPOSER_DEF_HPP 46 #include <Tpetra_CrsMatrix.hpp> 47 #include <Tpetra_Export.hpp> 48 #include <Tpetra_Import.hpp> 49 #include <Teuchos_TimeMonitor.hpp> 53 template<
class Scalar,
59 : origMatrix_(origMatrix), label_(label) {}
61 template<
class Scalar,
65 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
70 #ifdef HAVE_TPETRA_MMM_TIMINGS 71 std::string prefix = std::string(
"Tpetra ")+ label_ + std::string(
": ");
72 using Teuchos::TimeMonitor;
73 Teuchos::RCP<Teuchos::TimeMonitor> MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix + std::string(
"Transpose Local"))));
76 RCP<crs_matrix_type> transMatrixWithSharedRows = createTransposeLocal ();
78 #ifdef HAVE_TPETRA_MMM_TIMINGS 79 MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix + std::string(
"Transpose TAFC"))));
85 RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > exporter =
86 transMatrixWithSharedRows->getGraph ()->getExporter ();
87 if (exporter.is_null ()) {
88 return transMatrixWithSharedRows;
91 Teuchos::ParameterList labelList;
92 #ifdef HAVE_TPETRA_MMM_TIMINGS 93 labelList.set(
"Timer Label",label_);
96 return exportAndFillCompleteCrsMatrix<crs_matrix_type> (transMatrixWithSharedRows, *exporter,Teuchos::null,Teuchos::null,Teuchos::rcp(&labelList,
false));
105 template<
class Scalar,
109 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
113 using Teuchos::Array;
114 using Teuchos::ArrayRCP;
115 using Teuchos::ArrayView;
118 using Teuchos::rcp_dynamic_cast;
119 typedef LocalOrdinal LO;
120 typedef GlobalOrdinal GO;
127 size_t numLocalCols = origMatrix_->getNodeNumCols();
128 size_t numLocalRows = origMatrix_->getNodeNumRows();
129 size_t numLocalNnz = origMatrix_->getNodeNumEntries();
132 Array<size_t> CurrentStart(numLocalCols,0);
133 ArrayView<const LO> localIndices;
134 ArrayView<const Scalar> localValues;
135 RCP<const crs_matrix_type> crsMatrix =
137 if (crsMatrix == Teuchos::null) {
138 for (
size_t i=0; i<numLocalRows; ++i) {
140 origMatrix_->getLocalRowView(i, localIndices, localValues);
141 for (
size_t j=0; j<numEntriesInRow; ++j) {
142 ++CurrentStart[ localIndices[j] ];
146 ArrayRCP<const size_t> origRowPtr_rcp;
147 ArrayRCP<const LO> origColInd_rcp;
148 ArrayRCP<const Scalar> origValues_rcp;
149 crsMatrix->getAllValues(origRowPtr_rcp, origColInd_rcp, origValues_rcp);
150 ArrayView<const LO> origColInd = origColInd_rcp();
151 for (LO j=0; j<origColInd.size(); ++j) {
152 ++CurrentStart[ origColInd[j] ];
158 ArrayRCP<size_t> rowptr_rcp(numLocalCols+1);
159 ArrayRCP<LO> colind_rcp(numLocalNnz);
160 ArrayRCP<Scalar> values_rcp(numLocalNnz);
163 ArrayView<size_t> TransRowptr = rowptr_rcp();
164 ArrayView<LO> TransColind = colind_rcp();
165 ArrayView<Scalar> TransValues = values_rcp();
169 for (
size_t i=1; i<numLocalCols+1; ++i) TransRowptr[i] = CurrentStart[i-1] + TransRowptr[i-1];
170 for (
size_t i=0; i<numLocalCols; ++i) CurrentStart[i] = TransRowptr[i];
174 if (crsMatrix == Teuchos::null) {
175 for (
size_t i=0; i<numLocalRows; ++i) {
176 const size_t numEntriesInRow = origMatrix_->getNumEntriesInLocalRow (i);
177 origMatrix_->getLocalRowView(i, localIndices, localValues);
179 for (
size_t j=0; j<numEntriesInRow; ++j) {
180 size_t idx = CurrentStart[localIndices[j]];
181 TransColind[idx] = Teuchos::as<LO>(i);
182 TransValues[idx] = localValues[j];
183 ++CurrentStart[localIndices[j]];
187 ArrayRCP<const size_t> origRowPtr_rcp;
188 ArrayRCP<const LO> origColInd_rcp;
189 ArrayRCP<const Scalar> origValues_rcp;
190 crsMatrix->getAllValues(origRowPtr_rcp, origColInd_rcp, origValues_rcp);
191 ArrayView<const size_t> origRowPtr = origRowPtr_rcp();
192 ArrayView<const LO> origColInd = origColInd_rcp();
193 ArrayView<const Scalar> origValues = origValues_rcp();
195 for (LO i=0; i<origRowPtr.size()-1; ++i) {
196 const LO rowIndex = Teuchos::as<LO>(i);
197 size_t rowStart = origRowPtr[i], rowEnd = origRowPtr[i+1];
198 for (
size_t j = rowStart; j < rowEnd; ++j) {
199 size_t idx = CurrentStart[origColInd[k]];
200 TransColind[idx] = rowIndex;
201 TransValues[idx] = origValues[k];
202 ++CurrentStart[origColInd[k++]];
208 RCP<crs_matrix_type> transMatrixWithSharedRows =
210 origMatrix_->getRowMap (), 0));
211 transMatrixWithSharedRows->setAllValues (rowptr_rcp, colind_rcp, values_rcp);
215 RCP<const import_type> myImport;
216 RCP<const export_type> myExport;
217 if (! origMatrix_->getGraph ()->getImporter ().is_null ()) {
218 myExport = rcp (
new export_type (*origMatrix_->getGraph ()->getImporter ()));
220 if (! origMatrix_->getGraph ()->getExporter ().is_null ()) {
221 myImport = rcp (
new import_type (*origMatrix_->getGraph ()->getExporter ()));
225 transMatrixWithSharedRows->expertStaticFillComplete (origMatrix_->getRangeMap (),
226 origMatrix_->getDomainMap (),
228 return transMatrixWithSharedRows;
236 #define TPETRA_ROWMATRIXTRANSPOSER_INSTANT(SCALAR,LO,GO,NODE) \ 238 template class RowMatrixTransposer< SCALAR, LO , GO , NODE >; RowMatrixTransposer(const Teuchos::RCP< const crs_matrix_type > &origMatrix, const std::string &label=std::string())
Constructor that takes the matrix to transpose.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries...
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Teuchos::RCP< crs_matrix_type > createTranspose()
Compute and return the transpose of the matrix given to the constructor.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
Teuchos::RCP< crs_matrix_type > createTransposeLocal()
Compute and return the transpose of the matrix given to the constructor.