Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_MDF_decl.hpp
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_MDF_DECL_HPP
14#define IFPACK2_MDF_DECL_HPP
15
18#include "Tpetra_CrsMatrix_decl.hpp"
20#include "Ifpack2_IlukGraph.hpp"
21#include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
22#include "KokkosSparse_mdf.hpp"
23
24#include <type_traits>
25
26namespace Teuchos {
27 class ParameterList; // forward declaration
28}
29namespace Ifpack2 {
30
49template<class MatrixType>
50class MDF:
51 virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
52 typename MatrixType::local_ordinal_type,
53 typename MatrixType::global_ordinal_type,
54 typename MatrixType::node_type>,
55 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
56 typename MatrixType::local_ordinal_type,
57 typename MatrixType::global_ordinal_type,
58 typename MatrixType::node_type> >
59{
60 public:
62 typedef typename MatrixType::scalar_type scalar_type;
63
65 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
66
68 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
69
71 typedef typename MatrixType::node_type node_type;
72
74 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
75
77 typedef typename node_type::device_type device_type;
78
80 typedef typename node_type::execution_space execution_space;
81
83 typedef Tpetra::RowMatrix<scalar_type,
87
88
89 static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::MDF: The template parameter MatrixType must be a Tpetra::RowMatrix specialization. Please don't use Tpetra::CrsMatrix (a subclass of Tpetra::RowMatrix) here anymore.");
90
92 typedef Tpetra::CrsMatrix<scalar_type,
96
98 typedef typename crs_matrix_type::impl_scalar_type impl_scalar_type;
99
100 template <class NewMatrixType> friend class MDF;
101
102 typedef typename crs_matrix_type::global_inds_host_view_type global_inds_host_view_type;
103 typedef typename crs_matrix_type::local_inds_host_view_type local_inds_host_view_type;
104 typedef typename crs_matrix_type::values_host_view_type values_host_view_type;
105
106
107 typedef typename crs_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
108 typedef typename crs_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
109 typedef typename crs_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
110
111
113
115
116 typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
117 typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
118 typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
119 typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
120 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space TemporaryMemorySpace;
121 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space PersistentMemorySpace;
122 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::execution_space HandleExecSpace;
123 typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
124 <typename lno_row_view_t::const_value_type, typename lno_nonzero_view_t::const_value_type, typename scalar_nonzero_view_t::value_type,
125 HandleExecSpace, TemporaryMemorySpace,PersistentMemorySpace > kk_handle_type;
126
130 MDF (const Teuchos::RCP<const row_matrix_type>& A_in);
131
139 MDF (const Teuchos::RCP<const crs_matrix_type>& A_in);
140
141 private:
144 MDF (const MDF<MatrixType> & src);
145
146 public:
148 virtual ~MDF () = default;
149
156 void setParameters (const Teuchos::ParameterList& params);
157
159 void initialize ();
160
169 void compute ();
170
172 bool isInitialized () const {
173 return isInitialized_;
174 }
175
176 bool isComputed () const {
177 return isComputed_;
178 }
179
181 int getNumInitialize () const {
182 return numInitialize_;
183 }
184
185 int getNumCompute () const {
186 return numCompute_;
187 }
188
189 int getNumApply () const {
190 return numApply_;
191 }
192
194 double getInitializeTime () const {
195 return initializeTime_;
196 }
197
198 double getComputeTime () const {
199 return computeTime_;
200 }
201
202 double getApplyTime () const {
203 return applyTime_;
204 }
205
207 size_t getNodeSmootherComplexity() const;
208
210
211
234 virtual void
235 setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
236
238
240
242 std::string description () const;
243
245
247
249 Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
250 getDomainMap () const;
251
253 Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
254 getRangeMap () const;
255
285 void
286 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
287 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
288 Teuchos::ETransp mode = Teuchos::NO_TRANS,
289 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
290 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const;
292
293private:
294
295 // Split off to a different impl call so that nested apply calls don't mess up apply counts/timers
296 void apply_impl (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
297 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
298 Teuchos::ETransp mode = Teuchos::NO_TRANS,
299 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
300 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const;
301
323 void
324 multiply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
325 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
326 const Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
327public:
328 using MDF_handle_device_type = KokkosSparse::Experimental::MDF_handle<local_matrix_device_type>;
329 using permutations_type = Teuchos::ArrayRCP<local_ordinal_type>;
330
332 Teuchos::RCP<const row_matrix_type> getMatrix () const;
333
335 int getLevelOfFill () const { return LevelOfFill_; }
336
338 Tpetra::CombineMode getOverlapMode () {
339 TEUCHOS_TEST_FOR_EXCEPTION(
340 true, std::logic_error, "Ifpack2::MDF::SetOverlapMode: "
341 "MDF no longer implements overlap on its own. "
342 "Use MDF with AdditiveSchwarz if you want overlap.");
343 }
344
346 Tpetra::global_size_t getGlobalNumEntries () const {
347 return getL ().getGlobalNumEntries () + getU ().getGlobalNumEntries ();
348 }
349
351 const crs_matrix_type& getL () const;
352
354 const crs_matrix_type& getU () const;
355
357 permutations_type & getPermutations() const;
358
360 permutations_type & getReversePermutations() const;
361
363 Teuchos::RCP<const crs_matrix_type> getCrsMatrix () const;
364
365private:
366 typedef Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> MV;
367 typedef Teuchos::ScalarTraits<scalar_type> STS;
368 typedef Teuchos::ScalarTraits<magnitude_type> STM;
369
370 void allocateSolvers ();
371 void allocatePermutations(bool force = false);
372 static void checkOrderingConsistency (const row_matrix_type& A);
373 // void initAllValues (const row_matrix_type& A);
374
380 static Teuchos::RCP<const row_matrix_type>
381 makeLocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
382
383protected:
384 typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vec_type;
385
387 Teuchos::RCP<const row_matrix_type> A_;
388
389 // The MDF handle
390 Teuchos::RCP<MDF_handle_device_type> MDF_handle_;
391
395 Teuchos::RCP<const row_matrix_type> A_local_;
396 lno_row_view_t A_local_rowmap_;
397 lno_nonzero_view_t A_local_entries_;
398 scalar_nonzero_view_t A_local_values_;
399
401 Teuchos::RCP<crs_matrix_type> L_;
403 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > L_solver_;
405 Teuchos::RCP<crs_matrix_type> U_;
407 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > U_solver_;
408
410 permutations_type permutations_;
411
413 permutations_type reversePermutations_;
414
415 int Verbosity_;
416
417 int LevelOfFill_;
418 double Overalloc_;
419
420 bool isAllocated_;
421 bool isInitialized_;
422 bool isComputed_;
423
424 int numInitialize_;
425 int numCompute_;
426 mutable int numApply_;
427
428 double initializeTime_;
429 double computeTime_;
430 mutable double applyTime_;
431};
432
433} // namespace Ifpack2
434
435#endif /* IFPACK2_MDF_DECL_HPP */
Declaration of interface for preconditioners that can change their matrix after construction.
Declaration and definition of IlukGraph.
Ifpack2::ScalingType enumerable type.
Mix-in interface for preconditioners that can change their matrix after construction.
Definition Ifpack2_Details_CanChangeMatrix.hpp:60
void setParameters(const Teuchos::ParameterList &params)
Definition Ifpack2_MDF_def.hpp:334
double getApplyTime() const
Total time in seconds taken by all successful apply() calls for this object.
Definition Ifpack2_MDF_decl.hpp:202
const crs_matrix_type & getL() const
Return the L factor of the MDF factorization.
Definition Ifpack2_MDF_def.hpp:230
node_type::execution_space execution_space
The Kokkos execution space of the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:80
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_MDF_def.hpp:665
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition Ifpack2_MDF_decl.hpp:74
int getLevelOfFill() const
Get level of fill (the "k" in ILU(k)).
Definition Ifpack2_MDF_decl.hpp:335
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > L_solver_
Sparse triangular solver for L.
Definition Ifpack2_MDF_decl.hpp:403
bool isComputed() const
Whether compute() has been called on this object.
Definition Ifpack2_MDF_decl.hpp:176
permutations_type & getReversePermutations() const
Return the reverse permutations of the MDF factorization.
Definition Ifpack2_MDF_def.hpp:255
permutations_type reversePermutations_
The reverse permuations from MDF factorization.
Definition Ifpack2_MDF_decl.hpp:413
Tpetra::CombineMode getOverlapMode()
Get overlap mode type.
Definition Ifpack2_MDF_decl.hpp:338
const crs_matrix_type & getU() const
Return the U factor of the MDF factorization.
Definition Ifpack2_MDF_def.hpp:268
void compute()
Compute the (numeric) incomplete factorization.
Definition Ifpack2_MDF_def.hpp:533
Teuchos::RCP< crs_matrix_type > U_
The U (upper triangular) factor of ILU(k).
Definition Ifpack2_MDF_decl.hpp:405
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:65
bool isInitialized() const
Whether initialize() has been called on this object.
Definition Ifpack2_MDF_decl.hpp:172
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_MDF_decl.hpp:395
void initialize()
Initialize by computing the symbolic incomplete factorization.
Definition Ifpack2_MDF_def.hpp:437
int getNumCompute() const
Number of successful compute() calls for this object.
Definition Ifpack2_MDF_decl.hpp:185
std::string description() const
A one-line description of this object.
Definition Ifpack2_MDF_def.hpp:734
double getComputeTime() const
Total time in seconds taken by all successful compute() calls for this object.
Definition Ifpack2_MDF_decl.hpp:198
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_MDF_def.hpp:317
Tpetra::global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition Ifpack2_MDF_decl.hpp:346
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_MDF_decl.hpp:95
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_MDF_def.hpp:298
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization used by this class.
Definition Ifpack2_MDF_decl.hpp:86
Teuchos::RCP< const crs_matrix_type > getCrsMatrix() const
Return the input matrix A as a Tpetra::CrsMatrix, if possible; else throws.
Definition Ifpack2_MDF_def.hpp:397
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:71
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:68
double getInitializeTime() const
Total time in seconds taken by all successful initialize() calls for this object.
Definition Ifpack2_MDF_decl.hpp:194
permutations_type permutations_
The computed permuations from MDF factorization.
Definition Ifpack2_MDF_decl.hpp:410
int getNumInitialize() const
Number of successful initialize() calls for this object.
Definition Ifpack2_MDF_decl.hpp:181
crs_matrix_type::impl_scalar_type impl_scalar_type
Scalar type stored in Kokkos::Views (CrsMatrix and MultiVector).
Definition Ifpack2_MDF_decl.hpp:98
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > U_solver_
Sparse triangular solver for U.
Definition Ifpack2_MDF_decl.hpp:407
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:62
Teuchos::RCP< const row_matrix_type > getMatrix() const
Get the input matrix.
Definition Ifpack2_MDF_def.hpp:390
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_MDF_def.hpp:193
node_type::device_type device_type
The Kokkos device type of the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:77
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_MDF_def.hpp:281
Teuchos::RCP< crs_matrix_type > L_
The L (lower triangular) factor of ILU(k).
Definition Ifpack2_MDF_decl.hpp:401
Teuchos::RCP< const row_matrix_type > A_
The (original) input matrix for which to compute ILU(k).
Definition Ifpack2_MDF_decl.hpp:387
permutations_type & getPermutations() const
Return the permutations of the MDF factorization.
Definition Ifpack2_MDF_def.hpp:243
virtual ~MDF()=default
Destructor (declared virtual for memory safety).
int getNumApply() const
Number of successful apply() calls for this object.
Definition Ifpack2_MDF_decl.hpp:189
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:75
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41