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_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 
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 
296 
298  virtual ~Relaxation();
299 
301 
303 
381  void setParameters (const Teuchos::ParameterList& params);
382 
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
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,
471 
474  getDomainMap () const;
475 
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 
506 
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
573  const Teuchos::EVerbosityLevel verbLevel =
576 
577 private:
579 
580 
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 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& B,
682  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
683  const Tpetra::ESweepDirection direction) const;
684 
686  void ApplyInverseSGS_RowMatrix(
687  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
688  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
689 
691  void
692  ApplyInverseSGS_CrsMatrix (const crs_matrix_type& A,
693  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
694  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y) const;
695 
697  void
698  ApplyInverseSGS_BlockCrsMatrix (const block_crs_matrix_type& A,
699  const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
700  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y);
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 
707 
709 
711 
718  mutable Teuchos::RCP<const Teuchos::ParameterList> validParams_;
719 
729 
730  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
731  typename block_crs_matrix_type::device_type> block_diag_type;
732  typedef Kokkos::View<typename block_crs_matrix_type::impl_scalar_type***,
733  typename block_crs_matrix_type::device_type,
734  Kokkos::MemoryUnmanaged> unmanaged_block_diag_type;
735 
750  block_diag_type blockDiag_;
751 
752  Teuchos::RCP<block_multivector_type> yBlockColumnPointMap_;
753 
755  int NumSweeps_;
757  Details::RelaxationType PrecType_;
759  scalar_type DampingFactor_;
761  bool IsParallel_;
763  bool ZeroStartingSolution_;
765  bool DoBackwardGS_;
767  bool DoL1Method_;
769  magnitude_type L1Eta_;
771  scalar_type MinDiagonalValue_;
773  bool fixTinyDiagEntries_;
775  bool checkDiagEntries_;
776 
778  bool is_matrix_structurally_symmetric_;
779 
781  bool ifpack2_dump_matrix_;
782 
783 
785  bool isInitialized_;
787  bool IsComputed_;
789  int NumInitialize_;
791  int NumCompute_;
793  mutable int NumApply_;
795  double InitializeTime_;
797  double ComputeTime_;
799  mutable double ApplyTime_;
801  double ComputeFlops_;
803  mutable double ApplyFlops_;
804 
806  magnitude_type globalMinMagDiagEntryMag_;
808  magnitude_type globalMaxMagDiagEntryMag_;
810  size_t globalNumSmallDiagEntries_;
812  size_t globalNumZeroDiagEntries_;
814  size_t globalNumNegDiagEntries_;
819  magnitude_type globalDiagNormDiff_;
820 
826  Kokkos::View<size_t*, typename node_type::device_type> diagOffsets_;
827 
833  bool savedDiagOffsets_;
834 
835  bool hasBlockCrsMatrix_;
836 
838  Teuchos::ArrayRCP<local_ordinal_type> localSmoothingIndices_;
839 
841 }; //class Relaxation
842 
843 }//namespace Ifpack2
844 
845 #endif // IFPACK2_RELAXATION_DECL_HPP
846 
bool hasTransposeApply() const
Whether apply() and applyMat() let you apply the transpose or conjugate transpose.
Definition: Ifpack2_Relaxation_def.hpp:409
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:451
double getApplyFlops() const
Total number of floating-point operations over all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:457
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:2497
Relaxation(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Relaxation_def.hpp:177
void compute()
Compute the preconditioner.
Definition: Ifpack2_Relaxation_def.hpp:883
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_Relaxation_def.hpp:464
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the matrix and vectors are distributed.
Definition: Ifpack2_Relaxation_def.hpp:366
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:157
int getNumApply() const
Total number of calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:427
double getComputeTime() const
Total time in seconds spent in all calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:439
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:247
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:386
void setParameters(const Teuchos::ParameterList &params)
Set the relaxation / preconditioner parameters.
Definition: Ifpack2_Relaxation_def.hpp:356
std::string description() const
A simple one-line description of this object.
Definition: Ifpack2_Relaxation_def.hpp:2442
int getNumInitialize() const
Total number of calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:415
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:413
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:399
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:244
double getInitializeTime() const
Total time in seconds spent in all calls to initialize().
Definition: Ifpack2_Relaxation_def.hpp:433
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 preconditioner to X, returning the result in Y.
Definition: Ifpack2_Relaxation_def.hpp:584
Teuchos::RCP< const row_matrix_type > getMatrix() const
The matrix to be preconditioned.
Definition: Ifpack2_Relaxation_def.hpp:377
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Relaxation_decl.hpp:241
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:218
int getNumCompute() const
Total number of calls to compute().
Definition: Ifpack2_Relaxation_def.hpp:421
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack2_Relaxation_decl.hpp:398
Relaxation preconditioners for Tpetra::RowMatrix and Tpetra::CrsMatrix sparse matrices.
Definition: Ifpack2_Relaxation_decl.hpp:223
double getApplyTime() const
Total time in seconds spent in all calls to apply().
Definition: Ifpack2_Relaxation_def.hpp:445
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Relaxation_def.hpp:605
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
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:477
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a list of all the parameters that this class accepts.
Definition: Ifpack2_Relaxation_def.hpp:223
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_Relaxation_decl.hpp:250