Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_Relaxation_decl.hpp
1// @HEADER
2// *****************************************************************************
3// Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4//
5// Copyright 2009 NTESS and the Ifpack2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef IFPACK2_RELAXATION_DECL_HPP
11#define IFPACK2_RELAXATION_DECL_HPP
12
15#include "Ifpack2_Parameters.hpp"
16#include "Tpetra_Vector.hpp"
17#include "Teuchos_ScalarTraits.hpp"
18#include "Tpetra_CrsMatrix.hpp" // Don't need the definition here
19#include "Tpetra_BlockCrsMatrix.hpp"
20#include <type_traits>
21#include <KokkosKernels_Handle.hpp>
22#include "Ifpack2_Details_GaussSeidel.hpp"
23#include "Ifpack2_Details_InverseDiagonalKernel.hpp"
24
25#ifndef DOXYGEN_SHOULD_SKIP_THIS
26namespace Ifpack2 {
27namespace Details {
28
29template <class TpetraOperatorType>
30class ScaledDampedResidual; // forward declaration
31
32} // namespace Details
33} // namespace Ifpack2
34
35namespace Teuchos {
36// forward declarations
37class ParameterList;
38class Time;
39} // namespace Teuchos
40#endif // DOXYGEN_SHOULD_SKIP_THIS
41
42namespace Ifpack2 {
43
205template <class MatrixType>
206class Relaxation : virtual public Ifpack2::Preconditioner<
207 typename MatrixType::scalar_type,
208 typename MatrixType::local_ordinal_type,
209 typename MatrixType::global_ordinal_type,
210 typename MatrixType::node_type>,
212 Tpetra::RowMatrix<typename MatrixType::scalar_type,
213 typename MatrixType::local_ordinal_type,
214 typename MatrixType::global_ordinal_type,
215 typename MatrixType::node_type> > {
216 public:
218
219
221 typedef typename MatrixType::scalar_type scalar_type;
222
224 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
225
227 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
228
230 typedef typename MatrixType::node_type node_type;
231
233 typedef typename MatrixType::node_type::device_type device_type;
234
236 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
237
239 typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
242
244 typedef Tpetra::Operator<scalar_type,
247 node_type>
249
250 static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::Relaxation: Please use MatrixType = Tpetra::RowMatrix. This saves build times, library sizes, and executable sizes. Don't worry, this class still works with CrsMatrix and BlockCrsMatrix; those are both subclasses of RowMatrix.");
251
253
255
286 explicit Relaxation(const Teuchos::RCP<const row_matrix_type>& A);
287
289 virtual ~Relaxation() = default;
290
292
294
373 void setParameters(const Teuchos::ParameterList& params);
374
375 bool supportsZeroStartingSolution() { return true; }
376
377 void setZeroStartingSolution(bool zeroStartingSolution) { ZeroStartingSolution_ = zeroStartingSolution; };
378
380 Teuchos::RCP<const Teuchos::ParameterList>
381 getValidParameters() const;
382
384 void initialize();
385
387 inline bool isInitialized() const {
388 return isInitialized_;
389 }
390
392 void compute();
393
395 inline bool isComputed() const {
396 return IsComputed_;
397 }
398
400
402
425 virtual void
426 setMatrix(const Teuchos::RCP<const row_matrix_type>& A);
427
429
431
447 void
448 apply(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
449 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
450 Teuchos::ETransp mode = Teuchos::NO_TRANS,
451 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
452 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
453
455 Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
456 getDomainMap() const;
457
459 Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
460 getRangeMap() const;
461
464 bool hasTransposeApply() const;
465
472 void
473 applyMat(const Tpetra::MultiVector<
477 node_type>& X,
478 Tpetra::MultiVector<
482 node_type>& Y,
483 Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
484
486
488
490 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
491
493 Teuchos::RCP<const row_matrix_type> getMatrix() const;
494
496 double getComputeFlops() const;
497
499 double getApplyFlops() const;
500
502 int getNumInitialize() const;
503
505 int getNumCompute() const;
506
508 int getNumApply() const;
509
511 double getInitializeTime() const;
512
514 double getComputeTime() const;
515
517 double getApplyTime() const;
518
520 size_t getNodeSmootherComplexity() const;
521
523
525
532 std::string description() const;
533
556 void
557 describe(Teuchos::FancyOStream& out,
558 const Teuchos::EVerbosityLevel verbLevel =
559 Teuchos::Describable::verbLevel_default) const;
561
562 private:
564
565
566 typedef Teuchos::ScalarTraits<scalar_type> STS;
567 typedef Teuchos::ScalarTraits<magnitude_type> STM;
568
569#if KOKKOS_VERSION >= 40799
570 typedef typename KokkosKernels::ArithTraits<scalar_type>::val_type impl_scalar_type;
571#else
572 typedef typename Kokkos::ArithTraits<scalar_type>::val_type impl_scalar_type;
573#endif
574
579 typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
581 crs_matrix_type;
582 typedef Tpetra::CrsGraph<local_ordinal_type,
584 crs_graph_type;
585 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
587 multivector_type;
588 typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type,
590 block_crs_matrix_type;
591 typedef Tpetra::BlockMultiVector<scalar_type, local_ordinal_type,
593 block_multivector_type;
594
595 typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
596 typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
597
598 typedef typename crs_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
599 typedef typename crs_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
600
601 Teuchos::RCP<Ifpack2::Details::InverseDiagonalKernel<op_type> > invDiagKernel_;
602
604
606
607 typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
608 typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
609 typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
610 typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
611 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type TemporaryWorkSpace;
612 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type PersistentWorkSpace;
613 typedef typename local_matrix_device_type::StaticCrsGraphType::execution_space MyExecSpace;
614 typedef typename KokkosKernels::Experimental::KokkosKernelsHandle<typename lno_row_view_t::const_value_type, local_ordinal_type, typename scalar_nonzero_view_t::value_type,
615 MyExecSpace, TemporaryWorkSpace, PersistentWorkSpace>
616 mt_kernel_handle_type;
617 Teuchos::RCP<mt_kernel_handle_type> mtKernelHandle_;
618
620
622
624 Teuchos::RCP<SerialGaussSeidel> serialGaussSeidel_;
625
627
629
632
634 Relaxation<MatrixType>& operator=(const Relaxation<MatrixType>& RHS);
635
637
639
644 void setParametersImpl(Teuchos::ParameterList& params);
645
647 void ApplyInverseRichardson(
648 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
649 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y) const;
650
652 void ApplyInverseJacobi(
653 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
654 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y) const;
655
657 void ApplyInverseJacobi_BlockCrsMatrix(
658 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
659 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y) const;
660
662 void ApplyInverseMTGS_CrsMatrix(
663 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& B,
664 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
665 Tpetra::ESweepDirection direction) const;
666
668 void ApplyInverseSerialGS(
669 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
670 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
671 Tpetra::ESweepDirection direction) const;
672
674 void ApplyInverseSerialGS_CrsMatrix(const crs_matrix_type& A,
675 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& B,
676 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
677 Tpetra::ESweepDirection direction) const;
678
680 void ApplyInverseSerialGS_RowMatrix(
681 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
682 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
683 Tpetra::ESweepDirection direction) const;
684
686 void ApplyInverseSerialGS_BlockCrsMatrix(
687 const block_crs_matrix_type& A,
688 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
689 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
690 Tpetra::ESweepDirection direction);
691
693 void ApplyInverseMTSGS_CrsMatrix(
694 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
695 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y) const;
696
697 void MTGaussSeidel(
698 const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& B,
699 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
700 const Tpetra::ESweepDirection direction) const;
701
702 void computeBlockCrs();
703
705 void updateCachedMultiVector(const Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >& map, size_t numVecs) const;
706
708
710
717 mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
718
720 Teuchos::RCP<const row_matrix_type> A_;
723 Teuchos::RCP<const import_type> Importer_;
725 Teuchos::RCP<const import_type> pointImporter_;
727 Teuchos::RCP<Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> > Diagonal_;
729 mutable Teuchos::RCP<Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> > cachedMV_;
730
731 typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
732 typename block_crs_matrix_type::device_type>
733 block_diag_type;
734 typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
735 typename block_crs_matrix_type::device_type,
736 Kokkos::MemoryUnmanaged>
737 unmanaged_block_diag_type;
738
753 block_diag_type blockDiag_;
754
755 Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
756
758 int NumSweeps_ = 1;
760 Details::RelaxationType PrecType_ = Ifpack2::Details::JACOBI;
762 scalar_type DampingFactor_ = STS::one();
764 bool IsParallel_;
766 bool ZeroStartingSolution_ = true;
768 bool DoBackwardGS_ = false;
770 bool DoL1Method_ = false;
772 magnitude_type L1Eta_ = Teuchos::as<magnitude_type>(1.5);
774 scalar_type MinDiagonalValue_ = STS::zero();
776 bool fixTinyDiagEntries_ = false;
778 bool checkDiagEntries_ = false;
780 int clusterSize_ = 1;
782 int longRowThreshold_ = 0;
784 KokkosGraph::ColoringAlgorithm mtColoringAlgorithm_ = KokkosGraph::COLORING_DEFAULT;
785
787 int NumOuterSweeps_ = 1;
789 int NumInnerSweeps_ = 1;
791 bool InnerSpTrsv_ = false;
793 scalar_type InnerDampingFactor_ = STS::one();
795 bool CompactForm_ = false;
796
798 bool is_matrix_structurally_symmetric_ = false;
799
801 bool ifpack2_dump_matrix_ = false;
802
804 bool isInitialized_ = false;
806 bool IsComputed_ = false;
808 int NumInitialize_ = 0;
810 int NumCompute_ = 0;
812 bool TimerForApply_ = true;
814 mutable int NumApply_ = 0;
816 double InitializeTime_ = 0.0;
818 double ComputeTime_ = 0.0;
820 mutable double ApplyTime_ = 0.0;
822 double ComputeFlops_ = 0.0;
824 mutable double ApplyFlops_ = 0.0;
825
827 magnitude_type globalMinMagDiagEntryMag_ = STM::zero();
829 magnitude_type globalMaxMagDiagEntryMag_ = STM::zero();
831 size_t globalNumSmallDiagEntries_ = 0;
833 size_t globalNumZeroDiagEntries_ = 0;
835 size_t globalNumNegDiagEntries_ = 0;
840 magnitude_type globalDiagNormDiff_ = STM::zero();
841
847 Kokkos::View<size_t*, typename node_type::device_type> diagOffsets_;
848
854 bool savedDiagOffsets_ = false;
855
856 bool hasBlockCrsMatrix_ = false;
857
859 Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
860
862}; // class Relaxation
863
864} // namespace Ifpack2
865
866#endif // IFPACK2_RELAXATION_DECL_HPP
Declaration of interface for preconditioners that can change their matrix after construction.
Mix-in interface for preconditioners that can change their matrix after construction.
Definition Ifpack2_Details_CanChangeMatrix.hpp:60
Ifpack2's implementation of Trilinos::Details::LinearSolver interface.
Definition Ifpack2_Details_LinearSolver_decl.hpp:75
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:74
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition Ifpack2_Relaxation_decl.hpp:215
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_Relaxation_decl.hpp:227
void setParameters(const Teuchos::ParameterList &params)
Set the relaxation / preconditioner parameters.
Definition Ifpack2_Relaxation_def.hpp:438
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_Relaxation_decl.hpp:230
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix and vectors are distributed.
Definition Ifpack2_Relaxation_def.hpp:446
virtual ~Relaxation()=default
Destructor.
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Definition Ifpack2_Relaxation_def.hpp:465
double getApplyTime() const
Total time in seconds spent in all calls to apply().
Definition Ifpack2_Relaxation_def.hpp:518
int getNumCompute() const
Total number of calls to compute().
Definition Ifpack2_Relaxation_def.hpp:498
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix to be preconditioned.
Definition Ifpack2_Relaxation_def.hpp:457
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner's parameters.
Definition Ifpack2_Relaxation_decl.hpp:377
void compute()
Compute the preconditioner ("numeric setup");.
Definition Ifpack2_Relaxation_def.hpp:964
void initialize()
Initialize the preconditioner ("symbolic setup").
Definition Ifpack2_Relaxation_def.hpp:678
double getComputeTime() const
Total time in seconds spent in all calls to compute().
Definition Ifpack2_Relaxation_def.hpp:513
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object's attributes to the given output stream.
Definition Ifpack2_Relaxation_def.hpp:2194
Tpetra::Operator< scalar_type, local_ordinal_type, global_ordinal_type, node_type > op_type
Tpetra::Operator specialization used by this class.
Definition Ifpack2_Relaxation_decl.hpp:248
std::string description() const
A simple one-line description of this object.
Definition Ifpack2_Relaxation_def.hpp:2093
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition Ifpack2_Relaxation_def.hpp:195
double getInitializeTime() const
Total time in seconds spent in all calls to initialize().
Definition Ifpack2_Relaxation_def.hpp:508
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_Relaxation_def.hpp:166
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_Relaxation_decl.hpp:221
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_Relaxation_def.hpp:545
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_Relaxation_decl.hpp:224
bool isComputed() const
Return true if compute() has been called.
Definition Ifpack2_Relaxation_decl.hpp:395
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
Apply the input matrix to X, returning the result in Y.
Definition Ifpack2_Relaxation_def.hpp:657
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization used by this class.
Definition Ifpack2_Relaxation_decl.hpp:241
MatrixType::node_type::device_type device_type
The Kokkos device type used by the input MatrixType.
Definition Ifpack2_Relaxation_decl.hpp:233
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition Ifpack2_Relaxation_decl.hpp:236
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_Relaxation_def.hpp:533
int getNumApply() const
Total number of calls to apply().
Definition Ifpack2_Relaxation_def.hpp:503
int getNumInitialize() const
Total number of calls to initialize().
Definition Ifpack2_Relaxation_def.hpp:493
double getComputeFlops() const
Total number of floating-point operations over all calls to compute().
Definition Ifpack2_Relaxation_def.hpp:523
bool hasTransposeApply() const
Whether apply() and applyMat() let you apply the transpose or conjugate transpose.
Definition Ifpack2_Relaxation_def.hpp:488
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition Ifpack2_Relaxation_decl.hpp:387
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Definition Ifpack2_Relaxation_def.hpp:478
double getApplyFlops() const
Total number of floating-point operations over all calls to apply().
Definition Ifpack2_Relaxation_def.hpp:528
Ifpack2 implementation details.
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40