Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_RILUK_decl.hpp
Go to the documentation of this file.
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 
45 
46 #ifndef IFPACK2_CRSRILUK_DECL_HPP
47 #define IFPACK2_CRSRILUK_DECL_HPP
48 
49 #include "KokkosSparse_spiluk.hpp"
50 
53 #include "Tpetra_CrsMatrix_decl.hpp"
54 #include "Ifpack2_ScalingType.hpp"
55 #include "Ifpack2_IlukGraph.hpp"
56 #include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
57 
58 #include <type_traits>
59 
60 namespace Teuchos {
61  class ParameterList; // forward declaration
62 }
63 
64 namespace Ifpack2 {
65 
244 template<class MatrixType>
245 class RILUK:
246  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
247  typename MatrixType::local_ordinal_type,
248  typename MatrixType::global_ordinal_type,
249  typename MatrixType::node_type>,
250  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
251  typename MatrixType::local_ordinal_type,
252  typename MatrixType::global_ordinal_type,
253  typename MatrixType::node_type> >
254 {
255  public:
257  typedef typename MatrixType::scalar_type scalar_type;
258 
260  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
261 
263  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
264 
266  typedef typename MatrixType::node_type node_type;
267 
269  typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
270 
272  typedef typename node_type::device_type device_type;
273 
275  typedef typename node_type::execution_space execution_space;
276 
278  typedef Tpetra::RowMatrix<scalar_type,
282 
283 
284  static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::RILUK: The template parameter MatrixType must be a Tpetra::RowMatrix specialization. Please don't use Tpetra::CrsMatrix (a subclass of Tpetra::RowMatrix) here anymore.");
285 
287  typedef Tpetra::CrsMatrix<scalar_type,
291 
293  typedef typename crs_matrix_type::impl_scalar_type impl_scalar_type;
294 
295  template <class NewMatrixType> friend class RILUK;
296 
297  typedef typename crs_matrix_type::global_inds_host_view_type global_inds_host_view_type;
298  typedef typename crs_matrix_type::local_inds_host_view_type local_inds_host_view_type;
299  typedef typename crs_matrix_type::values_host_view_type values_host_view_type;
300 
301 
302  typedef typename crs_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
303  typedef typename crs_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
304  typedef typename crs_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
305 
306 
308 
310 
311  typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
312  typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
313  typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
314  typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
315  typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space TemporaryMemorySpace;
316  typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space PersistentMemorySpace;
317  typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::execution_space HandleExecSpace;
318  typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
319  <typename lno_row_view_t::const_value_type, typename lno_nonzero_view_t::const_value_type, typename scalar_nonzero_view_t::value_type,
320  HandleExecSpace, TemporaryMemorySpace,PersistentMemorySpace > kk_handle_type;
321 
325  RILUK (const Teuchos::RCP<const row_matrix_type>& A_in);
326 
334  RILUK (const Teuchos::RCP<const crs_matrix_type>& A_in);
335 
336  private:
339  RILUK (const RILUK<MatrixType> & src);
340 
341  public:
343  virtual ~RILUK ();
344 
353  void setParameters (const Teuchos::ParameterList& params);
354 
356  void initialize ();
357 
366  void compute ();
367 
369  bool isInitialized () const {
370  return isInitialized_;
371  }
373  bool isComputed () const {
374  return isComputed_;
375  }
376 
378  int getNumInitialize () const {
379  return numInitialize_;
380  }
382  int getNumCompute () const {
383  return numCompute_;
384  }
386  int getNumApply () const {
387  return numApply_;
388  }
389 
391  double getInitializeTime () const {
392  return initializeTime_;
393  }
395  double getComputeTime () const {
396  return computeTime_;
397  }
399  double getApplyTime () const {
400  return applyTime_;
401  }
402 
404  size_t getNodeSmootherComplexity() const;
405 
406 
407 
409 
410 
433  virtual void
434  setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
435 
437 
439 
441  std::string description () const;
442 
444 
446 
448  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
449  getDomainMap () const;
450 
452  Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
453  getRangeMap () const;
454 
484  void
485  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
486  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
487  Teuchos::ETransp mode = Teuchos::NO_TRANS,
488  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
489  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const;
491 
492 private:
514  void
515  multiply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
516  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
517  const Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
518 public:
519 
521  Teuchos::RCP<const row_matrix_type> getMatrix () const;
522 
523  // Attribute access functions
524 
526  magnitude_type getRelaxValue () const { return RelaxValue_; }
527 
529  magnitude_type getAbsoluteThreshold () const { return Athresh_; }
530 
532  magnitude_type getRelativeThreshold () const {return Rthresh_;}
533 
535  int getLevelOfFill () const { return LevelOfFill_; }
536 
538  Tpetra::CombineMode getOverlapMode () {
539  TEUCHOS_TEST_FOR_EXCEPTION(
540  true, std::logic_error, "Ifpack2::RILUK::SetOverlapMode: "
541  "RILUK no longer implements overlap on its own. "
542  "Use RILUK with AdditiveSchwarz if you want overlap.");
543  }
544 
546  Tpetra::global_size_t getGlobalNumEntries () const {
547  return getL ().getGlobalNumEntries () + getU ().getGlobalNumEntries ();
548  }
549 
551  Teuchos::RCP<Ifpack2::IlukGraph<Tpetra::CrsGraph<local_ordinal_type,
553  node_type>, kk_handle_type> > getGraph () const {
554  return Graph_;
555  }
556 
558  const crs_matrix_type& getL () const;
559 
561  const Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>&
562  getD () const;
563 
565  const crs_matrix_type& getU () const;
566 
568  Teuchos::RCP<const crs_matrix_type> getCrsMatrix () const;
569 
570 private:
571  typedef Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> MV;
572  typedef Teuchos::ScalarTraits<scalar_type> STS;
573  typedef Teuchos::ScalarTraits<magnitude_type> STM;
574 
575  void allocateSolvers ();
576  void allocate_L_and_U ();
577  static void checkOrderingConsistency (const row_matrix_type& A);
578  void initAllValues (const row_matrix_type& A);
579 
585  static Teuchos::RCP<const row_matrix_type>
586  makeLocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
587 
588 protected:
589  typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vec_type;
590 
592  Teuchos::RCP<const row_matrix_type> A_;
593 
595  Teuchos::RCP<Ifpack2::IlukGraph<Tpetra::CrsGraph<local_ordinal_type,
597  node_type>, kk_handle_type> > Graph_;
601  Teuchos::RCP<const row_matrix_type> A_local_;
602  lno_row_view_t A_local_rowmap_;
603  lno_nonzero_view_t A_local_entries_;
604  scalar_nonzero_view_t A_local_values_;
605 
607  Teuchos::RCP<crs_matrix_type> L_;
609  Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > L_solver_;
611  Teuchos::RCP<crs_matrix_type> U_;
613  Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > U_solver_;
614 
616  Teuchos::RCP<vec_type> D_;
617 
618  int LevelOfFill_;
619  double Overalloc_;
620 
621  bool isAllocated_;
622  bool isInitialized_;
623  bool isComputed_;
624 
625  int numInitialize_;
626  int numCompute_;
627  mutable int numApply_;
628 
629  double initializeTime_;
630  double computeTime_;
631  mutable double applyTime_;
632 
633  magnitude_type RelaxValue_;
634  magnitude_type Athresh_;
635  magnitude_type Rthresh_;
636 
639  Teuchos::RCP<kk_handle_type> KernelHandle_;
640 };
641 
642 // NOTE (mfh 11 Feb 2015) This used to exist in order to deal with
643 // different behavior of Tpetra::Crs{Graph,Matrix} for
644 // KokkosClassic::ThrustGPUNode. In particular, fillComplete on a
645 // CrsMatrix used to make the graph go away by default, so we had to
646 // pass in a parameter to keep a host copy of the graph. With the new
647 // (Kokkos refactor) version of Tpetra, this problem has gone away.
648 namespace detail {
649  template<class MatrixType, class NodeType>
650  struct setLocalSolveParams{
651  static Teuchos::RCP<Teuchos::ParameterList>
652  setParams (const Teuchos::RCP<Teuchos::ParameterList>& param) {
653  return param;
654  }
655  };
656 } // namespace detail
657 
658 } // namespace Ifpack2
659 
660 #endif /* IFPACK2_CRSRILUK_DECL_HPP */
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
Declaration and definition of IlukGraph.
Ifpack2::ScalingType enumerable type.
double getComputeTime() const
Total time in seconds taken by all successful compute() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:395
int getNumApply() const
Number of successful apply() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:386
node_type::execution_space execution_space
The Kokkos execution space of the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:275
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:263
Teuchos::RCP< crs_matrix_type > L_
The L (lower triangular) factor of ILU(k).
Definition: Ifpack2_RILUK_decl.hpp:607
void initialize()
Initialize by computing the symbolic incomplete factorization.
Definition: Ifpack2_RILUK_def.hpp:452
Teuchos::RCP< const row_matrix_type > getMatrix() const
Get the input matrix.
Definition: Ifpack2_RILUK_def.hpp:405
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization used by this class.
Definition: Ifpack2_RILUK_decl.hpp:281
Teuchos::RCP< const crs_matrix_type > getCrsMatrix() const
Return the input matrix A as a Tpetra::CrsMatrix, if possible; else throws.
Definition: Ifpack2_RILUK_def.hpp:412
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_RILUK_def.hpp:137
void setParameters(const Teuchos::ParameterList &params)
Definition: Ifpack2_RILUK_def.hpp:300
bool isKokkosKernelsSpiluk_
Optional KokkosKernels implementation.
Definition: Ifpack2_RILUK_decl.hpp:638
ILU(k) factorization of a given Tpetra::RowMatrix.
Definition: Ifpack2_RILUK_decl.hpp:245
Tpetra::CombineMode getOverlapMode()
Get overlap mode type.
Definition: Ifpack2_RILUK_decl.hpp:538
bool isComputed() const
Whether compute() has been called on this object.
Definition: Ifpack2_RILUK_decl.hpp:373
double getApplyTime() const
Total time in seconds taken by all successful apply() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:399
Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > crs_matrix_type
Tpetra::CrsMatrix specialization used by this class for representing L and U.
Definition: Ifpack2_RILUK_decl.hpp:284
magnitude_type getAbsoluteThreshold() const
Get absolute threshold value.
Definition: Ifpack2_RILUK_decl.hpp:529
node_type::device_type device_type
The Kokkos device type of the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:272
Teuchos::RCP< Ifpack2::IlukGraph< Tpetra::CrsGraph< local_ordinal_type, global_ordinal_type, node_type >, kk_handle_type > > Graph_
The ILU(k) graph.
Definition: Ifpack2_RILUK_decl.hpp:597
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:266
const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > & getD() const
Return the diagonal entries of the ILU factorization.
Definition: Ifpack2_RILUK_def.hpp:190
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:260
virtual ~RILUK()
Destructor (declared virtual for memory safety).
Definition: Ifpack2_RILUK_def.hpp:120
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition: Ifpack2_RILUK_def.hpp:217
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > U_solver_
Sparse triangular solver for U.
Definition: Ifpack2_RILUK_decl.hpp:613
int getNumCompute() const
Number of successful compute() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:382
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_RILUK_def.hpp:234
magnitude_type getRelaxValue() const
Get RILU(k) relaxation parameter.
Definition: Ifpack2_RILUK_decl.hpp:526
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
void compute()
Compute the (numeric) incomplete factorization.
Definition: Ifpack2_RILUK_def.hpp:717
const crs_matrix_type & getU() const
Return the U factor of the ILU factorization.
Definition: Ifpack2_RILUK_def.hpp:204
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition: Ifpack2_RILUK_decl.hpp:269
crs_matrix_type::impl_scalar_type impl_scalar_type
Scalar type stored in Kokkos::Views (CrsMatrix and MultiVector)
Definition: Ifpack2_RILUK_decl.hpp:293
Construct a level filled graph for use in computing an ILU(k) incomplete factorization.
Definition: Ifpack2_IlukGraph.hpp:100
Declaration of interface for preconditioners that can change their matrix after construction.
Teuchos::RCP< Ifpack2::IlukGraph< Tpetra::CrsGraph< local_ordinal_type, global_ordinal_type, node_type >, kk_handle_type > > getGraph() const
Return the Ifpack2::IlukGraph associated with this factored matrix.
Definition: Ifpack2_RILUK_decl.hpp:553
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > L_solver_
Sparse triangular solver for L.
Definition: Ifpack2_RILUK_decl.hpp:609
bool isInitialized() const
Whether initialize() has been called on this object.
Definition: Ifpack2_RILUK_decl.hpp:369
Teuchos::RCP< const row_matrix_type > A_
The (original) input matrix for which to compute ILU(k).
Definition: Ifpack2_RILUK_decl.hpp:592
Tpetra::global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition: Ifpack2_RILUK_decl.hpp:546
Definition: Ifpack2_Container_decl.hpp:576
Teuchos::RCP< vec_type > D_
The diagonal entries of the ILU(k) factorization.
Definition: Ifpack2_RILUK_decl.hpp:616
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 (inverse of the) incomplete factorization to X, resulting in Y.
Definition: Ifpack2_RILUK_def.hpp:973
std::string description() const
A one-line description of this object.
Definition: Ifpack2_RILUK_def.hpp:1125
magnitude_type getRelativeThreshold() const
Get relative threshold value.
Definition: Ifpack2_RILUK_decl.hpp:532
int getNumInitialize() const
Number of successful initialize() calls for this object.
Definition: Ifpack2_RILUK_decl.hpp:378
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:73
int getLevelOfFill() const
Get level of fill (the "k" in ILU(k)).
Definition: Ifpack2_RILUK_decl.hpp:535
double getInitializeTime() const
Total time in seconds taken by all successful initialize() calls for this object. ...
Definition: Ifpack2_RILUK_decl.hpp:391
Teuchos::RCP< const row_matrix_type > A_local_
The matrix whos numbers are used to to compute ILU(k). The graph may be computed using a crs_matrix_t...
Definition: Ifpack2_RILUK_decl.hpp:601
Teuchos::RCP< crs_matrix_type > U_
The U (upper triangular) factor of ILU(k).
Definition: Ifpack2_RILUK_decl.hpp:611
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_RILUK_def.hpp:253
const crs_matrix_type & getL() const
Return the L factor of the ILU factorization.
Definition: Ifpack2_RILUK_def.hpp:173
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_RILUK_decl.hpp:257