49 #ifndef XPETRA_CRSMATRIXWRAP_DEF_HPP
50 #define XPETRA_CRSMATRIXWRAP_DEF_HPP
54 #include <Teuchos_SerialDenseMatrix.hpp>
55 #include <Teuchos_Hashtable.hpp>
60 #include "Xpetra_MultiVector.hpp"
70 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 : finalDefaultView_ (false)
78 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
80 size_t maxNumEntriesPerRow)
81 : finalDefaultView_ (false)
87 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 const ArrayRCP<const size_t>& NumEntriesPerRowToAlloc)
90 : finalDefaultView_ (false)
96 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
98 : finalDefaultView_(false)
107 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
109 : finalDefaultView_(false)
118 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
119 #ifdef HAVE_XPETRA_TPETRA
120 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
122 : finalDefaultView_(false)
131 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
133 const RCP<const Map>& domainMap,
const RCP<const Map>& rangeMap,
134 const Teuchos::RCP<Teuchos::ParameterList>& params)
135 : finalDefaultView_(false)
145 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
150 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
152 : finalDefaultView_(matrix->isFillComplete())
161 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
163 : finalDefaultView_(false)
172 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
175 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
177 matrixData_->insertGlobalValues(globalRow, cols, vals);
180 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
182 matrixData_->insertLocalValues(localRow, cols, vals);
185 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
187 const ArrayView<const GlobalOrdinal> &cols,
188 const ArrayView<const Scalar> &vals) { matrixData_->replaceGlobalValues(globalRow, cols, vals); }
190 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
192 const ArrayView<const LocalOrdinal> &cols,
193 const ArrayView<const Scalar> &vals) { matrixData_->replaceLocalValues(localRow, cols, vals); }
195 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
198 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
200 matrixData_->scale(alpha);
203 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
205 matrixData_->resumeFill(params);
208 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
210 matrixData_->fillComplete(domainMap, rangeMap, params);
216 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
218 matrixData_->fillComplete(params);
224 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
226 return matrixData_->getGlobalNumRows();
229 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
231 return matrixData_->getGlobalNumCols();
234 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
236 return matrixData_->getNodeNumRows();
239 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
241 return matrixData_->getGlobalNumEntries();
244 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
246 return matrixData_->getNodeNumEntries();
249 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
251 return matrixData_->getNumEntriesInLocalRow(localRow);
254 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
256 return matrixData_->getNumEntriesInGlobalRow(globalRow);
259 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
261 return matrixData_->getGlobalMaxNumRowEntries();
264 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
266 return matrixData_->getNodeMaxNumRowEntries();
269 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
271 return matrixData_->isLocallyIndexed();
274 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
276 return matrixData_->isGloballyIndexed();
279 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
281 return matrixData_->isFillComplete();
284 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
286 const ArrayView<LocalOrdinal> &Indices,
287 const ArrayView<Scalar> &Values,
290 matrixData_->getLocalRowCopy(LocalRow, Indices, Values, NumEntries);
293 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
295 matrixData_->getGlobalRowView(GlobalRow, indices, values);
298 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
300 matrixData_->getLocalRowView(LocalRow, indices, values);
303 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
305 matrixData_->getLocalDiagCopy(diag);
308 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
310 matrixData_->getLocalDiagOffsets(offsets);
313 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
315 matrixData_->getLocalDiagCopy(diag,offsets);
318 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
320 return matrixData_->getFrobeniusNorm();
323 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
325 matrixData_->leftScale(x);
328 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
330 matrixData_->rightScale(x);
333 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
335 return matrixData_->haveGlobalConstants();
338 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
341 Teuchos::ETransp mode,
345 matrixData_->apply(X,Y,mode,alpha,beta);
348 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
350 return matrixData_->getDomainMap();
353 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
355 return matrixData_->getRangeMap();
358 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
361 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
368 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
370 matrixData_->removeEmptyProcessesInPlace(newMap);
371 this->operatorViewTable_.get(this->GetCurrentViewLabel())->SetRowMap(matrixData_->getRowMap());
372 this->operatorViewTable_.get(this->GetCurrentViewLabel())->SetColMap(matrixData_->getColMap());
375 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
377 return matrixData_->getMap();
380 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
387 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
394 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
401 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
408 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
410 return "Xpetra::CrsMatrixWrap";
413 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
423 matrixData_->describe(out,verbLevel);
428 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
430 Teuchos::LabeledObject::setObjectLabel(objectLabel);
431 matrixData_->setObjectLabel(objectLabel);
434 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
435 #ifdef HAVE_XPETRA_TPETRA
436 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
439 return matrixData_->getLocalMatrix();
443 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
448 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
452 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
456 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
461 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
465 this->defaultViewLabel_ =
"point";
466 this->CreateView(this->GetDefaultViewLabel(), matrixData_->getRowMap(), matrixData_->getColMap());
469 this->currentViewLabel_ = this->GetDefaultViewLabel();
472 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
474 if ((finalDefaultView_ ==
false) && matrixData_->isFillComplete() ) {
477 finalDefaultView_ =
true;
482 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
487 matrixData_->residual(X,B,R);
493 #endif //ifndef XPETRA_CRSMATRIXWRAP_DEF_HPP
void setObjectLabel(const std::string &objectLabel)
RCP< CrsMatrix > getCrsMatrix() const
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Right scale matrix using the given vector entries.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
static RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
Constructor for empty matrix (intended use is an import/export target - can't insert entries directly...
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using global IDs.
global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
bool hasCrsGraph() const
Supports the getCrsGraph() call.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
Exception throws to report errors in the internal logical of the program.
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map > &newMap)
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
void doExport(const Matrix &dest, const Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
Teuchos::Hashtable< viewLabel_t, RCP< MatrixView > > operatorViewTable_
void updateDefaultView() const
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Get Frobenius norm of the matrix.
void doImport(const Matrix &source, const Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
std::string description() const
Return a simple one-line description of this object.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
const viewLabel_t & GetCurrentViewLabel() const
void getLocalDiagCopy(Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row idices.
CrsMatrixWrap(const RCP< const Map > &rowMap)
Constructor for a dynamic profile matrix (Epetra only)
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
Compute a residual R = B - (*this) * X.
RCP< const CrsGraph > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
size_t global_size_t
Global size_t object.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void fillComplete(const RCP< const Map > &domainMap, const RCP< const Map > &rangeMap, const RCP< Teuchos::ParameterList > ¶ms=null)
Signal that data entry is complete, specifying domain and range maps.
RCP< CrsMatrix > matrixData_
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
virtual ~CrsMatrixWrap()
Destructor.
const RCP< const Map > & getColMap() const
Returns the Map that describes the column distribution in this matrix. This might be null until fillC...
void resumeFill(const RCP< ParameterList > ¶ms=null)
bool isFillComplete() const
Returns true if fillComplete() has been called and the matrix is in compute mode. ...
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
virtual void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalar.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
Concrete implementation of Xpetra::Matrix.
global_size_t getGlobalNumCols() const
Returns the number of global columns in the matrix.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
CombineMode
Xpetra::Combine Mode enumerable type.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Left scale matrix using the given vector entries.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
const viewLabel_t & GetDefaultViewLabel() const
virtual void apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries in the specified global row.
RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using local IDs.
Xpetra-specific matrix class.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...