Ifpack2 Templated Preconditioning Package  Version 1.0
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_decl.hpp" // Don't need the definition here
52 #include "Tpetra_Experimental_BlockCrsMatrix_decl.hpp"
53 #include <type_traits>
54 #include <KokkosKernels_Handle.hpp>
55 
56 namespace Teuchos {
57  // forward declarations
58  class ParameterList;
59  class Time;
60 } // namespace Teuchos
61 
62 namespace Ifpack2 {
63 
222 template<class MatrixType>
223 class Relaxation :
224  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
225  typename MatrixType::local_ordinal_type,
226  typename MatrixType::global_ordinal_type,
227  typename MatrixType::node_type>,
228  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
229  typename MatrixType::local_ordinal_type,
230  typename MatrixType::global_ordinal_type,
231  typename MatrixType::node_type> >
232 {
233 public:
235 
236 
238  typedef typename MatrixType::scalar_type scalar_type;
239 
241  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
242 
244  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
245 
247  typedef typename MatrixType::node_type node_type;
248 
250  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
251 
253  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
255 
256  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.");
257 
259 
261 
295  explicit Relaxation (const Teuchos::RCP<const row_matrix_type>& A);
296 
298  virtual ~Relaxation();
299 
301 
303 
381  void setParameters (const Teuchos::ParameterList& params);
382 
384  Teuchos::RCP<const Teuchos::ParameterList>
385  getValidParameters () const;
386 
395  void initialize ();
396 
398  inline bool isInitialized() const {
399  return isInitialized_;
400  }
401 
409  void compute ();
410 
411 
413  inline bool isComputed() const {
414  return(IsComputed_);
415  }
416 
418 
420 
443  virtual void
444  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
445 
447 
449 
465  void
466  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
467  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
468  Teuchos::ETransp mode = Teuchos::NO_TRANS,
469  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
470  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
471 
473  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
474  getDomainMap () const;
475 
477  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
478  getRangeMap () const;
479 
481  bool hasTransposeApply () const;
482 
495  void
496  applyMat (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
497  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
498  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
499 
501 
503 
505  Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
506 
508  Teuchos::RCP<const row_matrix_type> getMatrix () const;
509 
511  double getComputeFlops() const;
512 
514  double getApplyFlops() const;
515 
517  int getNumInitialize() const;
518 
520  int getNumCompute() const;
521 
523  int getNumApply() const;
524 
526  double getInitializeTime() const;
527 
529  double getComputeTime() const;
530 
532  double getApplyTime() const;
533 
535  size_t getNodeSmootherComplexity() const;
536 
538 
540 
547  std::string description () const;
548 
571  void
572  describe (Teuchos::FancyOStream &out,
573  const Teuchos::EVerbosityLevel verbLevel =
574  Teuchos::Describable::verbLevel_default) const;
576 
577 private:
579 
580 
581  typedef Teuchos::ScalarTraits<scalar_type> STS;
582  typedef Teuchos::ScalarTraits<magnitude_type> STM;
583 
588  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
589  global_ordinal_type, node_type> crs_matrix_type;
590  typedef Tpetra::Experimental::BlockCrsMatrix<scalar_type, local_ordinal_type,
591  global_ordinal_type, node_type> block_crs_matrix_type;
592  typedef Tpetra::Experimental::BlockMultiVector<scalar_type, local_ordinal_type,
593  global_ordinal_type, node_type> block_multivector_type;
594 
595 
597 
599 
600  typedef typename crs_matrix_type::local_matrix_type local_matrix_type;
601  typedef typename local_matrix_type::StaticCrsGraphType::row_map_type lno_row_view_t;
602  typedef typename local_matrix_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
603  typedef typename local_matrix_type::values_type scalar_nonzero_view_t;
604  typedef typename local_matrix_type::StaticCrsGraphType::device_type TemporaryWorkSpace;
605  typedef typename local_matrix_type::StaticCrsGraphType::device_type PersistentWorkSpace;
606  typedef typename local_matrix_type::StaticCrsGraphType::execution_space MyExecSpace;
607  typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
608  <typename lno_row_view_t::const_value_type, local_ordinal_type,typename scalar_nonzero_view_t::value_type,
609  MyExecSpace, TemporaryWorkSpace,PersistentWorkSpace > mt_kernel_handle_type;
610  Teuchos::RCP<mt_kernel_handle_type> mtKernelHandle_;
611 
613 
615 
617  Relaxation (const Relaxation<MatrixType>& RHS);
618 
620  Relaxation<MatrixType>& operator= (const Relaxation<MatrixType>& RHS);
621 
623 
625 
630  void setParametersImpl (Teuchos::ParameterList& params);
631 
633  void ApplyInverseJacobi(
634  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
635  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
636 
638  void ApplyInverseJacobi_BlockCrsMatrix(
639  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
640  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
641 
643  void ApplyInverseGS(
644  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
645  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
646 
648  void ApplyInverseMTGS_CrsMatrix(
649  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
650  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
651 
652 
654  void ApplyInverseGS_RowMatrix(
655  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
656  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
657 
659  void
660  ApplyInverseGS_CrsMatrix (const crs_matrix_type& A,
661  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
662  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
663 
665  void
666  ApplyInverseGS_BlockCrsMatrix (const block_crs_matrix_type& A,
667  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
668  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
669 
671  void ApplyInverseSGS(
672  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
673  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
674 
676  void ApplyInverseMTSGS_CrsMatrix(
677  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
678  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
679 
680  void MTGaussSeidel (
681  const crs_matrix_type* crsMat,
682  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
683  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
684  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& D,
685  const scalar_type& dampingFactor,
686  const Tpetra::ESweepDirection direction,
687  const int numSweeps,
688  const bool zeroInitialGuess) const;
689 
691  void ApplyInverseSGS_RowMatrix(
692  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
693  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
694 
696  void
697  ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
698  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
699  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
700 
702  void
703  ApplyInverseSGS_BlockCrsMatrix (const block_crs_matrix_type& A,
704  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
705  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
706 
707  void computeBlockCrs ();
708 
710  void updateCachedMultiVector(const Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >& map, size_t numVecs) const;
711 
712 
714 
716 
723  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
724 
726  Teuchos::RCP<const row_matrix_type> A_;
729  Teuchos::RCP<const Tpetra::Import<local_ordinal_type,global_ordinal_type,node_type> > Importer_;
731  Teuchos::RCP<Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > Diagonal_;
733  mutable Teuchos::RCP<Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> > cachedMV_;
734 
735  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
736  typename block_crs_matrix_type::device_type> block_diag_type;
737  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
738  typename block_crs_matrix_type::device_type,
739  Kokkos::MemoryUnmanaged> unmanaged_block_diag_type;
740 
755  block_diag_type blockDiag_;
756 
757  Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
758 
760  int NumSweeps_;
762  Details::RelaxationType PrecType_;
764  scalar_type DampingFactor_;
766  bool IsParallel_;
768  bool ZeroStartingSolution_;
770  bool DoBackwardGS_;
772  bool DoL1Method_;
774  magnitude_type L1Eta_;
776  scalar_type MinDiagonalValue_;
778  bool fixTinyDiagEntries_;
780  bool checkDiagEntries_;
781 
783  bool is_matrix_structurally_symmetric_;
784 
786  bool ifpack2_dump_matrix_;
787 
788 
790  bool isInitialized_;
792  bool IsComputed_;
794  int NumInitialize_;
796  int NumCompute_;
798  mutable int NumApply_;
800  double InitializeTime_;
802  double ComputeTime_;
804  mutable double ApplyTime_;
806  double ComputeFlops_;
808  mutable double ApplyFlops_;
809 
811  magnitude_type globalMinMagDiagEntryMag_;
813  magnitude_type globalMaxMagDiagEntryMag_;
815  size_t globalNumSmallDiagEntries_;
817  size_t globalNumZeroDiagEntries_;
819  size_t globalNumNegDiagEntries_;
824  magnitude_type globalDiagNormDiff_;
825 
831  Kokkos::View<size_t*, typename node_type::device_type> diagOffsets_;
832 
838  bool savedDiagOffsets_;
839 
840  bool hasBlockCrsMatrix_;
841 
843  Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
844 
846 }; //class Relaxation
847 
848 }//namespace Ifpack2
849 
850 #endif // IFPACK2_RELAXATION_DECL_HPP
851 
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Relaxation_def.hpp:2454
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:406
int getNumInitialize() const
Total number of calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:422
double getApplyTime() const
Total time in seconds spent in all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:452
Relaxation(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Relaxation_def.hpp:184
void compute()
Compute the preconditioner.
Definition: Ifpack2_Relaxation_def.hpp:882
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:484
bool hasTransposeApply() const
Whether apply() and applyMat() let you apply the transpose or conjugate transpose.
Definition: Ifpack2_Relaxation_def.hpp:416
int getNumApply() const
Total number of calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:434
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:398
double getInitializeTime() const
Total time in seconds spent in all calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:440
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:164
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:393
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:384
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:247
void setParameters(const Teuchos::ParameterList &params)
Set the relaxation / preconditioner parameters.
Definition: Ifpack2_Relaxation_def.hpp:363
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Relaxation_def.hpp:471
double getApplyFlops() const
Total number of floating-point operations over all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:464
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition: Ifpack2_Relaxation_def.hpp:230
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:244
Declaration of interface for preconditioners that can change their matrix after construction.
double getComputeFlops() const
Total number of floating-point operations over all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:458
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_Relaxation_decl.hpp:413
double getComputeTime() const
Total time in seconds spent in all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:446
Definition: Ifpack2_Container.hpp:774
int getNumCompute() const
Total number of calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:428
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:241
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix and vectors are distributed.
Definition: Ifpack2_Relaxation_def.hpp:373
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:238
virtual ~Relaxation()
Destructor.
Definition: Ifpack2_Relaxation_def.hpp:225
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 preconditioner to X, returning the result in Y.
Definition: Ifpack2_Relaxation_def.hpp:586
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:223
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:2509
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Relaxation_def.hpp:607
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:254
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Relaxation_decl.hpp:250