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> >
73 #ifdef HAVE_TPETRA_MMM_TIMINGS 74 std::string prefix = std::string(
"Tpetra ")+ label_ + std::string(
": ");
75 using Teuchos::TimeMonitor;
76 Teuchos::RCP<Teuchos::TimeMonitor> MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix + std::string(
"Transpose TAFC"))));
82 RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > exporter =
83 transMatrixWithSharedRows->getGraph ()->getExporter ();
84 if (exporter.is_null ()) {
85 return transMatrixWithSharedRows;
88 Teuchos::ParameterList labelList;
89 #ifdef HAVE_TPETRA_MMM_TIMINGS 90 labelList.set(
"Timer Label",label_);
92 if(!params.is_null()) labelList.set(
"compute global constants",params->get(
"compute global constants",
true));
94 return exportAndFillCompleteCrsMatrix<crs_matrix_type> (transMatrixWithSharedRows, *exporter,Teuchos::null,Teuchos::null,Teuchos::rcp(&labelList,
false));
103 template<
class Scalar,
107 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
111 using Teuchos::Array;
112 using Teuchos::ArrayRCP;
113 using Teuchos::ArrayView;
116 using Teuchos::rcp_dynamic_cast;
117 typedef LocalOrdinal LO;
118 typedef GlobalOrdinal GO;
122 #ifdef HAVE_TPETRA_MMM_TIMINGS 123 std::string prefix = std::string(
"Tpetra ")+ label_ + std::string(
": ");
124 using Teuchos::TimeMonitor;
125 Teuchos::RCP<Teuchos::TimeMonitor> MM = Teuchos::rcp(
new TimeMonitor(*TimeMonitor::getNewTimer(prefix + std::string(
"Transpose Local"))));
131 size_t numLocalCols = origMatrix_->getNodeNumCols();
132 size_t numLocalRows = origMatrix_->getNodeNumRows();
133 size_t numLocalNnz = origMatrix_->getNodeNumEntries();
136 Array<size_t> CurrentStart(numLocalCols,0);
137 ArrayView<const LO> localIndices;
138 ArrayView<const Scalar> localValues;
139 RCP<const crs_matrix_type> crsMatrix =
141 if (crsMatrix == Teuchos::null) {
142 for (
size_t i=0; i<numLocalRows; ++i) {
143 const size_t numEntriesInRow = origMatrix_->getNumEntriesInLocalRow(i);
144 origMatrix_->getLocalRowView(i, localIndices, localValues);
145 for (
size_t j=0; j<numEntriesInRow; ++j) {
146 ++CurrentStart[ localIndices[j] ];
150 ArrayRCP<const size_t> origRowPtr_rcp;
151 ArrayRCP<const LO> origColInd_rcp;
152 ArrayRCP<const Scalar> origValues_rcp;
153 crsMatrix->getAllValues(origRowPtr_rcp, origColInd_rcp, origValues_rcp);
154 ArrayView<const LO> origColInd = origColInd_rcp();
155 for (LO j=0; j<origColInd.size(); ++j) {
156 ++CurrentStart[ origColInd[j] ];
162 ArrayRCP<size_t> rowptr_rcp(numLocalCols+1);
163 ArrayRCP<LO> colind_rcp(numLocalNnz);
164 ArrayRCP<Scalar> values_rcp(numLocalNnz);
167 ArrayView<size_t> TransRowptr = rowptr_rcp();
168 ArrayView<LO> TransColind = colind_rcp();
169 ArrayView<Scalar> TransValues = values_rcp();
173 for (
size_t i=1; i<numLocalCols+1; ++i) TransRowptr[i] = CurrentStart[i-1] + TransRowptr[i-1];
174 for (
size_t i=0; i<numLocalCols; ++i) CurrentStart[i] = TransRowptr[i];
178 if (crsMatrix == Teuchos::null) {
179 for (
size_t i=0; i<numLocalRows; ++i) {
180 const size_t numEntriesInRow = origMatrix_->getNumEntriesInLocalRow (i);
181 origMatrix_->getLocalRowView(i, localIndices, localValues);
183 for (
size_t j=0; j<numEntriesInRow; ++j) {
184 size_t idx = CurrentStart[localIndices[j]];
185 TransColind[idx] = Teuchos::as<LO>(i);
186 TransValues[idx] = localValues[j];
187 ++CurrentStart[localIndices[j]];
191 ArrayRCP<const size_t> origRowPtr_rcp;
192 ArrayRCP<const LO> origColInd_rcp;
193 ArrayRCP<const Scalar> origValues_rcp;
194 crsMatrix->getAllValues(origRowPtr_rcp, origColInd_rcp, origValues_rcp);
195 ArrayView<const size_t> origRowPtr = origRowPtr_rcp();
196 ArrayView<const LO> origColInd = origColInd_rcp();
197 ArrayView<const Scalar> origValues = origValues_rcp();
199 for (LO i=0; i<origRowPtr.size()-1; ++i) {
200 const LO rowIndex = Teuchos::as<LO>(i);
201 size_t rowStart = origRowPtr[i], rowEnd = origRowPtr[i+1];
202 for (
size_t j = rowStart; j < rowEnd; ++j) {
203 size_t idx = CurrentStart[origColInd[k]];
204 TransColind[idx] = rowIndex;
205 TransValues[idx] = origValues[k];
206 ++CurrentStart[origColInd[k++]];
212 RCP<crs_matrix_type> transMatrixWithSharedRows =
214 origMatrix_->getRowMap (), 0));
215 transMatrixWithSharedRows->setAllValues (rowptr_rcp, colind_rcp, values_rcp);
219 RCP<const import_type> myImport;
220 RCP<const export_type> myExport;
221 if (! origMatrix_->getGraph ()->getImporter ().is_null ()) {
222 myExport = rcp (
new export_type (*origMatrix_->getGraph ()->getImporter ()));
224 if (! origMatrix_->getGraph ()->getExporter ().is_null ()) {
225 myImport = rcp (
new import_type (*origMatrix_->getGraph ()->getExporter ()));
229 Teuchos::ParameterList eParams;
230 #ifdef HAVE_TPETRA_MMM_TIMINGS 231 eParams.set(
"Timer Label",label_);
233 if(!params.is_null()) eParams.set(
"compute global constants",params->get(
"compute global constants",
true));
235 transMatrixWithSharedRows->expertStaticFillComplete (origMatrix_->getRangeMap (),
236 origMatrix_->getDomainMap (),
237 myImport, myExport,rcp(&eParams,
false));
238 return transMatrixWithSharedRows;
246 #define TPETRA_ROWMATRIXTRANSPOSER_INSTANT(SCALAR,LO,GO,NODE) \ 248 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 > createTransposeLocal(const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Compute and return the transpose of the matrix given to the constructor.
Teuchos::RCP< crs_matrix_type > createTranspose(const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Compute and return the transpose of the matrix given to the constructor.