Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_MDF_decl.hpp
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_MDF_DECL_HPP
47#define IFPACK2_MDF_DECL_HPP
48
51#include "Tpetra_CrsMatrix_decl.hpp"
53#include "Ifpack2_IlukGraph.hpp"
54#include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
55#include "KokkosSparse_mdf.hpp"
56
57#include <type_traits>
58
59namespace Teuchos {
60 class ParameterList; // forward declaration
61}
62namespace Ifpack2 {
63
82template<class MatrixType>
83class MDF:
84 virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
85 typename MatrixType::local_ordinal_type,
86 typename MatrixType::global_ordinal_type,
87 typename MatrixType::node_type>,
88 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
89 typename MatrixType::local_ordinal_type,
90 typename MatrixType::global_ordinal_type,
91 typename MatrixType::node_type> >
92{
93 public:
95 typedef typename MatrixType::scalar_type scalar_type;
96
98 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
99
101 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
102
104 typedef typename MatrixType::node_type node_type;
105
107 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
108
110 typedef typename node_type::device_type device_type;
111
113 typedef typename node_type::execution_space execution_space;
114
116 typedef Tpetra::RowMatrix<scalar_type,
120
121
122 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.");
123
125 typedef Tpetra::CrsMatrix<scalar_type,
129
131 typedef typename crs_matrix_type::impl_scalar_type impl_scalar_type;
132
133 template <class NewMatrixType> friend class MDF;
134
135 typedef typename crs_matrix_type::global_inds_host_view_type global_inds_host_view_type;
136 typedef typename crs_matrix_type::local_inds_host_view_type local_inds_host_view_type;
137 typedef typename crs_matrix_type::values_host_view_type values_host_view_type;
138
139
140 typedef typename crs_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
141 typedef typename crs_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
142 typedef typename crs_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
143
144
146
148
149 typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
150 typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
151 typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
152 typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
153 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space TemporaryMemorySpace;
154 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space PersistentMemorySpace;
155 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::execution_space HandleExecSpace;
156 typedef typename KokkosKernels::Experimental::KokkosKernelsHandle
157 <typename lno_row_view_t::const_value_type, typename lno_nonzero_view_t::const_value_type, typename scalar_nonzero_view_t::value_type,
158 HandleExecSpace, TemporaryMemorySpace,PersistentMemorySpace > kk_handle_type;
159
163 MDF (const Teuchos::RCP<const row_matrix_type>& A_in);
164
172 MDF (const Teuchos::RCP<const crs_matrix_type>& A_in);
173
174 private:
177 MDF (const MDF<MatrixType> & src);
178
179 public:
181 virtual ~MDF () = default;
182
189 void setParameters (const Teuchos::ParameterList& params);
190
192 void initialize ();
193
202 void compute ();
203
205 bool isInitialized () const {
206 return isInitialized_;
207 }
208
209 bool isComputed () const {
210 return isComputed_;
211 }
212
214 int getNumInitialize () const {
215 return numInitialize_;
216 }
217
218 int getNumCompute () const {
219 return numCompute_;
220 }
221
222 int getNumApply () const {
223 return numApply_;
224 }
225
227 double getInitializeTime () const {
228 return initializeTime_;
229 }
230
231 double getComputeTime () const {
232 return computeTime_;
233 }
234
235 double getApplyTime () const {
236 return applyTime_;
237 }
238
240 size_t getNodeSmootherComplexity() const;
241
243
244
267 virtual void
268 setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
269
271
273
275 std::string description () const;
276
278
280
282 Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
283 getDomainMap () const;
284
286 Teuchos::RCP<const Tpetra::Map<local_ordinal_type,global_ordinal_type,node_type> >
287 getRangeMap () const;
288
318 void
319 apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
320 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
321 Teuchos::ETransp mode = Teuchos::NO_TRANS,
322 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
323 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const;
325
326private:
327
328 // Split off to a different impl call so that nested apply calls don't mess up apply counts/timers
329 void apply_impl (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
330 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
331 Teuchos::ETransp mode = Teuchos::NO_TRANS,
332 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
333 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const;
334
356 void
357 multiply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
358 Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
359 const Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
360public:
361 using MDF_handle_device_type = KokkosSparse::Experimental::MDF_handle<local_matrix_device_type>;
362 using permutations_type = Teuchos::ArrayRCP<local_ordinal_type>;
363
365 Teuchos::RCP<const row_matrix_type> getMatrix () const;
366
368 int getLevelOfFill () const { return LevelOfFill_; }
369
371 Tpetra::CombineMode getOverlapMode () {
372 TEUCHOS_TEST_FOR_EXCEPTION(
373 true, std::logic_error, "Ifpack2::MDF::SetOverlapMode: "
374 "MDF no longer implements overlap on its own. "
375 "Use MDF with AdditiveSchwarz if you want overlap.");
376 }
377
379 Tpetra::global_size_t getGlobalNumEntries () const {
380 return getL ().getGlobalNumEntries () + getU ().getGlobalNumEntries ();
381 }
382
384 const crs_matrix_type& getL () const;
385
387 const crs_matrix_type& getU () const;
388
390 permutations_type & getPermutations() const;
391
393 permutations_type & getReversePermutations() const;
394
396 Teuchos::RCP<const crs_matrix_type> getCrsMatrix () const;
397
398private:
399 typedef Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> MV;
400 typedef Teuchos::ScalarTraits<scalar_type> STS;
401 typedef Teuchos::ScalarTraits<magnitude_type> STM;
402
403 void allocateSolvers ();
404 void allocatePermutations(bool force = false);
405 static void checkOrderingConsistency (const row_matrix_type& A);
406 // void initAllValues (const row_matrix_type& A);
407
413 static Teuchos::RCP<const row_matrix_type>
414 makeLocalFilter (const Teuchos::RCP<const row_matrix_type>& A);
415
416protected:
417 typedef Tpetra::Vector<scalar_type,local_ordinal_type,global_ordinal_type,node_type> vec_type;
418
420 Teuchos::RCP<const row_matrix_type> A_;
421
422 // The MDF handle
423 Teuchos::RCP<MDF_handle_device_type> MDF_handle_;
424
428 Teuchos::RCP<const row_matrix_type> A_local_;
429 lno_row_view_t A_local_rowmap_;
430 lno_nonzero_view_t A_local_entries_;
431 scalar_nonzero_view_t A_local_values_;
432
434 Teuchos::RCP<crs_matrix_type> L_;
436 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > L_solver_;
438 Teuchos::RCP<crs_matrix_type> U_;
440 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > U_solver_;
441
443 permutations_type permutations_;
444
446 permutations_type reversePermutations_;
447
448 int Verbosity_;
449
450 int LevelOfFill_;
451 double Overalloc_;
452
453 bool isAllocated_;
454 bool isInitialized_;
455 bool isComputed_;
456
457 int numInitialize_;
458 int numCompute_;
459 mutable int numApply_;
460
461 double initializeTime_;
462 double computeTime_;
463 mutable double applyTime_;
464};
465
466} // namespace Ifpack2
467
468#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:93
void setParameters(const Teuchos::ParameterList &params)
Definition Ifpack2_MDF_def.hpp:363
double getApplyTime() const
Total time in seconds taken by all successful apply() calls for this object.
Definition Ifpack2_MDF_decl.hpp:235
const crs_matrix_type & getL() const
Return the L factor of the MDF factorization.
Definition Ifpack2_MDF_def.hpp:259
node_type::execution_space execution_space
The Kokkos execution space of the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:113
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:716
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition Ifpack2_MDF_decl.hpp:107
int getLevelOfFill() const
Get level of fill (the "k" in ILU(k)).
Definition Ifpack2_MDF_decl.hpp:368
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > L_solver_
Sparse triangular solver for L.
Definition Ifpack2_MDF_decl.hpp:436
bool isComputed() const
Whether compute() has been called on this object.
Definition Ifpack2_MDF_decl.hpp:209
permutations_type & getReversePermutations() const
Return the reverse permutations of the MDF factorization.
Definition Ifpack2_MDF_def.hpp:284
permutations_type reversePermutations_
The reverse permuations from MDF factorization.
Definition Ifpack2_MDF_decl.hpp:446
Tpetra::CombineMode getOverlapMode()
Get overlap mode type.
Definition Ifpack2_MDF_decl.hpp:371
const crs_matrix_type & getU() const
Return the U factor of the MDF factorization.
Definition Ifpack2_MDF_def.hpp:297
void compute()
Compute the (numeric) incomplete factorization.
Definition Ifpack2_MDF_def.hpp:575
Teuchos::RCP< crs_matrix_type > U_
The U (upper triangular) factor of ILU(k).
Definition Ifpack2_MDF_decl.hpp:438
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:98
bool isInitialized() const
Whether initialize() has been called on this object.
Definition Ifpack2_MDF_decl.hpp:205
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:428
void initialize()
Initialize by computing the symbolic incomplete factorization.
Definition Ifpack2_MDF_def.hpp:466
int getNumCompute() const
Number of successful compute() calls for this object.
Definition Ifpack2_MDF_decl.hpp:218
std::string description() const
A one-line description of this object.
Definition Ifpack2_MDF_def.hpp:785
double getComputeTime() const
Total time in seconds taken by all successful compute() calls for this object.
Definition Ifpack2_MDF_decl.hpp:231
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:346
Tpetra::global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition Ifpack2_MDF_decl.hpp:379
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:128
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:327
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:119
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:426
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:104
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:101
double getInitializeTime() const
Total time in seconds taken by all successful initialize() calls for this object.
Definition Ifpack2_MDF_decl.hpp:227
permutations_type permutations_
The computed permuations from MDF factorization.
Definition Ifpack2_MDF_decl.hpp:443
int getNumInitialize() const
Number of successful initialize() calls for this object.
Definition Ifpack2_MDF_decl.hpp:214
crs_matrix_type::impl_scalar_type impl_scalar_type
Scalar type stored in Kokkos::Views (CrsMatrix and MultiVector).
Definition Ifpack2_MDF_decl.hpp:131
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > U_solver_
Sparse triangular solver for U.
Definition Ifpack2_MDF_decl.hpp:440
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:95
Teuchos::RCP< const row_matrix_type > getMatrix() const
Get the input matrix.
Definition Ifpack2_MDF_def.hpp:419
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_MDF_def.hpp:222
node_type::device_type device_type
The Kokkos device type of the input MatrixType.
Definition Ifpack2_MDF_decl.hpp:110
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_MDF_def.hpp:310
Teuchos::RCP< crs_matrix_type > L_
The L (lower triangular) factor of ILU(k).
Definition Ifpack2_MDF_decl.hpp:434
Teuchos::RCP< const row_matrix_type > A_
The (original) input matrix for which to compute ILU(k).
Definition Ifpack2_MDF_decl.hpp:420
permutations_type & getPermutations() const
Return the permutations of the MDF factorization.
Definition Ifpack2_MDF_def.hpp:272
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:222
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:108
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:74