Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_ILUT_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4//
5// Copyright 2009 NTESS and the Ifpack2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
12
13#ifndef IFPACK2_ILUT_DECL_HPP
14#define IFPACK2_ILUT_DECL_HPP
15
16#include "KokkosSparse_par_ilut.hpp"
17
20#include "Tpetra_CrsMatrix_decl.hpp"
21#include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
22
23#include <string>
24#include <sstream>
25#include <iostream>
26#include <cmath>
27#include <type_traits>
28
29namespace Teuchos {
30 class ParameterList; // forward declaration
31}
32
33namespace Ifpack2 {
34
59template<class MatrixType>
60class ILUT :
61 virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
62 typename MatrixType::local_ordinal_type,
63 typename MatrixType::global_ordinal_type,
64 typename MatrixType::node_type>,
65 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
66 typename MatrixType::local_ordinal_type,
67 typename MatrixType::global_ordinal_type,
68 typename MatrixType::node_type> >
69{
70public:
72
73
75 typedef typename MatrixType::scalar_type scalar_type;
76
78 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
79
81 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
82
84 typedef typename MatrixType::node_type node_type;
85
87 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
88
90 typedef Tpetra::RowMatrix<scalar_type,
94
95 typedef typename row_matrix_type::global_inds_host_view_type global_inds_host_view_type;
96 typedef typename row_matrix_type::local_inds_host_view_type local_inds_host_view_type;
97 typedef typename row_matrix_type::values_host_view_type values_host_view_type;
98
99 typedef typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
100 typedef typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
101 typedef typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
102
103 static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::ILUT: The template parameter MatrixType must be a Tpetra::RowMatrix specialization. Please don't use Tpetra::CrsMatrix (a subclass of Tpetra::RowMatrix) here anymore. The constructor can take either a RowMatrix or a CrsMatrix just fine.");
104
106 typedef Tpetra::CrsMatrix<scalar_type,
110
112 typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
113 typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
115 typedef Tpetra::CrsGraph<local_ordinal_type, global_ordinal_type, node_type> crs_graph_type;
116 typedef typename crs_graph_type::local_graph_device_type local_graph_device_type;
117 typedef typename local_graph_device_type::array_layout array_layout;
118 typedef typename local_graph_device_type::device_type device_type;
119 typedef typename local_graph_device_type::size_type usize_type;
120 //KokkosKernels requires unsigned
121 //typedef typename Kokkos::View<size_type*, array_layout, device_type> lno_row_view_t;
122 typedef typename Kokkos::View<usize_type*, array_layout, device_type> lno_urow_view_t;
124 typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
125 //typedef typename Kokkos::View<lno_nonzero_view_t*, array_layout, device_type> static_graph_entries_t;
126 typedef typename Kokkos::View<typename local_matrix_device_type::non_const_ordinal_type*, array_layout, device_type> static_graph_entries_t;
127 typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
128 //typedef typename Kokkos::View<scalar_nonzero_view_t*, array_layout, device_type> local_matrix_values_t;
129 typedef typename Kokkos::View<typename local_matrix_device_type::non_const_value_type*, array_layout, device_type> local_matrix_values_t;
130 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space TemporaryMemorySpace;
131 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space PersistentMemorySpace;
132 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::execution_space HandleExecSpace;
133 typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
134 <typename lno_row_view_t::const_value_type, typename lno_nonzero_view_t::const_value_type, typename scalar_nonzero_view_t::value_type,
135 HandleExecSpace, TemporaryMemorySpace,PersistentMemorySpace > kk_handle_type;
136
138 typedef Tpetra::Map<local_ordinal_type,
142
144
154 explicit ILUT (const Teuchos::RCP<const row_matrix_type>& A);
155
157 virtual ~ILUT () = default;
158
160
162
194 void setParameters (const Teuchos::ParameterList& params);
195
207 void initialize ();
208
210 inline bool isInitialized() const {
211 return IsInitialized_;
212 }
213
215
222 void compute();
223
225 inline bool isComputed() const {
226 return IsComputed_;
227 }
228
230
232
255 virtual void
256 setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
257
259
261
266 void
267 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
268 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
269 Teuchos::ETransp mode = Teuchos::NO_TRANS,
270 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
271 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
272
274 Teuchos::RCP<const map_type> getDomainMap() const;
275
277 Teuchos::RCP<const map_type> getRangeMap() const;
278
280 bool hasTransposeApply() const;
281
283
285
287 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
288
290 Teuchos::RCP<const row_matrix_type> getMatrix () const;
291
293 Teuchos::RCP<const crs_matrix_type> getL () const { return L_; }
294
296 Teuchos::RCP<const crs_matrix_type> getU () const { return U_; }
297
299 int getNumInitialize() const;
300
302 int getNumCompute() const;
303
305 int getNumApply() const;
306
308 double getInitializeTime() const;
309
311 double getComputeTime() const;
312
314 double getApplyTime() const;
315
317 size_t getNodeSmootherComplexity() const;
318
319
327 inline double getLevelOfFill() const {
328 return LevelOfFill_;
329 }
330
333 return(Athresh_);
334 }
335
338 return(Rthresh_);
339 }
340
343 return(RelaxValue_);
344 }
345
348 return(DropTolerance_);
349 }
350
352 global_size_t getGlobalNumEntries() const;
353
355 size_t getLocalNumEntries() const;
356
358
360
362 std::string description() const;
363
365 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
366
368
369private:
370 typedef Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> MV;
371 typedef Teuchos::ScalarTraits<scalar_type> STS;
372 typedef Teuchos::ScalarTraits<magnitude_type> STM;
373 typedef typename Teuchos::Array<local_ordinal_type>::size_type size_type;
374
376 ILUT (const ILUT<MatrixType>& RHS);
377
378 void allocateSolvers ();
379
381 ILUT<MatrixType>& operator= (const ILUT<MatrixType>& RHS);
382
393 static Teuchos::RCP<const row_matrix_type>
394 makeLocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
395
396 // \name The matrix and its incomplete LU factors
398
400 Teuchos::RCP<const row_matrix_type> A_;
402 Teuchos::RCP<const row_matrix_type> A_local_;
403 lno_row_view_t A_local_rowmap_;
404 lno_nonzero_view_t A_local_entries_;
405 scalar_nonzero_view_t A_local_values_;
407 Teuchos::RCP<crs_matrix_type> L_;
408 lno_urow_view_t L_rowmap_;
409 lno_urow_view_t U_rowmap_;
410 lno_urow_view_t L_rowmap_orig_;
411 lno_urow_view_t U_rowmap_orig_;
413 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > L_solver_;
415 Teuchos::RCP<crs_matrix_type> U_;
417 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > U_solver_;
418
420 // \name Parameters (set by setParameters())
422
423 magnitude_type Athresh_;
424 magnitude_type Rthresh_;
425 magnitude_type RelaxValue_;
426 double LevelOfFill_;
428 magnitude_type DropTolerance_;
429 // See https://kokkos-kernels.readthedocs.io/en/latest/developer/apidocs/sparse.html#par-ilut
430 // for more information on the following options.
431 mutable struct par_ilut_option_struct {
432 int max_iter;
433 magnitude_type residual_norm_delta_stop;
434 int team_size;
435 int vector_size;
436 double fill_in_limit; //Note: par_ilut declares this as float
437 bool verbose;
438 } par_ilut_options_;
439
441 // \name Other internal data
443
445 double InitializeTime_;
447 double ComputeTime_;
449 mutable double ApplyTime_;
451 int NumInitialize_;
453 int NumCompute_;
455 mutable int NumApply_;
457 bool IsInitialized_;
459 bool IsComputed_;
461
463 bool useKokkosKernelsParILUT_;
464 Teuchos::RCP<kk_handle_type> KernelHandle_;
465
466}; // class ILUT
467
468} // namespace Ifpack2
469
470#endif /* IFPACK2_ILUT_HPP */
Declaration of interface for preconditioners that can change their matrix after construction.
Mix-in interface for preconditioners that can change their matrix after construction.
Definition Ifpack2_Details_CanChangeMatrix.hpp:60
ILUT (incomplete LU factorization with threshold) of a Tpetra sparse matrix.
Definition Ifpack2_ILUT_decl.hpp:69
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition Ifpack2_ILUT_decl.hpp:87
double getLevelOfFill() const
The level of fill.
Definition Ifpack2_ILUT_decl.hpp:327
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the input matrix's communicator.
Definition Ifpack2_ILUT_def.hpp:276
double getInitializeTime() const
Returns the time spent in Initialize().
Definition Ifpack2_ILUT_def.hpp:341
void compute()
Compute factors L and U using the specified diagonal perturbation thresholds and relaxation parameter...
Definition Ifpack2_ILUT_def.hpp:553
Teuchos::RCP< const row_matrix_type > getMatrix() const
Returns a reference to the matrix to be preconditioned.
Definition Ifpack2_ILUT_def.hpp:287
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition Ifpack2_ILUT_decl.hpp:210
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Type of the Tpetra::Map specialization that this class uses.
Definition Ifpack2_ILUT_decl.hpp:140
magnitude_type getDropTolerance() const
Gets the dropping tolerance.
Definition Ifpack2_ILUT_decl.hpp:347
global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition Ifpack2_ILUT_def.hpp:370
int getNumInitialize() const
Returns the number of calls to Initialize().
Definition Ifpack2_ILUT_def.hpp:323
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:78
Teuchos::RCP< const map_type > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition Ifpack2_ILUT_def.hpp:294
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 ILUT preconditioner to X, resulting in Y.
Definition Ifpack2_ILUT_def.hpp:1008
int getNumApply() const
Returns the number of calls to apply().
Definition Ifpack2_ILUT_def.hpp:335
bool isComputed() const
If compute() is completed, this query returns true, otherwise it returns false.
Definition Ifpack2_ILUT_decl.hpp:225
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_ILUT_def.hpp:359
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:75
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:81
std::string description() const
Return a simple one-line description of this object.
Definition Ifpack2_ILUT_def.hpp:1078
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:84
Teuchos::RCP< const crs_matrix_type > getL() const
Returns a reference to the L factor.
Definition Ifpack2_ILUT_decl.hpp:293
bool hasTransposeApply() const
Whether this object's apply() method can apply the transpose (or conjugate transpose,...
Definition Ifpack2_ILUT_def.hpp:317
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Definition Ifpack2_ILUT_def.hpp:1111
ILUT(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition Ifpack2_ILUT_def.hpp:100
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_ILUT_def.hpp:382
Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > crs_matrix_type
Type of the Tpetra::CrsMatrix specialization that this class uses for the L and U factors.
Definition Ifpack2_ILUT_decl.hpp:109
Teuchos::RCP< const map_type > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition Ifpack2_ILUT_def.hpp:306
size_t getLocalNumEntries() const
Returns the number of nonzero entries in the local graph.
Definition Ifpack2_ILUT_def.hpp:376
Teuchos::RCP< const crs_matrix_type > getU() const
Returns a reference to the U factor.
Definition Ifpack2_ILUT_decl.hpp:296
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Type of the Tpetra::RowMatrix specialization that this class uses.
Definition Ifpack2_ILUT_decl.hpp:93
void initialize()
Clear any previously computed factors, and potentially compute sparsity patterns of factors.
Definition Ifpack2_ILUT_def.hpp:455
virtual ~ILUT()=default
Destructor.
magnitude_type getRelaxValue() const
Get the relax value.
Definition Ifpack2_ILUT_decl.hpp:342
int getNumCompute() const
Returns the number of calls to Compute().
Definition Ifpack2_ILUT_def.hpp:329
double getApplyTime() const
Returns the time spent in apply().
Definition Ifpack2_ILUT_def.hpp:353
void setParameters(const Teuchos::ParameterList &params)
Set preconditioner parameters.
Definition Ifpack2_ILUT_def.hpp:132
magnitude_type getRelativeThreshold() const
Get relative threshold value.
Definition Ifpack2_ILUT_decl.hpp:337
magnitude_type getAbsoluteThreshold() const
Get absolute threshold value.
Definition Ifpack2_ILUT_decl.hpp:332
double getComputeTime() const
Returns the time spent in Compute().
Definition Ifpack2_ILUT_def.hpp:347
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:75
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41