Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Relaxation_decl.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // ***********************************************************************
38 //@HEADER
39 */
40 
41 #ifndef IFPACK2_RELAXATION_DECL_HPP
42 #define IFPACK2_RELAXATION_DECL_HPP
43 
46 #include "Ifpack2_Parameters.hpp"
47 #include "Tpetra_Vector.hpp"
48 #include "Teuchos_ScalarTraits.hpp"
49 #include "Tpetra_CrsMatrix.hpp" // Don't need the definition here
50 #include "Tpetra_BlockCrsMatrix.hpp"
51 #include <type_traits>
52 #include <KokkosKernels_Handle.hpp>
53 #include "Ifpack2_Details_GaussSeidel.hpp"
54 #include "Ifpack2_Details_InverseDiagonalKernel.hpp"
55 
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57 namespace Ifpack2 {
58 namespace Details {
59 
60 template<class TpetraOperatorType>
61 class ScaledDampedResidual; // forward declaration
62 
63 } // namespace Details
64 } // namespace Ifpack2
65 
66 namespace Teuchos {
67  // forward declarations
68  class ParameterList;
69  class Time;
70 } // namespace Teuchos
71 #endif // DOXYGEN_SHOULD_SKIP_THIS
72 
73 namespace Ifpack2 {
74 
236 template<class MatrixType>
237 class Relaxation :
238  virtual public Ifpack2::Preconditioner<
239  typename MatrixType::scalar_type,
240  typename MatrixType::local_ordinal_type,
241  typename MatrixType::global_ordinal_type,
242  typename MatrixType::node_type>,
243  virtual public Ifpack2::Details::CanChangeMatrix<
244  Tpetra::RowMatrix<typename MatrixType::scalar_type,
245  typename MatrixType::local_ordinal_type,
246  typename MatrixType::global_ordinal_type,
247  typename MatrixType::node_type> >
248 {
249 public:
251 
252 
254  typedef typename MatrixType::scalar_type scalar_type;
255 
257  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
258 
260  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
261 
263  typedef typename MatrixType::node_type node_type;
264 
266  typedef typename MatrixType::node_type::device_type device_type;
267 
270 
272  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
274 
276  typedef Tpetra::Operator<scalar_type,
280 
281  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.");
282 
284 
286 
318 
320  virtual ~Relaxation () = default;
321 
323 
325 
404  void setParameters (const Teuchos::ParameterList& params);
405 
406  bool supportsZeroStartingSolution() { return true; }
407 
408  void setZeroStartingSolution (bool zeroStartingSolution) { ZeroStartingSolution_ = zeroStartingSolution; };
409 
412  getValidParameters () const;
413 
415  void initialize ();
416 
418  inline bool isInitialized() const {
419  return isInitialized_;
420  }
421 
423  void compute ();
424 
426  inline bool isComputed() const {
427  return IsComputed_;
428  }
429 
431 
433 
456  virtual void
458 
460 
462 
478  void
479  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
480  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
484 
487  getDomainMap () const;
488 
491  getRangeMap () const;
492 
495  bool hasTransposeApply () const;
496 
503  void
504  applyMat (const Tpetra::MultiVector<
505  scalar_type,
508  node_type>& X,
509  Tpetra::MultiVector<
510  scalar_type,
513  node_type>& Y,
514  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
515 
517 
519 
522 
525 
527  double getComputeFlops() const;
528 
530  double getApplyFlops() const;
531 
533  int getNumInitialize() const;
534 
536  int getNumCompute() const;
537 
539  int getNumApply() const;
540 
542  double getInitializeTime() const;
543 
545  double getComputeTime() const;
546 
548  double getApplyTime() const;
549 
551  size_t getNodeSmootherComplexity() const;
552 
554 
556 
563  std::string description () const;
564 
587  void
589  const Teuchos::EVerbosityLevel verbLevel =
592 
593 private:
595 
596 
599 
600  typedef typename Kokkos::ArithTraits<scalar_type>::val_type impl_scalar_type;
601 
606  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
607  global_ordinal_type, node_type> crs_matrix_type;
608  typedef Tpetra::CrsGraph<local_ordinal_type,
609  global_ordinal_type, node_type> crs_graph_type;
610  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type,
611  global_ordinal_type, node_type> multivector_type;
612  typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type,
613  global_ordinal_type, node_type> block_crs_matrix_type;
614  typedef Tpetra::BlockMultiVector<scalar_type, local_ordinal_type,
615  global_ordinal_type, node_type> block_multivector_type;
616 
617  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
618  typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> import_type;
619 
620  typedef typename crs_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
621  typedef typename crs_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
622 
624 
626 
628 
629  typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
630  typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
631  typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
632  typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
633  typedef typename local_matrix_device_type::StaticCrsGraphType::device_type TemporaryWorkSpace;
634  typedef typename local_matrix_device_type::StaticCrsGraphType::device_type PersistentWorkSpace;
635  typedef typename local_matrix_device_type::StaticCrsGraphType::execution_space MyExecSpace;
636  typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
637  <typename lno_row_view_t::const_value_type, local_ordinal_type,typename scalar_nonzero_view_t::value_type,
638  MyExecSpace, TemporaryWorkSpace,PersistentWorkSpace > mt_kernel_handle_type;
639  Teuchos::RCP<mt_kernel_handle_type> mtKernelHandle_;
640 
642 
644 
645  using SerialGaussSeidel = Ifpack2::Details::GaussSeidel<scalar_type, local_ordinal_type, global_ordinal_type, node_type>;
646  Teuchos::RCP<SerialGaussSeidel> serialGaussSeidel_;
647 
649 
651 
653  Relaxation (const Relaxation<MatrixType>& RHS);
654 
656  Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
657 
659 
661 
666  void setParametersImpl (Teuchos::ParameterList& params);
667 
669  void ApplyInverseRichardson(
670  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
671  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
672 
674  void ApplyInverseJacobi(
675  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
676  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
677 
679  void ApplyInverseJacobi_BlockCrsMatrix(
680  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
681  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
682 
684  void ApplyInverseMTGS_CrsMatrix(
685  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
686  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
687  Tpetra::ESweepDirection direction) const;
688 
690  void ApplyInverseSerialGS(
691  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
692  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
693  Tpetra::ESweepDirection direction) const;
694 
696  void ApplyInverseSerialGS_CrsMatrix (const crs_matrix_type& A,
697  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
698  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
699  Tpetra::ESweepDirection direction) const;
700 
702  void ApplyInverseSerialGS_RowMatrix(
703  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
704  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
705  Tpetra::ESweepDirection direction) const;
706 
708  void ApplyInverseSerialGS_BlockCrsMatrix(
709  const block_crs_matrix_type& A,
710  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
711  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
712  Tpetra::ESweepDirection direction);
713 
715  void ApplyInverseMTSGS_CrsMatrix(
716  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
717  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
718 
719  void MTGaussSeidel (
720  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
721  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
722  const Tpetra::ESweepDirection direction) const;
723 
724  void computeBlockCrs ();
725 
727  void updateCachedMultiVector(const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& map, size_t numVecs) const;
728 
729 
731 
733 
740  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
741 
748  Teuchos::RCP<const import_type> pointImporter_;
753 
754  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
755  typename block_crs_matrix_type::device_type> block_diag_type;
756  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
757  typename block_crs_matrix_type::device_type,
758  Kokkos::MemoryUnmanaged> unmanaged_block_diag_type;
759 
774  block_diag_type blockDiag_;
775 
776  Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
777 
779  int NumSweeps_ = 1;
781  Details::RelaxationType PrecType_ = Ifpack2::Details::JACOBI;
783  scalar_type DampingFactor_ = STS::one();
785  bool IsParallel_;
787  bool ZeroStartingSolution_ = true;
789  bool DoBackwardGS_ = false;
791  bool DoL1Method_ = false;
793  magnitude_type L1Eta_ = Teuchos::as<magnitude_type>(1.5);
795  scalar_type MinDiagonalValue_ = STS::zero();
797  bool fixTinyDiagEntries_ = false;
799  bool checkDiagEntries_ = false;
801  int clusterSize_ = 1;
803  int longRowThreshold_ = 0;
805  KokkosGraph::ColoringAlgorithm mtColoringAlgorithm_ = KokkosGraph::COLORING_DEFAULT;
806 
808  int NumOuterSweeps_ = 1;
810  int NumInnerSweeps_ = 1;
812  bool InnerSpTrsv_ = false;
814  scalar_type InnerDampingFactor_ = STS::one();
816  bool CompactForm_ = false;
817 
819  bool is_matrix_structurally_symmetric_ = false;
820 
822  bool ifpack2_dump_matrix_ = false;
823 
824 
826  bool isInitialized_ = false;
828  bool IsComputed_ = false;
830  int NumInitialize_ = 0;
832  int NumCompute_ = 0;
834  bool TimerForApply_ = true;
836  mutable int NumApply_ = 0;
838  double InitializeTime_ = 0.0;
840  double ComputeTime_ = 0.0;
842  mutable double ApplyTime_ = 0.0;
844  double ComputeFlops_ = 0.0;
846  mutable double ApplyFlops_ = 0.0;
847 
849  magnitude_type globalMinMagDiagEntryMag_ = STM::zero();
851  magnitude_type globalMaxMagDiagEntryMag_ = STM::zero();
853  size_t globalNumSmallDiagEntries_ = 0;
855  size_t globalNumZeroDiagEntries_ = 0;
857  size_t globalNumNegDiagEntries_ = 0;
862  magnitude_type globalDiagNormDiff_ = STM::zero();
863 
869  Kokkos::View<size_t*, typename node_type::device_type> diagOffsets_;
870 
876  bool savedDiagOffsets_ = false;
877 
878  bool hasBlockCrsMatrix_ = false;
879 
881  Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
882 
884 }; //class Relaxation
885 
886 }//namespace Ifpack2
887 
888 #endif // IFPACK2_RELAXATION_DECL_HPP
bool hasTransposeApply() const
Whether apply() and applyMat() let you apply the transpose or conjugate transpose.
Definition: Ifpack2_Relaxation_def.hpp:525
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
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:279
double getComputeFlops() const
Total number of floating-point operations over all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:567
double getApplyFlops() const
Total number of floating-point operations over all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:573
void setZeroStartingSolution(bool zeroStartingSolution)
Set this preconditioner&#39;s parameters.
Definition: Ifpack2_Relaxation_decl.hpp:408
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object&#39;s attributes to the given output stream.
Definition: Ifpack2_Relaxation_def.hpp:2295
Relaxation(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Relaxation_def.hpp:214
void compute()
Compute the preconditioner (&quot;numeric setup&quot;);.
Definition: Ifpack2_Relaxation_def.hpp:1025
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Relaxation_def.hpp:580
MatrixType::node_type::device_type device_type
The Kokkos device type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:266
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix and vectors are distributed.
Definition: Ifpack2_Relaxation_def.hpp:482
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:193
int getNumApply() const
Total number of calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:543
double getComputeTime() const
Total time in seconds spent in all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:555
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:263
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:502
void setParameters(const Teuchos::ParameterList &params)
Set the relaxation / preconditioner parameters.
Definition: Ifpack2_Relaxation_def.hpp:472
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Relaxation_def.hpp:2197
int getNumInitialize() const
Total number of calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:531
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_Relaxation_decl.hpp:426
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:515
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:260
double getInitializeTime() const
Total time in seconds spent in all calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:549
Declaration of interface for preconditioners that can change their matrix after construction.
static const EVerbosityLevel verbLevel_default
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:706
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:493
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:257
virtual ~Relaxation()=default
Destructor.
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:254
int getNumCompute() const
Total number of calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:537
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:418
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:237
double getApplyTime() const
Total time in seconds spent in all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:561
void initialize()
Initialize the preconditioner (&quot;symbolic setup&quot;).
Definition: Ifpack2_Relaxation_def.hpp:727
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:273
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:593
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition: Ifpack2_Relaxation_def.hpp:226
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Relaxation_decl.hpp:269