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 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_RELAXATION_DECL_HPP
44 #define IFPACK2_RELAXATION_DECL_HPP
45 
48 #include "Ifpack2_Parameters.hpp"
49 #include "Tpetra_Vector.hpp"
50 #include "Teuchos_ScalarTraits.hpp"
51 #include "Tpetra_CrsMatrix.hpp" // Don't need the definition here
52 #include "Tpetra_BlockCrsMatrix.hpp"
53 #include <type_traits>
54 #include <KokkosKernels_Handle.hpp>
55 
56 
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 namespace Ifpack2 {
59 namespace Details {
60 
61 template<class TpetraOperatorType>
62 class ScaledDampedResidual; // forward declaration
63 
64 } // namespace Details
65 } // namespace Ifpack2
66 
67 namespace Teuchos {
68  // forward declarations
69  class ParameterList;
70  class Time;
71 } // namespace Teuchos
72 #endif // DOXYGEN_SHOULD_SKIP_THIS
73 
74 namespace Ifpack2 {
75 
231 template<class MatrixType>
232 class Relaxation :
233  virtual public Ifpack2::Preconditioner<
234  typename MatrixType::scalar_type,
235  typename MatrixType::local_ordinal_type,
236  typename MatrixType::global_ordinal_type,
237  typename MatrixType::node_type>,
238  virtual public Ifpack2::Details::CanChangeMatrix<
239  Tpetra::RowMatrix<typename MatrixType::scalar_type,
240  typename MatrixType::local_ordinal_type,
241  typename MatrixType::global_ordinal_type,
242  typename MatrixType::node_type> >
243 {
244 public:
246 
247 
249  typedef typename MatrixType::scalar_type scalar_type;
250 
252  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
253 
255  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
256 
258  typedef typename MatrixType::node_type node_type;
259 
262 
264  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
266 
267  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.");
268 
270 
272 
304 
306  virtual ~Relaxation () = default;
307 
309 
311 
389  void setParameters (const Teuchos::ParameterList& params);
390 
393  getValidParameters () const;
394 
396  void initialize ();
397 
399  inline bool isInitialized() const {
400  return isInitialized_;
401  }
402 
404  void compute ();
405 
407  inline bool isComputed() const {
408  return IsComputed_;
409  }
410 
412 
414 
437  virtual void
439 
441 
443 
459  void
460  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
461  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
465 
468  getDomainMap () const;
469 
472  getRangeMap () const;
473 
476  bool hasTransposeApply () const;
477 
484  void
485  applyMat (const Tpetra::MultiVector<
486  scalar_type,
489  node_type>& X,
490  Tpetra::MultiVector<
491  scalar_type,
494  node_type>& Y,
495  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
496 
498 
500 
503 
506 
508  double getComputeFlops() const;
509 
511  double getApplyFlops() const;
512 
514  int getNumInitialize() const;
515 
517  int getNumCompute() const;
518 
520  int getNumApply() const;
521 
523  double getInitializeTime() const;
524 
526  double getComputeTime() const;
527 
529  double getApplyTime() const;
530 
532  size_t getNodeSmootherComplexity() const;
533 
535 
537 
544  std::string description () const;
545 
568  void
570  const Teuchos::EVerbosityLevel verbLevel =
573 
574 private:
576 
577 
580 
585  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
586  global_ordinal_type, node_type> crs_matrix_type;
587  typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type,
588  global_ordinal_type, node_type> block_crs_matrix_type;
589  typedef Tpetra::BlockMultiVector<scalar_type, local_ordinal_type,
590  global_ordinal_type, node_type> block_multivector_type;
591 
592 
594 
596 
597  typedef typename crs_matrix_type::local_matrix_type local_matrix_type;
598  typedef typename local_matrix_type::StaticCrsGraphType::row_map_type lno_row_view_t;
599  typedef typename local_matrix_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
600  typedef typename local_matrix_type::values_type scalar_nonzero_view_t;
601  typedef typename local_matrix_type::StaticCrsGraphType::device_type TemporaryWorkSpace;
602  typedef typename local_matrix_type::StaticCrsGraphType::device_type PersistentWorkSpace;
603  typedef typename local_matrix_type::StaticCrsGraphType::execution_space MyExecSpace;
604  typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
605  <typename lno_row_view_t::const_value_type, local_ordinal_type,typename scalar_nonzero_view_t::value_type,
606  MyExecSpace, TemporaryWorkSpace,PersistentWorkSpace > mt_kernel_handle_type;
607  Teuchos::RCP<mt_kernel_handle_type> mtKernelHandle_;
608 
610 
612 
614  Relaxation (const Relaxation<MatrixType>& RHS);
615 
617  Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
618 
620 
622 
627  void setParametersImpl (Teuchos::ParameterList& params);
628 
630  void ApplyInverseJacobi(
631  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
632  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
633 
635  void ApplyInverseJacobi_BlockCrsMatrix(
636  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
637  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
638 
640  void ApplyInverseGS(
641  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
642  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
643 
645  void ApplyInverseMTGS_CrsMatrix(
646  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
647  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
648 
649 
651  void ApplyInverseGS_RowMatrix(
652  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
653  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
654 
656  void
657  ApplyInverseGS_CrsMatrix (const crs_matrix_type& A,
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
663  ApplyInverseGS_BlockCrsMatrix (const block_crs_matrix_type& A,
664  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
665  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
666 
668  void ApplyInverseSGS(
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) const;
671 
673  void ApplyInverseMTSGS_CrsMatrix(
674  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
675  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
676 
677  void MTGaussSeidel (
678  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
679  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
680  const Tpetra::ESweepDirection direction) const;
681 
683  void ApplyInverseSGS_RowMatrix(
684  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
685  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
686 
688  void
689  ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
690  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
691  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
692 
694  void
695  ApplyInverseSGS_BlockCrsMatrix (const block_crs_matrix_type& A,
696  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
697  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
698 
699  void computeBlockCrs ();
700 
702  void updateCachedMultiVector(const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& map, size_t numVecs) const;
703 
704 
706 
708 
715  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
716 
726 
727  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
728  typename block_crs_matrix_type::device_type> block_diag_type;
729  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
730  typename block_crs_matrix_type::device_type,
731  Kokkos::MemoryUnmanaged> unmanaged_block_diag_type;
732 
747  block_diag_type blockDiag_;
748 
749  Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
750 
752  int NumSweeps_;
754  Details::RelaxationType PrecType_;
756  scalar_type DampingFactor_;
758  bool IsParallel_;
760  bool ZeroStartingSolution_;
762  bool DoBackwardGS_;
764  bool DoL1Method_;
766  magnitude_type L1Eta_;
768  scalar_type MinDiagonalValue_;
770  bool fixTinyDiagEntries_;
772  bool checkDiagEntries_;
773 
775  bool is_matrix_structurally_symmetric_;
776 
778  bool ifpack2_dump_matrix_;
779 
780 
782  bool isInitialized_;
784  bool IsComputed_;
786  int NumInitialize_;
788  int NumCompute_;
790  mutable int NumApply_;
792  double InitializeTime_;
794  double ComputeTime_;
796  mutable double ApplyTime_;
798  double ComputeFlops_;
800  mutable double ApplyFlops_;
801 
803  magnitude_type globalMinMagDiagEntryMag_;
805  magnitude_type globalMaxMagDiagEntryMag_;
807  size_t globalNumSmallDiagEntries_;
809  size_t globalNumZeroDiagEntries_;
811  size_t globalNumNegDiagEntries_;
816  magnitude_type globalDiagNormDiff_;
817 
823  Kokkos::View<size_t*, typename node_type::device_type> diagOffsets_;
824 
830  bool savedDiagOffsets_;
831 
832  bool hasBlockCrsMatrix_;
833 
835  Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
836 
838 }; //class Relaxation
839 
840 }//namespace Ifpack2
841 
842 #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:444
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
double getComputeFlops() const
Total number of floating-point operations over all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:486
double getApplyFlops() const
Total number of floating-point operations over all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:492
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:2577
Relaxation(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Relaxation_def.hpp:216
void compute()
Compute the preconditioner (&quot;numeric setup&quot;);.
Definition: Ifpack2_Relaxation_def.hpp:928
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Relaxation_def.hpp:499
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix and vectors are distributed.
Definition: Ifpack2_Relaxation_def.hpp:401
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:196
int getNumApply() const
Total number of calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:462
double getComputeTime() const
Total time in seconds spent in all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:474
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:258
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:421
void setParameters(const Teuchos::ParameterList &params)
Set the relaxation / preconditioner parameters.
Definition: Ifpack2_Relaxation_def.hpp:391
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Relaxation_def.hpp:2522
int getNumInitialize() const
Total number of calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:450
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:407
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:434
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:255
double getInitializeTime() const
Total time in seconds spent in all calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:468
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:615
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:412
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:252
virtual ~Relaxation()=default
Destructor.
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:249
int getNumCompute() const
Total number of calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:456
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:399
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:232
double getApplyTime() const
Total time in seconds spent in all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:480
void initialize()
Initialize the preconditioner (&quot;symbolic setup&quot;).
Definition: Ifpack2_Relaxation_def.hpp:636
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:265
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:512
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition: Ifpack2_Relaxation_def.hpp:258
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Relaxation_decl.hpp:261