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
18#include "Tpetra_CrsMatrix_decl.hpp"
19#include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
20
21#include <string>
22#include <sstream>
23#include <iostream>
24#include <cmath>
25#include <type_traits>
26
27namespace Teuchos {
28class ParameterList; // forward declaration
29}
30
31namespace Ifpack2 {
32
57template <class MatrixType>
58class ILUT : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
59 typename MatrixType::local_ordinal_type,
60 typename MatrixType::global_ordinal_type,
61 typename MatrixType::node_type>,
62 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
63 typename MatrixType::local_ordinal_type,
64 typename MatrixType::global_ordinal_type,
65 typename MatrixType::node_type> > {
66 public:
68
69
71 typedef typename MatrixType::scalar_type scalar_type;
72
74 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
75
77 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
78
80 typedef typename MatrixType::node_type node_type;
81
83 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
84
86 typedef Tpetra::RowMatrix<scalar_type,
91
92 typedef typename row_matrix_type::global_inds_host_view_type global_inds_host_view_type;
93 typedef typename row_matrix_type::local_inds_host_view_type local_inds_host_view_type;
94 typedef typename row_matrix_type::values_host_view_type values_host_view_type;
95
96 typedef typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
97 typedef typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
98 typedef typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
99
100 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.");
101
103 typedef Tpetra::CrsMatrix<scalar_type,
106 node_type>
108
110 typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
111 typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
113 typedef Tpetra::CrsGraph<local_ordinal_type, global_ordinal_type, node_type> crs_graph_type;
114 typedef typename crs_graph_type::local_graph_device_type local_graph_device_type;
115 typedef typename local_graph_device_type::array_layout array_layout;
116 typedef typename local_graph_device_type::device_type device_type;
117 typedef typename local_graph_device_type::size_type usize_type;
118 // KokkosKernels requires unsigned
119 // typedef typename Kokkos::View<size_type*, array_layout, device_type> lno_row_view_t;
120 typedef typename Kokkos::View<usize_type*, array_layout, device_type> lno_urow_view_t;
122 typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
123 // typedef typename Kokkos::View<lno_nonzero_view_t*, array_layout, device_type> static_graph_entries_t;
124 typedef typename Kokkos::View<typename local_matrix_device_type::non_const_ordinal_type*, array_layout, device_type> static_graph_entries_t;
125 typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
126 // typedef typename Kokkos::View<scalar_nonzero_view_t*, array_layout, device_type> local_matrix_values_t;
127 typedef typename Kokkos::View<typename local_matrix_device_type::non_const_value_type*, array_layout, device_type> local_matrix_values_t;
128 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space TemporaryMemorySpace;
129 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space PersistentMemorySpace;
130 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::execution_space HandleExecSpace;
131 typedef typename KokkosKernels::Experimental::KokkosKernelsHandle<typename lno_row_view_t::const_value_type, typename lno_nonzero_view_t::const_value_type, typename scalar_nonzero_view_t::value_type,
132 HandleExecSpace, TemporaryMemorySpace, PersistentMemorySpace>
133 kk_handle_type;
134
136 typedef Tpetra::Map<local_ordinal_type,
138 node_type>
141
143
153 explicit ILUT(const Teuchos::RCP<const row_matrix_type>& A);
154
156 virtual ~ILUT() = default;
157
159
161
193 void setParameters(const Teuchos::ParameterList& params);
194
206 void initialize();
207
209 inline bool isInitialized() const {
210 return IsInitialized_;
211 }
212
214
221 void compute();
222
224 inline bool isComputed() const {
225 return IsComputed_;
226 }
227
229
231
254 virtual void
255 setMatrix(const Teuchos::RCP<const row_matrix_type>& A);
256
258
260
265 void
266 apply(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
267 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
268 Teuchos::ETransp mode = Teuchos::NO_TRANS,
269 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
270 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
271
273 Teuchos::RCP<const map_type> getDomainMap() const;
274
276 Teuchos::RCP<const map_type> getRangeMap() const;
277
279 bool hasTransposeApply() const;
280
282
284
286 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
287
289 Teuchos::RCP<const row_matrix_type> getMatrix() const;
290
292 Teuchos::RCP<const crs_matrix_type> getL() const { return L_; }
293
295 Teuchos::RCP<const crs_matrix_type> getU() const { return U_; }
296
298 int getNumInitialize() const;
299
301 int getNumCompute() const;
302
304 int getNumApply() const;
305
307 double getInitializeTime() const;
308
310 double getComputeTime() const;
311
313 double getApplyTime() const;
314
316 size_t getNodeSmootherComplexity() const;
317
325 inline double getLevelOfFill() const {
326 return LevelOfFill_;
327 }
328
331 return (Athresh_);
332 }
333
336 return (Rthresh_);
337 }
338
341 return (RelaxValue_);
342 }
343
346 return (DropTolerance_);
347 }
348
350 global_size_t getGlobalNumEntries() const;
351
353 size_t getLocalNumEntries() const;
354
356
358
360 std::string description() const;
361
363 void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default) const;
364
366
367 private:
368 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
369 typedef Teuchos::ScalarTraits<scalar_type> STS;
370 typedef Teuchos::ScalarTraits<magnitude_type> STM;
371 typedef typename Teuchos::Array<local_ordinal_type>::size_type size_type;
372
374 ILUT(const ILUT<MatrixType>& RHS);
375
376 void allocateSolvers();
377
379 ILUT<MatrixType>& operator=(const ILUT<MatrixType>& RHS);
380
391 static Teuchos::RCP<const row_matrix_type>
392 makeLocalFilter(const Teuchos::RCP<const row_matrix_type>& A);
393
394 // \name The matrix and its incomplete LU factors
396
398 Teuchos::RCP<const row_matrix_type> A_;
400 Teuchos::RCP<const row_matrix_type> A_local_;
401 lno_row_view_t A_local_rowmap_;
402 lno_nonzero_view_t A_local_entries_;
403 scalar_nonzero_view_t A_local_values_;
405 Teuchos::RCP<crs_matrix_type> L_;
406 lno_urow_view_t L_rowmap_;
407 lno_urow_view_t U_rowmap_;
408 lno_urow_view_t L_rowmap_orig_;
409 lno_urow_view_t U_rowmap_orig_;
411 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > L_solver_;
413 Teuchos::RCP<crs_matrix_type> U_;
415 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > U_solver_;
416
418 // \name Parameters (set by setParameters())
420
421 magnitude_type Athresh_;
422 magnitude_type Rthresh_;
423 magnitude_type RelaxValue_;
424 double LevelOfFill_;
426 magnitude_type DropTolerance_;
427 // See https://kokkos-kernels.readthedocs.io/en/latest/developer/apidocs/sparse.html#par-ilut
428 // for more information on the following options.
429 mutable struct par_ilut_option_struct {
430 int max_iter;
431 magnitude_type residual_norm_delta_stop;
432 int team_size;
433 int vector_size;
434 double fill_in_limit; // Note: par_ilut declares this as float
435 bool verbose;
436 } par_ilut_options_;
437
439 // \name Other internal data
441
443 double InitializeTime_;
445 double ComputeTime_;
447 mutable double ApplyTime_;
449 int NumInitialize_;
451 int NumCompute_;
453 mutable int NumApply_;
455 bool IsInitialized_;
457 bool IsComputed_;
459
461 bool useKokkosKernelsParILUT_;
462 Teuchos::RCP<kk_handle_type> KernelHandle_;
463
464}; // class ILUT
465
466} // namespace Ifpack2
467
468#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:65
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition Ifpack2_ILUT_decl.hpp:83
double getLevelOfFill() const
The level of fill.
Definition Ifpack2_ILUT_decl.hpp:325
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the input matrix's communicator.
Definition Ifpack2_ILUT_def.hpp:264
double getInitializeTime() const
Returns the time spent in Initialize().
Definition Ifpack2_ILUT_def.hpp:322
void compute()
Compute factors L and U using the specified diagonal perturbation thresholds and relaxation parameter...
Definition Ifpack2_ILUT_def.hpp:525
Teuchos::RCP< const row_matrix_type > getMatrix() const
Returns a reference to the matrix to be preconditioned.
Definition Ifpack2_ILUT_def.hpp:275
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition Ifpack2_ILUT_decl.hpp:209
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:139
magnitude_type getDropTolerance() const
Gets the dropping tolerance.
Definition Ifpack2_ILUT_decl.hpp:345
global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition Ifpack2_ILUT_def.hpp:348
int getNumInitialize() const
Returns the number of calls to Initialize().
Definition Ifpack2_ILUT_def.hpp:307
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:74
Teuchos::RCP< const map_type > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition Ifpack2_ILUT_def.hpp:281
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:969
int getNumApply() const
Returns the number of calls to apply().
Definition Ifpack2_ILUT_def.hpp:317
bool isComputed() const
If compute() is completed, this query returns true, otherwise it returns false.
Definition Ifpack2_ILUT_decl.hpp:224
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_ILUT_def.hpp:337
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:71
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:77
std::string description() const
Return a simple one-line description of this object.
Definition Ifpack2_ILUT_def.hpp:1036
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:80
Teuchos::RCP< const crs_matrix_type > getL() const
Returns a reference to the L factor.
Definition Ifpack2_ILUT_decl.hpp:292
bool hasTransposeApply() const
Whether this object's apply() method can apply the transpose (or conjugate transpose,...
Definition Ifpack2_ILUT_def.hpp:302
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:1065
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_ILUT_def.hpp:358
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:107
Teuchos::RCP< const map_type > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition Ifpack2_ILUT_def.hpp:292
size_t getLocalNumEntries() const
Returns the number of nonzero entries in the local graph.
Definition Ifpack2_ILUT_def.hpp:353
Teuchos::RCP< const crs_matrix_type > getU() const
Returns a reference to the U factor.
Definition Ifpack2_ILUT_decl.hpp:295
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:90
void initialize()
Clear any previously computed factors, and potentially compute sparsity patterns of factors.
Definition Ifpack2_ILUT_def.hpp:429
virtual ~ILUT()=default
Destructor.
magnitude_type getRelaxValue() const
Get the relax value.
Definition Ifpack2_ILUT_decl.hpp:340
int getNumCompute() const
Returns the number of calls to Compute().
Definition Ifpack2_ILUT_def.hpp:312
double getApplyTime() const
Returns the time spent in apply().
Definition Ifpack2_ILUT_def.hpp:332
void setParameters(const Teuchos::ParameterList &params)
Set preconditioner parameters.
Definition Ifpack2_ILUT_def.hpp:128
magnitude_type getRelativeThreshold() const
Get relative threshold value.
Definition Ifpack2_ILUT_decl.hpp:335
magnitude_type getAbsoluteThreshold() const
Get absolute threshold value.
Definition Ifpack2_ILUT_decl.hpp:330
double getComputeTime() const
Returns the time spent in Compute().
Definition Ifpack2_ILUT_def.hpp:327
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:74
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40