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//
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_ILUT_DECL_HPP
47#define IFPACK2_ILUT_DECL_HPP
48
49#include "KokkosSparse_par_ilut.hpp"
50
53#include "Tpetra_CrsMatrix_decl.hpp"
54#include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
55
56#include <string>
57#include <sstream>
58#include <iostream>
59#include <cmath>
60#include <type_traits>
61
62namespace Teuchos {
63 class ParameterList; // forward declaration
64}
65
66namespace Ifpack2 {
67
92template<class MatrixType>
93class ILUT :
94 virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
95 typename MatrixType::local_ordinal_type,
96 typename MatrixType::global_ordinal_type,
97 typename MatrixType::node_type>,
98 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
99 typename MatrixType::local_ordinal_type,
100 typename MatrixType::global_ordinal_type,
101 typename MatrixType::node_type> >
102{
103public:
105
106
108 typedef typename MatrixType::scalar_type scalar_type;
109
111 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
112
114 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
115
117 typedef typename MatrixType::node_type node_type;
118
120 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
121
123 typedef Tpetra::RowMatrix<scalar_type,
127
128 typedef typename row_matrix_type::global_inds_host_view_type global_inds_host_view_type;
129 typedef typename row_matrix_type::local_inds_host_view_type local_inds_host_view_type;
130 typedef typename row_matrix_type::values_host_view_type values_host_view_type;
131
132 typedef typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
133 typedef typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
134 typedef typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
135
136 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.");
137
139 typedef Tpetra::CrsMatrix<scalar_type,
143
145 typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
146 typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
148 typedef Tpetra::CrsGraph<local_ordinal_type, global_ordinal_type, node_type> crs_graph_type;
149 typedef typename crs_graph_type::local_graph_device_type local_graph_device_type;
150 typedef typename local_graph_device_type::array_layout array_layout;
151 typedef typename local_graph_device_type::device_type device_type;
152 typedef typename local_graph_device_type::size_type usize_type;
153 //KokkosKernels requires unsigned
154 //typedef typename Kokkos::View<size_type*, array_layout, device_type> lno_row_view_t;
155 typedef typename Kokkos::View<usize_type*, array_layout, device_type> lno_urow_view_t;
157 typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
158 //typedef typename Kokkos::View<lno_nonzero_view_t*, array_layout, device_type> static_graph_entries_t;
159 typedef typename Kokkos::View<typename local_matrix_device_type::non_const_ordinal_type*, array_layout, device_type> static_graph_entries_t;
160 typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
161 //typedef typename Kokkos::View<scalar_nonzero_view_t*, array_layout, device_type> local_matrix_values_t;
162 typedef typename Kokkos::View<typename local_matrix_device_type::non_const_value_type*, array_layout, device_type> local_matrix_values_t;
163 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space TemporaryMemorySpace;
164 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space PersistentMemorySpace;
165 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::execution_space HandleExecSpace;
166 typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
167 <typename lno_row_view_t::const_value_type, typename lno_nonzero_view_t::const_value_type, typename scalar_nonzero_view_t::value_type,
168 HandleExecSpace, TemporaryMemorySpace,PersistentMemorySpace > kk_handle_type;
169
171 typedef Tpetra::Map<local_ordinal_type,
175
177
187 explicit ILUT (const Teuchos::RCP<const row_matrix_type>& A);
188
190 virtual ~ILUT () = default;
191
193
195
227 void setParameters (const Teuchos::ParameterList& params);
228
240 void initialize ();
241
243 inline bool isInitialized() const {
244 return IsInitialized_;
245 }
246
248
255 void compute();
256
258 inline bool isComputed() const {
259 return IsComputed_;
260 }
261
263
265
288 virtual void
289 setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
290
292
294
299 void
300 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
301 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
302 Teuchos::ETransp mode = Teuchos::NO_TRANS,
303 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
304 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
305
307 Teuchos::RCP<const map_type> getDomainMap() const;
308
310 Teuchos::RCP<const map_type> getRangeMap() const;
311
313 bool hasTransposeApply() const;
314
316
318
320 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
321
323 Teuchos::RCP<const row_matrix_type> getMatrix () const;
324
326 Teuchos::RCP<const crs_matrix_type> getL () const { return L_; }
327
329 Teuchos::RCP<const crs_matrix_type> getU () const { return U_; }
330
332 int getNumInitialize() const;
333
335 int getNumCompute() const;
336
338 int getNumApply() const;
339
341 double getInitializeTime() const;
342
344 double getComputeTime() const;
345
347 double getApplyTime() const;
348
350 size_t getNodeSmootherComplexity() const;
351
352
360 inline double getLevelOfFill() const {
361 return LevelOfFill_;
362 }
363
366 return(Athresh_);
367 }
368
371 return(Rthresh_);
372 }
373
376 return(RelaxValue_);
377 }
378
381 return(DropTolerance_);
382 }
383
385 global_size_t getGlobalNumEntries() const;
386
388 size_t getLocalNumEntries() const;
389
391
393
395 std::string description() const;
396
398 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
399
401
402private:
403 typedef Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> MV;
404 typedef Teuchos::ScalarTraits<scalar_type> STS;
405 typedef Teuchos::ScalarTraits<magnitude_type> STM;
406 typedef typename Teuchos::Array<local_ordinal_type>::size_type size_type;
407
409 ILUT (const ILUT<MatrixType>& RHS);
410
411 void allocateSolvers ();
412
414 ILUT<MatrixType>& operator= (const ILUT<MatrixType>& RHS);
415
426 static Teuchos::RCP<const row_matrix_type>
427 makeLocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
428
429 // \name The matrix and its incomplete LU factors
431
433 Teuchos::RCP<const row_matrix_type> A_;
435 Teuchos::RCP<const row_matrix_type> A_local_;
436 lno_row_view_t A_local_rowmap_;
437 lno_nonzero_view_t A_local_entries_;
438 scalar_nonzero_view_t A_local_values_;
440 Teuchos::RCP<crs_matrix_type> L_;
441 lno_urow_view_t L_rowmap_;
442 lno_urow_view_t U_rowmap_;
444 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > L_solver_;
446 Teuchos::RCP<crs_matrix_type> U_;
448 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > U_solver_;
449
451 // \name Parameters (set by setParameters())
453
454 magnitude_type Athresh_;
455 magnitude_type Rthresh_;
456 magnitude_type RelaxValue_;
457 double LevelOfFill_;
459 magnitude_type DropTolerance_;
460 // See https://kokkos-kernels.readthedocs.io/en/latest/developer/apidocs/sparse.html#par-ilut
461 // for more information on the following options.
462 mutable struct par_ilut_option_struct {
463 int max_iter;
464 magnitude_type residual_norm_delta_stop;
465 int team_size;
466 int vector_size;
467 double fill_in_limit; //Note: par_ilut declares this as float
468 bool verbose;
469 } par_ilut_options_;
470
472 // \name Other internal data
474
476 double InitializeTime_;
478 double ComputeTime_;
480 mutable double ApplyTime_;
482 int NumInitialize_;
484 int NumCompute_;
486 mutable int NumApply_;
488 bool IsInitialized_;
490 bool IsComputed_;
492
494 bool useKokkosKernelsParILUT_;
495 Teuchos::RCP<kk_handle_type> KernelHandle_;
496
497}; // class ILUT
498
499} // namespace Ifpack2
500
501#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:93
ILUT (incomplete LU factorization with threshold) of a Tpetra sparse matrix.
Definition Ifpack2_ILUT_decl.hpp:102
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition Ifpack2_ILUT_decl.hpp:120
double getLevelOfFill() const
The level of fill.
Definition Ifpack2_ILUT_decl.hpp:360
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Returns the input matrix's communicator.
Definition Ifpack2_ILUT_def.hpp:309
double getInitializeTime() const
Returns the time spent in Initialize().
Definition Ifpack2_ILUT_def.hpp:374
void compute()
Compute factors L and U using the specified diagonal perturbation thresholds and relaxation parameter...
Definition Ifpack2_ILUT_def.hpp:581
Teuchos::RCP< const row_matrix_type > getMatrix() const
Returns a reference to the matrix to be preconditioned.
Definition Ifpack2_ILUT_def.hpp:320
bool isInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition Ifpack2_ILUT_decl.hpp:243
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:173
magnitude_type getDropTolerance() const
Gets the dropping tolerance.
Definition Ifpack2_ILUT_decl.hpp:380
global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition Ifpack2_ILUT_def.hpp:403
int getNumInitialize() const
Returns the number of calls to Initialize().
Definition Ifpack2_ILUT_def.hpp:356
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:111
Teuchos::RCP< const map_type > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition Ifpack2_ILUT_def.hpp:327
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:1028
int getNumApply() const
Returns the number of calls to apply().
Definition Ifpack2_ILUT_def.hpp:368
bool isComputed() const
If compute() is completed, this query returns true, otherwise it returns false.
Definition Ifpack2_ILUT_decl.hpp:258
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_ILUT_def.hpp:392
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:108
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:114
std::string description() const
Return a simple one-line description of this object.
Definition Ifpack2_ILUT_def.hpp:1098
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_ILUT_decl.hpp:117
Teuchos::RCP< const crs_matrix_type > getL() const
Returns a reference to the L factor.
Definition Ifpack2_ILUT_decl.hpp:326
bool hasTransposeApply() const
Whether this object's apply() method can apply the transpose (or conjugate transpose,...
Definition Ifpack2_ILUT_def.hpp:350
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:1131
ILUT(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition Ifpack2_ILUT_def.hpp:133
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_ILUT_def.hpp:415
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:142
Teuchos::RCP< const map_type > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition Ifpack2_ILUT_def.hpp:339
size_t getLocalNumEntries() const
Returns the number of nonzero entries in the local graph.
Definition Ifpack2_ILUT_def.hpp:409
Teuchos::RCP< const crs_matrix_type > getU() const
Returns a reference to the U factor.
Definition Ifpack2_ILUT_decl.hpp:329
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:126
void initialize()
Clear any previously computed factors, and potentially compute sparsity patterns of factors.
Definition Ifpack2_ILUT_def.hpp:488
virtual ~ILUT()=default
Destructor.
magnitude_type getRelaxValue() const
Get the relax value.
Definition Ifpack2_ILUT_decl.hpp:375
int getNumCompute() const
Returns the number of calls to Compute().
Definition Ifpack2_ILUT_def.hpp:362
double getApplyTime() const
Returns the time spent in apply().
Definition Ifpack2_ILUT_def.hpp:386
void setParameters(const Teuchos::ParameterList &params)
Set preconditioner parameters.
Definition Ifpack2_ILUT_def.hpp:165
magnitude_type getRelativeThreshold() const
Get relative threshold value.
Definition Ifpack2_ILUT_decl.hpp:370
magnitude_type getAbsoluteThreshold() const
Get absolute threshold value.
Definition Ifpack2_ILUT_decl.hpp:365
double getComputeTime() const
Returns the time spent in Compute().
Definition Ifpack2_ILUT_def.hpp:380
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:108
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:74