55 #ifndef XPETRA_BLOCKEDCRSMATRIX_HPP
56 #define XPETRA_BLOCKEDCRSMATRIX_HPP
78 #define sumAll(rcpComm, in, out) \
79 Teuchos::reduceAll(*rcpComm, Teuchos::REDUCE_SUM, in, Teuchos::outArg(out));
89 template <
class Scalar,
90 class LocalOrdinal = int,
91 class GlobalOrdinal = LocalOrdinal,
101 #ifdef HAVE_CTHULHU_TPETRA
132 for (
size_t r=0; r<
Rows(); ++r)
134 for(
size_t c=0; c<
Cols(); ++c)
169 "insertGlobalValues not supported by BlockedCrsMatrix" );
182 "insertLocalValues not supported by BlockedCrsMatrix" );
187 "removeEmptyProcesses not supported by BlockedCrsMatrix");
200 "replaceGlobalValues not supported by BlockedCrsMatrix" );
211 "replaceLocalValues not supported by BlockedCrsMatrix" );
217 "setAllToScalar not supported by BlockedCrsMatrix");
223 "scale not supported by BlockedCrsMatrix" );
242 "resumeFill not supported for block matrices" );
259 "fillComplete with arguments not supported for block matrices" );
278 for (
size_t r=0; r<
Rows(); ++r)
280 for (
size_t c=0; c<
Cols(); ++c)
282 if(
getMatrix(r,c)->isFillComplete() ==
false)
295 std::vector<GlobalOrdinal> colmapentries;
296 for (
size_t c=0; c<
Cols(); ++c)
298 std::set<GlobalOrdinal> colset;
299 for (
size_t r=0; r<
Rows(); ++r)
305 inserter(colset,colset.begin()));
308 colmapentries.reserve(colmapentries.size()+colset.size());
309 copy(colset.begin(), colset.end(), back_inserter(colmapentries));
310 sort(colmapentries.begin(), colmapentries.end());
311 typename std::vector<GlobalOrdinal>::iterator gendLocation;
312 gendLocation = std::unique(colmapentries.begin(), colmapentries.end());
313 colmapentries.erase(gendLocation,colmapentries.end());
317 size_t numGlobalElements = 0;
318 sumAll(
rangemaps_->getFullMap()->getComm(), colmapentries.size(), numGlobalElements)
336 for (
size_t r=0; r<
Rows(); ++r)
338 globalNumRows +=
getMatrix(r,0)->getGlobalNumRows();
340 return globalNumRows;
349 for (
size_t c=0; c<
Cols(); ++c)
351 globalNumCols +=
getMatrix(0,c)->getGlobalNumCols();
353 return globalNumCols;
360 for (
size_t r=0; r<
Rows(); ++r)
362 nodeNumRows +=
getMatrix(r,0)->getNodeNumRows();
371 for (
size_t r=0; r<
Rows(); ++r)
373 for(
size_t c=0; c<
Cols(); ++c)
375 globalNumEntries +=
getMatrix(r,c)->getGlobalNumEntries();
378 return globalNumEntries;
385 for (
size_t r=0; r<
Rows(); ++r)
387 for(
size_t c=0; c<
Cols(); ++c)
389 nodeNumEntries +=
getMatrix(r,c)->getNodeNumEntries();
392 return nodeNumEntries;
400 "getNumEntriesInLocalRow not supported by BlockedCrsMatrix" );
410 "getGlobalNumDiags() not supported by BlockedCrsMatrix" );
420 "getNodeNumDiags() not supported by BlockedCrsMatrix" );
430 "getGlobalMaxNumRowEntries() not supported by BlockedCrsMatrix" );
440 "getNodeMaxNumRowEntries() not supported by BlockedCrsMatrix" );
450 for (
size_t i=0; i<
blocks_.size(); ++i)
462 for (
size_t i=0; i<
blocks_.size(); ++i)
471 for (
size_t i=0; i<
blocks_.size(); ++i)
497 "getLocalRowCopy not supported by BlockedCrsMatrix" );
513 "getGlobalRowView not supported by BlockedCrsMatrix" );
529 "getLocalRowView not supported by BlockedCrsMatrix" );
538 "getLocalDiagCopy not supported by BlockedCrsMatrix" );
545 "getFrobeniusNorm() not supported by BlockedCrsMatrix, yet" );
589 for(
size_t rblock=0; rblock<
Rows(); ++rblock)
593 for (
size_t cblock=0; cblock<
Cols(); ++cblock)
597 bmat->
apply(*colx,*rowy);
600 rangemaps_->InsertVector(rowresult,rblock,tmpY);
602 Y.
update(alpha,*tmpY,beta);
607 for (
size_t cblock = 0; cblock<
Cols(); ++cblock)
611 for (
size_t rblock = 0; rblock<
Rows(); ++rblock)
620 Y.
update(alpha,*tmpY,beta);
624 "apply() only supports NO_TRANS and TRANS." );
709 std::ostringstream oss;
710 oss <<
"Xpetra_BlockedCrsMatrix.description()" << std::endl;
724 out <<
"Xpetra::BlockedCrsMatrix: " <<
Rows() <<
" x " <<
Cols() << std::endl;
728 out <<
"BlockMatrix is filled" << std::endl;
729 out <<
"fullRowMap" << std::endl;
731 out <<
"fullColMap" << std::endl;
735 out <<
"BlockMatrix is NOT filled" << std::endl;
737 for (
size_t r=0; r<
Rows(); ++r)
739 for(
size_t c=0; c<
Cols(); ++c)
741 out <<
"Block(" << r <<
"," << c <<
")" << std::endl;
758 "getCrsGraph() not supported by BlockedCrsMatrix");
759 return Teuchos::null;
799 for (
size_t i=0; i<
blocks_.size(); ++i)
829 "Matrix A is not completed");
834 std::vector<GlobalOrdinal> vecIndices(MaxNumEntries);
835 std::vector<Scalar> vecValues (MaxNumEntries);
847 GlobalOrdinal Row = MyGlobalRowIds[i];
853 for (
size_t j=0; j<NumEntries; ++j)
854 Values[j] *= scalarA;
858 for (
size_t j=0; j<NumEntries; ++j)
860 std::vector<GlobalOrdinal> tempVec; tempVec.push_back(Indices[j]);
861 std::vector<Scalar> tempVal; tempVal.push_back(Values[j]);
868 std::vector<GlobalOrdinal> tempvecIndices(NumEntries);
869 std::copy(Indices.getRawPtr(),
870 Indices.getRawPtr()+NumEntries,
871 std::inserter(tempvecIndices,tempvecIndices.begin()));
872 std::vector<Scalar> tempvecValues(NumEntries);
873 std::copy(Values.getRawPtr(),
874 Values.getRawPtr()+NumEntries,
875 std::inserter(tempvecValues,tempvecValues.begin()));
910 std::vector<Teuchos::RCP<CrsMatrixClass> >
blocks_;
923 #define XPETRA_BLOCKEDCRSMATRIX_SHORT
void doImport(const Matrix &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Import (using an Exporter).
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > CrsMatrixClass
virtual Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const =0
Return a view of the global indices owned by this node.
Xpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > CrsGraph
Teuchos::RCP< const MapExtractorClass > rangemaps_
the full range map together with all partial domain maps
void CreateView(viewLabel_t viewLabel, const RCP< const Map > &rowMap, const RCP< const Map > &colMap)
virtual bool isFillComplete() const =0
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
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.
const RCP< const MapClass > getDomainMap() const
Returns the Map associated with the full domain of this operator. This will be null until fillComplet...
virtual void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)=0
Insert matrix entries, using global IDs.
virtual size_t getNodeMaxNumRowEntries() const =0
Returns the maximum number of entries across all rows/columns on this node.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using global IDs.
virtual void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, 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.
const RCP< const MapExtractorClass > getRangeMapExtractor()
Returns map extractor class for range map.
const RCP< const MapClass > getRangeMap() const
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
Teuchos::RCP< CrsMatrixClass > Merge() const
merge BlockedCrsMatrix blocks in a CrsMatrix
void doExport(const Matrix &dest, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export (using an Importer).
virtual void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const =0
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
void setMatrix(size_t r, size_t c, Teuchos::RCP< CrsMatrixClass > &mat)
set matrix block
void doExport(const Matrix &dest, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const RCP< const MapExtractorClass > getDomainMapExtractor()
Returns map extractor for domain map.
static Teuchos::RCP< Map< LocalOrdinal, GlobalOrdinal, Node > > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalGlobal lg=Xpetra::GloballyDistributed, const Teuchos::RCP< Node > &node=Kokkos::Details::getNode< Node >())
Map constructor with Xpetra-defined contiguous uniform distribution.
virtual size_t getNodeNumElements() const =0
The number of elements belonging to the calling node.
Exception throws to report errors in the internal logical of the program.
std::vector< Teuchos::RCP< CrsMatrixClass > > blocks_
row major matrix block storage
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
bool isFillComplete() const
Returns true if fillComplete() has been called and the matrix is in compute mode. ...
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
virtual void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > ¶ms=null)=0
Signal that data entry is complete, specifying domain and range maps.
virtual size_t Rows() const
number of row blocks
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row idices.
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
virtual size_t getNodeNumRows() const =0
Returns the number of matrix rows owned on the calling node.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Xpetra::MapExtractor< Scalar, LocalOrdinal, GlobalOrdinal, Node > MapExtractorClass
virtual const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const =0
The Map describing the parallel distribution of this object.
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.
Teuchos::RCP< MapClass > fullrowmap_
full matrix row map
virtual const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const =0
Returns the Map that describes the row distribution in this matrix.
viewLabel_t currentViewLabel_
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
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 fillComplete(const RCP< ParameterList > ¶ms=null)
Signal that data entry is complete.
const RCP< const MapClass > getRangeMap(size_t i) const
Teuchos::RCP< const MapExtractorClass > domainmaps_
the full domain map together with all partial domain maps
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using local IDs.
size_t global_size_t
Global size_t object.
Xpetra::CrsMatrixFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > CrsMatrixFactory
static const EVerbosityLevel verbLevel_default
void Add(Teuchos::RCP< CrsMatrixClass > &A, const Scalar scalarA, Teuchos::RCP< CrsMatrixClass > &B, const Scalar scalarB) const
Add a Xpetra::CrsMatrix to another: B = B*scalarB + A*scalarA.
global_size_t getGlobalNumRows() const
Returns the number of global rows.
Xpetra::MatrixView< LocalOrdinal, GlobalOrdinal, Node > MatrixView
BlockedCrsMatrix(Teuchos::RCP< const MapExtractorClass > &rangeMaps, Teuchos::RCP< const MapExtractorClass > &domainMaps, size_t npr, Xpetra::ProfileType pftype=Xpetra::DynamicProfile)
Constructor.
Teuchos::RCP< CrsMatrixClass > getMatrix(size_t r, size_t c) const
return block (r,c)
viewLabel_t defaultViewLabel_
std::string description() const
Return a simple one-line description of this object.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
Xpetra::TpetraCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > TpetraCrsMatrix
const RCP< const MapClass > getDomainMap(size_t i) const
Returns the Map associated with the i'th block domain of this operator. This will be null until fillC...
virtual ~BlockedCrsMatrix()
Destructor.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
bool isLocallyIndexed() const
If matrix indices of all matrix blocks are in the local range, this function returns true...
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
virtual ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Get Frobenius norm of the matrix.
CombineMode
Xpetra::Combine Mode enumerable type.
virtual 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...
virtual void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const =0
Computes the sparse matrix-multivector multiplication.
#define sumAll(rcpComm, in, out)
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
virtual size_t Cols() const
number of column blocks
static RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, size_t maxNumEntriesPerRow, Xpetra::ProfileType pftype=Xpetra::DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying fixed number of entries for each row.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
virtual size_t getNumVectors() const =0
Number of columns in the multivector.
void resumeFill(const RCP< ParameterList > ¶ms=null)
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
const viewLabel_t & GetDefaultViewLabel() const
void removeEmptyProcessesInPlace(const Teuchos::RCP< const MapClass > &newMap)
virtual void scale(const Scalar &alpha)=0
Scale the current values of a matrix, this = alpha*this.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
global_size_t getGlobalNumCols() const
Returns the number of global columns in the matrix.
virtual void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalar.
Teuchos::RCP< MapClass > fullcolmap_
full matrix column map
void fillComplete(const RCP< const MapClass > &domainMap, const RCP< const MapClass > &rangeMap, const RCP< ParameterList > ¶ms=null)
Signal that data entry is complete, specifying domain and range maps.
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > MapClass
Xpetra-specific matrix class.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > Matrix
void doImport(const Matrix &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.