43 #ifndef IFPACK2_SPARSITYFILTER_DEF_HPP
44 #define IFPACK2_SPARSITYFILTER_DEF_HPP
46 #include "Tpetra_Map.hpp"
47 #include "Tpetra_MultiVector.hpp"
48 #include "Tpetra_Vector.hpp"
56 template<
class MatrixType>
58 size_t AllowedNumEntries,
59 LocalOrdinal AllowedBandwidth):
61 AllowedNumEntries_(AllowedNumEntries),
62 AllowedBandwidth_(AllowedBandwidth),
71 A_->getComm()->getSize() != 1 || A_->getLocalNumRows() != A_->getGlobalNumRows(),
72 std::runtime_error,
"Ifpack2::SparsityFilter: "
73 "This class may only be used when A.getComm()->getSize() == 1.");
76 NumRows_ = A_->getLocalNumRows();
81 NumEntries_.resize(NumRows_);
85 MaxNumEntries_ = A_->getLocalMaxNumRowEntries();
86 MaxNumEntriesA_ = A_->getLocalMaxNumRowEntries();
89 Kokkos::resize(Indices_,MaxNumEntries_);
90 Kokkos::resize(Values_,MaxNumEntries_);
92 size_t ActualMaxNumEntries = 0;
93 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
94 NumEntries_[i] = MaxNumEntriesA_;
96 A_->getLocalRowCopy(i,Indices_,Values_,Nnz);
100 if (Nnz > ActualMaxNumEntries)
101 ActualMaxNumEntries = Nnz;
104 MaxNumEntries_ = ActualMaxNumEntries;
108 template<
class MatrixType>
112 template<
class MatrixType>
115 return A_->getComm();
120 template<
class MatrixType>
121 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
122 typename MatrixType::global_ordinal_type,
123 typename MatrixType::node_type> >
126 return A_->getRowMap();
130 template<
class MatrixType>
131 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
132 typename MatrixType::global_ordinal_type,
133 typename MatrixType::node_type> >
136 return A_->getColMap();
140 template<
class MatrixType>
141 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
142 typename MatrixType::global_ordinal_type,
143 typename MatrixType::node_type> >
146 return A_->getDomainMap();
150 template<
class MatrixType>
151 Teuchos::RCP<
const Tpetra::Map<
typename MatrixType::local_ordinal_type,
152 typename MatrixType::global_ordinal_type,
153 typename MatrixType::node_type> >
156 return A_->getRangeMap();
160 template<
class MatrixType>
161 Teuchos::RCP<
const Tpetra::RowGraph<
typename MatrixType::local_ordinal_type,
162 typename MatrixType::global_ordinal_type,
163 typename MatrixType::node_type> >
166 throw std::runtime_error(
"Ifpack2::SparsityFilter: does not support getGraph.");
170 template<
class MatrixType>
177 template<
class MatrixType>
184 template<
class MatrixType>
192 template<
class MatrixType>
199 template<
class MatrixType>
202 return A_->getIndexBase();
206 template<
class MatrixType>
213 template<
class MatrixType>
220 template<
class MatrixType>
223 throw std::runtime_error(
"Ifpack2::SparsityFilter does not implement getNumEntriesInGlobalRow.");
227 template<
class MatrixType>
230 return NumEntries_[localRow];
234 template<
class MatrixType>
237 return MaxNumEntries_;
241 template<
class MatrixType>
244 return MaxNumEntries_;
248 template<
class MatrixType>
251 return A_->getBlockSize();
255 template<
class MatrixType>
262 template<
class MatrixType>
265 return A_->isLocallyIndexed();
269 template<
class MatrixType>
272 return A_->isGloballyIndexed();
276 template<
class MatrixType>
279 return A_->isFillComplete();
283 template<
class MatrixType>
286 nonconst_global_inds_host_view_type &,
287 nonconst_values_host_view_type &,
289 throw std::runtime_error(
"Ifpack2::SparsityFilter does not implement getGlobalRowCopy.");
293 template<
class MatrixType>
296 nonconst_local_inds_host_view_type &Indices,
297 nonconst_values_host_view_type &Values,
298 size_t& NumEntries)
const
300 TEUCHOS_TEST_FOR_EXCEPTION((LocalRow < 0 || (
size_t) LocalRow >= NumRows_ || (
size_t) Indices.size() < NumEntries_[LocalRow]), std::runtime_error,
"Ifpack2::SparsityFilter::getLocalRowCopy invalid row or array size.");
308 size_t A_NumEntries=0;
309 A_->getLocalRowCopy(LocalRow,Indices_,Values_,A_NumEntries);
313 if (A_NumEntries > AllowedNumEntries_) {
315 for (
size_t i = 0 ; i < A_NumEntries ; ++i) {
317 if (Indices_[i] == LocalRow)
325 std::sort(Values2.rbegin(),Values2.rend());
327 Threshold = Values2[AllowedNumEntries_ - 1];
335 for (
size_t i = 0 ; i < A_NumEntries ; ++i) {
336 if (std::abs(Indices_[i] - LocalRow) > AllowedBandwidth_)
342 Values[NumEntries] = Values_[i];
343 Indices[NumEntries] = Indices_[i];
346 if (NumEntries > AllowedNumEntries_)
354 template<
class MatrixType>
356 global_inds_host_view_type &,
357 values_host_view_type &)
const
359 throw std::runtime_error(
"Ifpack2::SparsityFilter: does not support getGlobalRowView.");
363 template<
class MatrixType>
365 local_inds_host_view_type & ,
366 values_host_view_type & )
const
368 throw std::runtime_error(
"Ifpack2::SparsityFilter: does not support getLocalRowView.");
372 template<
class MatrixType>
376 return A_->getLocalDiagCopy(diag);
380 template<
class MatrixType>
383 throw std::runtime_error(
"Ifpack2::SparsityFilter does not support leftScale.");
387 template<
class MatrixType>
390 throw std::runtime_error(
"Ifpack2::SparsityFilter does not support rightScale.");
394 template<
class MatrixType>
396 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
404 "Ifpack2::SparsityFilter::apply ERROR: X.getNumVectors() != Y.getNumVectors().");
411 size_t NumVectors = Y.getNumVectors();
413 for (
size_t i = 0 ; i < NumRows_ ; ++i) {
416 getLocalRowCopy(i,Indices_,Values_,Nnz);
417 Scalar* Values =
reinterpret_cast<Scalar*
>(Values_.data());
419 for (
size_t j = 0 ; j < Nnz ; ++j)
420 for (
size_t k = 0 ; k < NumVectors ; ++k)
421 y_ptr[k][i] += Values[j] * x_ptr[k][Indices_[j]];
424 for (
size_t j = 0 ; j < Nnz ; ++j)
425 for (
size_t k = 0 ; k < NumVectors ; ++k)
426 y_ptr[k][Indices_[j]] += Values[j] * x_ptr[k][i];
429 for (
size_t j = 0 ; j < Nnz ; ++j)
430 for (
size_t k = 0 ; k < NumVectors ; ++k)
438 template<
class MatrixType>
445 template<
class MatrixType>
452 template<
class MatrixType>
455 throw std::runtime_error(
"Ifpack2::SparsityFilter does not implement getFrobeniusNorm.");
460 #define IFPACK2_SPARSITYFILTER_INSTANT(S,LO,GO,N) \
461 template class Ifpack2::SparsityFilter< Tpetra::RowMatrix<S, LO, GO, N> >;
virtual void apply(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Computes the operator-multivector application.
Definition: Ifpack2_SparsityFilter_def.hpp:395
virtual size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
Definition: Ifpack2_SparsityFilter_def.hpp:228
virtual bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Definition: Ifpack2_SparsityFilter_def.hpp:439
virtual size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Definition: Ifpack2_SparsityFilter_def.hpp:242
virtual Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:124
virtual Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map that describes the domain distribution in this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:144
virtual void getLocalRowCopy(LocalOrdinal LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the graph. Put into storage allocated by callin...
Definition: Ifpack2_SparsityFilter_def.hpp:295
virtual size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:214
virtual void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:355
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:200
virtual Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:134
virtual void getLocalDiagCopy(Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
Definition: Ifpack2_SparsityFilter_def.hpp:373
virtual LocalOrdinal getBlockSize() const
The number of degrees of freedom per mesh point.
Definition: Ifpack2_SparsityFilter_def.hpp:249
virtual bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
Definition: Ifpack2_SparsityFilter_def.hpp:270
virtual Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:164
virtual bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
Definition: Ifpack2_SparsityFilter_def.hpp:263
virtual ~SparsityFilter()
Destructor.
Definition: Ifpack2_SparsityFilter_def.hpp:109
virtual global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:171
virtual size_t getLocalNumCols() const
Returns the number of columns needed to apply the forward operator on this node, i.e., the number of elements listed in the column map.
Definition: Ifpack2_SparsityFilter_def.hpp:193
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the communicator.
Definition: Ifpack2_SparsityFilter_def.hpp:113
SparsityFilter(const Teuchos::RCP< const row_matrix_type > &Matrix, size_t AllowedNumEntries, LocalOrdinal AllowedBandwidth=-Teuchos::ScalarTraits< LocalOrdinal >::one())
Constructor.
Definition: Ifpack2_SparsityFilter_def.hpp:57
virtual size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
Definition: Ifpack2_SparsityFilter_def.hpp:221
virtual global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:178
virtual bool hasColMap() const
Indicates whether this matrix has a well-defined column map.
Definition: Ifpack2_SparsityFilter_def.hpp:256
virtual mag_type getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:453
virtual size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Definition: Ifpack2_SparsityFilter_def.hpp:235
virtual void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:364
virtual Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map that describes the range distribution in this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:154
virtual global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
Definition: Ifpack2_SparsityFilter_def.hpp:207
virtual bool isFillComplete() const
Returns true if fillComplete() has been called.
Definition: Ifpack2_SparsityFilter_def.hpp:277
static magnitudeType magnitude(T a)
virtual void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
Definition: Ifpack2_SparsityFilter_def.hpp:285
virtual void rightScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the right with the Vector x.
Definition: Ifpack2_SparsityFilter_def.hpp:388
virtual void leftScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Scales the RowMatrix on the left with the Vector x.
Definition: Ifpack2_SparsityFilter_def.hpp:381
virtual bool supportsRowViews() const
Returns true if RowViews are supported.
Definition: Ifpack2_SparsityFilter_def.hpp:446
virtual size_t getLocalNumRows() const
Returns the number of rows owned on the calling node.
Definition: Ifpack2_SparsityFilter_def.hpp:185