43 #ifndef IFPACK2_CHEBYSHEV_DEF_HPP 44 #define IFPACK2_CHEBYSHEV_DEF_HPP 46 #include "Ifpack2_Parameters.hpp" 47 #include "Teuchos_TimeMonitor.hpp" 48 #include "Tpetra_CrsMatrix.hpp" 49 #include "Teuchos_TypeNameTraits.hpp" 56 template<
class MatrixType>
57 Chebyshev<MatrixType>::
58 Chebyshev (
const Teuchos::RCP<const row_matrix_type>& A)
60 IsInitialized_ (false),
65 InitializeTime_ (0.0),
71 this->setObjectLabel (
"Ifpack2::Chebyshev");
75 template<
class MatrixType>
80 template<
class MatrixType>
83 if (A.getRawPtr () != impl_.getMatrix ().getRawPtr ()) {
84 IsInitialized_ =
false;
91 template<
class MatrixType>
96 impl_.setParameters (const_cast<Teuchos::ParameterList&> (List));
100 template<
class MatrixType>
101 Teuchos::RCP<const Teuchos::Comm<int> >
104 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
105 TEUCHOS_TEST_FOR_EXCEPTION(
106 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getComm: The input " 107 "matrix A is null. Please call setMatrix() with a nonnull input matrix " 108 "before calling this method.");
109 return A->getRowMap ()->getComm ();
113 template<
class MatrixType>
114 Teuchos::RCP<const typename Chebyshev<MatrixType>::row_matrix_type>
117 return impl_.getMatrix ();
121 template<
class MatrixType>
122 Teuchos::RCP<
const Tpetra::CrsMatrix<
typename MatrixType::scalar_type,
123 typename MatrixType::local_ordinal_type,
124 typename MatrixType::global_ordinal_type,
125 typename MatrixType::node_type> >
130 return Teuchos::rcp_dynamic_cast<
const crs_matrix_type> (impl_.getMatrix ());
134 template<
class MatrixType>
135 Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
139 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
140 TEUCHOS_TEST_FOR_EXCEPTION(
141 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getDomainMap: The " 142 "input matrix A is null. Please call setMatrix() with a nonnull input " 143 "matrix before calling this method.");
144 return A->getDomainMap ();
148 template<
class MatrixType>
149 Teuchos::RCP<const typename Chebyshev<MatrixType>::map_type>
153 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
154 TEUCHOS_TEST_FOR_EXCEPTION(
155 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::getRangeMap: The " 156 "input matrix A is null. Please call setMatrix() with a nonnull input " 157 "matrix before calling this method.");
158 return A->getRangeMap ();
162 template<
class MatrixType>
164 return impl_.hasTransposeApply ();
168 template<
class MatrixType>
170 return NumInitialize_;
174 template<
class MatrixType>
180 template<
class MatrixType>
186 template<
class MatrixType>
188 return InitializeTime_;
192 template<
class MatrixType>
198 template<
class MatrixType>
204 template<
class MatrixType>
206 return ComputeFlops_;
210 template<
class MatrixType>
216 template<
class MatrixType>
219 apply (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
220 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
221 Teuchos::ETransp mode,
225 const std::string timerName (
"Ifpack2::Chebyshev::apply");
226 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
227 if (timer.is_null ()) {
228 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
233 Teuchos::TimeMonitor timeMon (*timer);
237 TEUCHOS_TEST_FOR_EXCEPTION(
238 ! isComputed (), std::runtime_error,
239 "Ifpack2::Chebyshev::apply(): You must call the compute() method before " 240 "you may call apply().");
241 TEUCHOS_TEST_FOR_EXCEPTION(
242 X.getNumVectors () != Y.getNumVectors (), std::runtime_error,
243 "Ifpack2::Chebyshev::apply(): X and Y must have the same number of " 244 "columns. X.getNumVectors() = " << X.getNumVectors() <<
" != " 245 <<
"Y.getNumVectors() = " << Y.getNumVectors() <<
".");
246 applyImpl (X, Y, mode, alpha, beta);
252 ApplyTime_ = timer->totalElapsedTime ();
256 template<
class MatrixType>
259 applyMat (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
260 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
261 Teuchos::ETransp mode)
const 263 TEUCHOS_TEST_FOR_EXCEPTION(
264 X.getNumVectors () != Y.getNumVectors (), std::invalid_argument,
265 "Ifpack2::Chebyshev::applyMat: X.getNumVectors() != Y.getNumVectors().");
267 Teuchos::RCP<const row_matrix_type> A = impl_.getMatrix ();
268 TEUCHOS_TEST_FOR_EXCEPTION(
269 A.is_null (), std::runtime_error,
"Ifpack2::Chebyshev::applyMat: The input " 270 "matrix A is null. Please call setMatrix() with a nonnull input matrix " 271 "before calling this method.");
273 A->apply (X, Y, mode);
277 template<
class MatrixType>
282 const std::string timerName (
"Ifpack2::Chebyshev::initialize");
283 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
284 if (timer.is_null ()) {
285 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
287 IsInitialized_ =
true;
292 template<
class MatrixType>
295 const std::string timerName (
"Ifpack2::Chebyshev::compute");
296 Teuchos::RCP<Teuchos::Time> timer = Teuchos::TimeMonitor::lookupCounter (timerName);
297 if (timer.is_null ()) {
298 timer = Teuchos::TimeMonitor::getNewCounter (timerName);
303 Teuchos::TimeMonitor timeMon (*timer);
304 if (! isInitialized ()) {
315 ComputeTime_ = timer->totalElapsedTime ();
319 template <
class MatrixType>
321 std::ostringstream out;
326 out <<
"\"Ifpack2::Chebyshev\": {";
327 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") <<
", " 328 <<
"Computed: " << (isComputed () ?
"true" :
"false") <<
", ";
330 out << impl_.description() <<
", ";
332 if (impl_.getMatrix ().is_null ()) {
333 out <<
"Matrix: null";
336 out <<
"Global matrix dimensions: [" 337 << impl_.getMatrix ()->getGlobalNumRows () <<
", " 338 << impl_.getMatrix ()->getGlobalNumCols () <<
"]" 339 <<
", Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries();
347 template <
class MatrixType>
350 const Teuchos::EVerbosityLevel verbLevel)
const 352 using Teuchos::TypeNameTraits;
356 const Teuchos::EVerbosityLevel vl =
357 (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
359 if (vl == Teuchos::VERB_NONE) {
369 Teuchos::OSTab tab0 (out);
370 const int myRank = this->getComm ()->getRank ();
374 out <<
"\"Ifpack2::Chebyshev\":" << endl;
377 Teuchos::OSTab tab1 (out);
378 if (vl >= Teuchos::VERB_LOW && myRank == 0) {
379 out <<
"Template parameters:" << endl;
381 Teuchos::OSTab tab2 (out);
382 out <<
"Scalar: " << TypeNameTraits<scalar_type>::name () << endl
383 <<
"LocalOrdinal: " << TypeNameTraits<local_ordinal_type>::name () << endl
384 <<
"GlobalOrdinal: " << TypeNameTraits<global_ordinal_type>::name () << endl
385 <<
"Device: " << TypeNameTraits<device_type>::name () << endl;
387 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") << endl
388 <<
"Computed: " << (isComputed () ?
"true" :
"false") << endl;
389 impl_.describe (out, vl);
391 if (impl_.getMatrix ().is_null ()) {
392 out <<
"Matrix: null" << endl;
395 out <<
"Global matrix dimensions: [" 396 << impl_.getMatrix ()->getGlobalNumRows () <<
", " 397 << impl_.getMatrix ()->getGlobalNumCols () <<
"]" << endl
398 <<
"Global nnz: " << impl_.getMatrix ()->getGlobalNumEntries() << endl;
403 template<
class MatrixType>
408 Teuchos::ETransp mode,
410 scalar_type beta)
const 412 using Teuchos::ArrayRCP;
416 using Teuchos::rcp_const_cast;
417 using Teuchos::rcpFromRef;
419 const scalar_type
zero = STS::zero();
420 const scalar_type one = STS::one();
441 Y_orig = rcp (
new MV (Y, Teuchos::Copy));
450 RCP<const MV> X_copy;
451 bool copiedInput =
false;
453 auto X_lcl_host = X.template getLocalView<Kokkos::HostSpace> ();
454 auto Y_lcl_host = Y.template getLocalView<Kokkos::HostSpace> ();
455 if (X_lcl_host.ptr_on_device () == Y_lcl_host.ptr_on_device ()) {
456 X_copy = rcp (
new MV (X, Teuchos::Copy));
459 X_copy = rcpFromRef (X);
469 RCP<MV> X_copy_nonConst = rcp_const_cast<MV> (X_copy);
471 X_copy_nonConst = rcp (
new MV (X, Teuchos::Copy));
474 X_copy_nonConst->scale (alpha);
475 X_copy = rcp_const_cast<
const MV> (X_copy_nonConst);
478 impl_.apply (*X_copy, Y);
481 Y.update (beta, *Y_orig, one);
486 template<
class MatrixType>
488 return impl_.getLambdaMaxForApply ();
495 #define IFPACK2_CHEBYSHEV_INSTANT(S,LO,GO,N) \ 496 template class Ifpack2::Chebyshev< Tpetra::RowMatrix<S, LO, GO, N> >; 498 #endif // IFPACK2_CHEBYSHEV_DEF_HPP void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to a Teuchos::FancyOStream.
Definition: Ifpack2_Chebyshev_def.hpp:349
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:223
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:217
Teuchos::RCP< const map_type > getRangeMap() const
The Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:151
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Chebyshev_def.hpp:81
void setParameters(const Teuchos::ParameterList ¶ms)
Set (or reset) parameters.
Definition: Ifpack2_Chebyshev_def.hpp:93
double getApplyTime() const
The total time spent in all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:199
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:229
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:175
void apply(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, scalar_type alpha=Teuchos::ScalarTraits< scalar_type >::one(), scalar_type beta=Teuchos::ScalarTraits< scalar_type >::zero()) const
Apply the preconditioner to X, returning the result in Y.
Definition: Ifpack2_Chebyshev_def.hpp:219
void compute()
(Re)compute the left scaling, and (if applicable) estimate max and min eigenvalues of D_inv * A...
Definition: Ifpack2_Chebyshev_def.hpp:293
Teuchos::RCP< const Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > > getCrsMatrix() const
Attempt to return the matrix A as a Tpetra::CrsMatrix.
Definition: Ifpack2_Chebyshev_def.hpp:127
MatrixType::scalar_type getLambdaMaxForApply() const
The estimate of the maximum eigenvalue used in the apply().
Definition: Ifpack2_Chebyshev_def.hpp:487
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix for which this is a preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:116
Diagonally scaled Chebyshev iteration for Tpetra sparse matrices.
Definition: Ifpack2_Chebyshev_decl.hpp:199
LinearOp zero(const VectorSpace &vs)
void applyMat(const Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &X, Tpetra::MultiVector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS) const
Compute Y = Op(A)*X, where Op(A) is either A, , or .
Definition: Ifpack2_Chebyshev_def.hpp:259
bool hasTransposeApply() const
Whether it's possible to apply the transpose of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:163
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Chebyshev_def.hpp:278
double getComputeTime() const
The total time spent in all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:193
double getApplyFlops() const
The total number of floating-point operations taken by all calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:211
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:169
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Chebyshev_decl.hpp:220
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Chebyshev_def.hpp:320
Teuchos::RCP< const map_type > getDomainMap() const
The Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Chebyshev_def.hpp:137
double getInitializeTime() const
The total time spent in all calls to initialize().
Definition: Ifpack2_Chebyshev_def.hpp:187
virtual ~Chebyshev()
Destructor.
Definition: Ifpack2_Chebyshev_def.hpp:76
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix is distributed.
Definition: Ifpack2_Chebyshev_def.hpp:102
int getNumApply() const
The total number of successful calls to apply().
Definition: Ifpack2_Chebyshev_def.hpp:181
double getComputeFlops() const
The total number of floating-point operations taken by all calls to compute().
Definition: Ifpack2_Chebyshev_def.hpp:205