Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_RILUK_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_CRSRILUK_DECL_HPP
14#define IFPACK2_CRSRILUK_DECL_HPP
15
18#include "Tpetra_CrsMatrix_decl.hpp"
20#include "Ifpack2_IlukGraph.hpp"
21#include "Ifpack2_LocalSparseTriangularSolver_decl.hpp"
22
23#include <memory>
24#include <type_traits>
25
26namespace Teuchos {
27class ParameterList; // forward declaration
28}
29
30namespace Ifpack2 {
31
210template <class MatrixType>
211class RILUK : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
212 typename MatrixType::local_ordinal_type,
213 typename MatrixType::global_ordinal_type,
214 typename MatrixType::node_type>,
215 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
216 typename MatrixType::local_ordinal_type,
217 typename MatrixType::global_ordinal_type,
218 typename MatrixType::node_type> > {
219 public:
221 typedef typename MatrixType::scalar_type scalar_type;
222
224 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
225
227 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
228
230 typedef typename MatrixType::node_type node_type;
231
233 typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
234
236 typedef typename node_type::device_type device_type;
237
239 typedef typename node_type::execution_space execution_space;
240
242 typedef Tpetra::RowMatrix<scalar_type,
245 node_type>
247
248 static_assert(std::is_same<MatrixType, row_matrix_type>::value, "Ifpack2::RILUK: The template parameter MatrixType must be a Tpetra::RowMatrix specialization. Please don't use Tpetra::CrsMatrix (a subclass of Tpetra::RowMatrix) here anymore.");
249
251 typedef Tpetra::CrsMatrix<scalar_type,
254 node_type>
256
258 typedef typename crs_matrix_type::impl_scalar_type impl_scalar_type;
259
260 template <class NewMatrixType>
261 friend class RILUK;
262
263 typedef typename crs_matrix_type::global_inds_host_view_type global_inds_host_view_type;
264 typedef typename crs_matrix_type::local_inds_host_view_type local_inds_host_view_type;
265 typedef typename crs_matrix_type::values_host_view_type values_host_view_type;
266
267 typedef typename crs_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type;
268 typedef typename crs_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type;
269 typedef typename crs_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type;
270
272 typedef Tpetra::MultiVector<magnitude_type, local_ordinal_type,
275
277
279
280 typedef typename crs_matrix_type::local_matrix_device_type local_matrix_device_type;
281 typedef typename local_matrix_device_type::StaticCrsGraphType::row_map_type lno_row_view_t;
282 typedef typename local_matrix_device_type::StaticCrsGraphType::entries_type lno_nonzero_view_t;
283 typedef typename local_matrix_device_type::values_type scalar_nonzero_view_t;
284 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space TemporaryMemorySpace;
285 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::memory_space PersistentMemorySpace;
286 typedef typename local_matrix_device_type::StaticCrsGraphType::device_type::execution_space HandleExecSpace;
287 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,
288 HandleExecSpace, TemporaryMemorySpace, PersistentMemorySpace>
289 kk_handle_type;
291 typedef Kokkos::View<magnitude_type**, Kokkos::LayoutLeft, device_type> coors_view_t;
292 typedef Kokkos::View<local_ordinal_type*, Kokkos::LayoutLeft, device_type> perm_view_t;
293
297 RILUK(const Teuchos::RCP<const row_matrix_type>& A_in, const Teuchos::RCP<const coord_type>& A_in_coordinates = Teuchos::null);
298
306 RILUK(const Teuchos::RCP<const crs_matrix_type>& A_in, const Teuchos::RCP<const coord_type>& A_in_coordinates = Teuchos::null);
307
308 private:
311 RILUK(const RILUK<MatrixType>& src);
312
313 public:
315 virtual ~RILUK();
316
325 void setParameters(const Teuchos::ParameterList& params);
326
328 void initialize();
329
338 void compute();
339
341 bool isInitialized() const {
342 return isInitialized_;
343 }
345 bool isComputed() const {
346 return isComputed_;
347 }
348
350 int getNumInitialize() const {
351 return numInitialize_;
352 }
354 int getNumCompute() const {
355 return numCompute_;
356 }
358 int getNumApply() const {
359 return numApply_;
360 }
361
363 double getInitializeTime() const {
364 return initializeTime_;
365 }
367 double getComputeTime() const {
368 return computeTime_;
369 }
371 double getApplyTime() const {
372 return applyTime_;
373 }
374
376 size_t getNodeSmootherComplexity() const;
377
379
380
403 virtual void
404 setMatrix(const Teuchos::RCP<const row_matrix_type>& A);
405
409 void
410 setCoord(const Teuchos::RCP<const coord_type>& A_coordinates);
411
413
415
417 std::string description() const;
418
420
422
424 Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
425 getDomainMap() const;
426
428 Teuchos::RCP<const Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> >
429 getRangeMap() const;
430
460 void
461 apply(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
462 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
463 Teuchos::ETransp mode = Teuchos::NO_TRANS,
464 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
465 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
467
468 private:
490 void
491 multiply(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
492 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
493 const Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
494
495 public:
497 Teuchos::RCP<const row_matrix_type> getMatrix() const;
498
500 Teuchos::RCP<const coord_type> getCoord() const;
501
502 // Attribute access functions
503
505 magnitude_type getRelaxValue() const { return RelaxValue_; }
506
508 magnitude_type getAbsoluteThreshold() const { return Athresh_; }
509
511 magnitude_type getRelativeThreshold() const { return Rthresh_; }
512
514 int getLevelOfFill() const { return LevelOfFill_; }
515
517 Tpetra::CombineMode getOverlapMode() {
518 TEUCHOS_TEST_FOR_EXCEPTION(
519 true, std::logic_error,
520 "Ifpack2::RILUK::SetOverlapMode: "
521 "RILUK no longer implements overlap on its own. "
522 "Use RILUK with AdditiveSchwarz if you want overlap.");
523 }
524
526 Tpetra::global_size_t getGlobalNumEntries() const {
527 return getL().getGlobalNumEntries() + getU().getGlobalNumEntries();
528 }
529
531 Teuchos::RCP<Ifpack2::IlukGraph<Tpetra::CrsGraph<local_ordinal_type,
533 node_type>,
534 kk_handle_type> >
535 getGraph() const {
536 return Graph_;
537 }
538
540 const crs_matrix_type& getL() const;
541
543 const Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>&
544 getD() const;
545
547 const crs_matrix_type& getU() const;
548
550 Teuchos::RCP<const crs_matrix_type> getCrsMatrix() const;
551
557 static Teuchos::RCP<const row_matrix_type>
558 makeLocalFilter(const Teuchos::RCP<const row_matrix_type>& A);
559
560 private:
561 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
562 typedef Teuchos::ScalarTraits<scalar_type> STS;
563 typedef Teuchos::ScalarTraits<magnitude_type> STM;
564
565 void allocateSolvers();
566 void allocate_L_and_U();
567 static void checkOrderingConsistency(const row_matrix_type& A);
568 void initAllValues(const row_matrix_type& A);
569
570 void compute_serial();
571 void compute_kkspiluk();
572// Workaround Cuda limitation of KOKKOS_LAMBDA in private/protected member functions
573#ifdef KOKKOS_ENABLE_CUDA
574 public:
575#endif
576 void compute_kkspiluk_stream();
577#ifdef KOKKOS_ENABLE_CUDA
578 private:
579#endif
580
581 protected:
582 typedef Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> vec_type;
583
585 Teuchos::RCP<const row_matrix_type> A_;
586
589 Teuchos::RCP<const coord_type> A_coordinates_;
590
592 Teuchos::RCP<iluk_graph_type> Graph_;
593 std::vector<Teuchos::RCP<iluk_graph_type> > Graph_v_;
597 Teuchos::RCP<const row_matrix_type> A_local_;
598 Teuchos::RCP<const crs_matrix_type> A_local_crs_;
599 Teuchos::RCP<crs_matrix_type> A_local_crs_nc_;
600 std::vector<local_matrix_device_type> A_local_diagblks_v_;
601 std::vector<lno_row_view_t> A_local_diagblks_rowmap_v_;
602 std::vector<lno_nonzero_view_t> A_local_diagblks_entries_v_;
603 std::vector<scalar_nonzero_view_t> A_local_diagblks_values_v_;
604
606 Teuchos::RCP<crs_matrix_type> L_;
607 std::vector<Teuchos::RCP<crs_matrix_type> > L_v_;
609 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > L_solver_;
611 Teuchos::RCP<crs_matrix_type> U_;
612 std::vector<Teuchos::RCP<crs_matrix_type> > U_v_;
614 Teuchos::RCP<LocalSparseTriangularSolver<row_matrix_type> > U_solver_;
615
617 Teuchos::RCP<vec_type> D_;
618
619 int LevelOfFill_;
620 double Overalloc_;
621
622 bool isAllocated_;
623 bool isInitialized_;
624 bool isComputed_;
625
626 int numInitialize_;
627 int numCompute_;
628 mutable int numApply_;
629
630 double initializeTime_;
631 double computeTime_;
632 mutable double applyTime_;
633
634 magnitude_type RelaxValue_;
635 magnitude_type Athresh_;
636 magnitude_type Rthresh_;
637
640 Teuchos::RCP<kk_handle_type> KernelHandle_;
641 std::vector<Teuchos::RCP<kk_handle_type> > KernelHandle_v_;
642 bool isKokkosKernelsStream_;
643 int num_streams_;
644 std::vector<execution_space> exec_space_instances_;
645 bool hasStreamReordered_;
646 bool hasStreamsWithRCB_;
647 std::vector<typename lno_nonzero_view_t::non_const_type> perm_v_;
648 std::vector<typename lno_nonzero_view_t::non_const_type> reverse_perm_v_;
649 mutable std::unique_ptr<MV> Y_tmp_;
650 mutable std::unique_ptr<MV> reordered_x_;
651 mutable std::unique_ptr<MV> reordered_y_;
652 perm_view_t perm_rcb_;
653 coors_view_t coors_rcb_;
654};
655
656// NOTE (mfh 11 Feb 2015) This used to exist in order to deal with
657// different behavior of Tpetra::Crs{Graph,Matrix} for
658// KokkosClassic::ThrustGPUNode. In particular, fillComplete on a
659// CrsMatrix used to make the graph go away by default, so we had to
660// pass in a parameter to keep a host copy of the graph. With the new
661// (Kokkos refactor) version of Tpetra, this problem has gone away.
662namespace detail {
663template <class MatrixType, class NodeType>
664struct setLocalSolveParams {
665 static Teuchos::RCP<Teuchos::ParameterList>
666 setParams(const Teuchos::RCP<Teuchos::ParameterList>& param) {
667 return param;
668 }
669};
670} // namespace detail
671
672} // namespace Ifpack2
673
674#endif /* IFPACK2_CRSRILUK_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
Construct a level filled graph for use in computing an ILU(k) incomplete factorization.
Definition Ifpack2_IlukGraph.hpp:67
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:74
ILU(k) factorization of a given Tpetra::RowMatrix.
Definition Ifpack2_RILUK_decl.hpp:218
crs_matrix_type::impl_scalar_type impl_scalar_type
Scalar type stored in Kokkos::Views (CrsMatrix and MultiVector)
Definition Ifpack2_RILUK_decl.hpp:258
Tpetra::MultiVector< magnitude_type, local_ordinal_type, global_ordinal_type, node_type > coord_type
Tpetra::MultiVector specialization used for containing coordinates.
Definition Ifpack2_RILUK_decl.hpp:274
void initialize()
Initialize by computing the symbolic incomplete factorization.
Definition Ifpack2_RILUK_def.hpp:468
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_RILUK_decl.hpp:255
virtual ~RILUK()
Destructor (declared virtual for memory safety).
Definition Ifpack2_RILUK_def.hpp:99
double getApplyTime() const
Total time in seconds taken by all successful apply() calls for this object.
Definition Ifpack2_RILUK_decl.hpp:371
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_RILUK_def.hpp:1172
Teuchos::ScalarTraits< scalar_type >::magnitudeType magnitude_type
The type of the magnitude (absolute value) of a matrix entry.
Definition Ifpack2_RILUK_decl.hpp:233
double getComputeTime() const
Total time in seconds taken by all successful compute() calls for this object.
Definition Ifpack2_RILUK_decl.hpp:367
int getNumApply() const
Number of successful apply() calls for this object.
Definition Ifpack2_RILUK_decl.hpp:358
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_RILUK_def.hpp:240
magnitude_type getRelaxValue() const
Get RILU(k) relaxation parameter.
Definition Ifpack2_RILUK_decl.hpp:505
int getNumCompute() const
Number of successful compute() calls for this object.
Definition Ifpack2_RILUK_decl.hpp:354
Teuchos::RCP< const coord_type > A_coordinates_
Definition Ifpack2_RILUK_decl.hpp:589
Teuchos::RCP< const row_matrix_type > A_
The (original) input matrix for which to compute ILU(k).
Definition Ifpack2_RILUK_decl.hpp:585
Tpetra::CombineMode getOverlapMode()
Get overlap mode type.
Definition Ifpack2_RILUK_decl.hpp:517
Teuchos::RCP< crs_matrix_type > U_
The U (upper triangular) factor of ILU(k).
Definition Ifpack2_RILUK_decl.hpp:611
const crs_matrix_type & getU() const
Return the U factor of the ILU factorization.
Definition Ifpack2_RILUK_def.hpp:191
std::string description() const
A one-line description of this object.
Definition Ifpack2_RILUK_def.hpp:1439
Tpetra::global_size_t getGlobalNumEntries() const
Returns the number of nonzero entries in the global graph.
Definition Ifpack2_RILUK_decl.hpp:526
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_RILUK_def.hpp:122
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_RILUK_decl.hpp:221
bool isComputed() const
Whether compute() has been called on this object.
Definition Ifpack2_RILUK_decl.hpp:345
Teuchos::RCP< const coord_type > getCoord() const
Get the coordinates associated with the input matrix's rows.
Definition Ifpack2_RILUK_def.hpp:432
const Tpetra::Vector< scalar_type, local_ordinal_type, global_ordinal_type, node_type > & getD() const
Return the diagonal entries of the ILU factorization.
Definition Ifpack2_RILUK_def.hpp:178
MatrixType::node_type node_type
The Node type used by the input MatrixType.
Definition Ifpack2_RILUK_decl.hpp:230
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_RILUK_decl.hpp:597
void setCoord(const Teuchos::RCP< const coord_type > &A_coordinates)
Set the matrix rows' coordinates.
Definition Ifpack2_RILUK_def.hpp:154
Teuchos::RCP< const row_matrix_type > getMatrix() const
Get the input matrix.
Definition Ifpack2_RILUK_def.hpp:420
magnitude_type getAbsoluteThreshold() const
Get absolute threshold value.
Definition Ifpack2_RILUK_decl.hpp:508
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > L_solver_
Sparse triangular solver for L.
Definition Ifpack2_RILUK_decl.hpp:609
int getLevelOfFill() const
Get level of fill (the "k" in ILU(k)).
Definition Ifpack2_RILUK_decl.hpp:514
Teuchos::RCP< const crs_matrix_type > getCrsMatrix() const
Return the input matrix A as a Tpetra::CrsMatrix, if possible; else throws.
Definition Ifpack2_RILUK_def.hpp:426
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_RILUK_def.hpp:220
void setParameters(const Teuchos::ParameterList &params)
Definition Ifpack2_RILUK_def.hpp:299
magnitude_type getRelativeThreshold() const
Get relative threshold value.
Definition Ifpack2_RILUK_decl.hpp:511
int getNumInitialize() const
Number of successful initialize() calls for this object.
Definition Ifpack2_RILUK_decl.hpp:350
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_RILUK_decl.hpp:224
Teuchos::RCP< crs_matrix_type > L_
The L (lower triangular) factor of ILU(k).
Definition Ifpack2_RILUK_decl.hpp:606
MatrixType::global_ordinal_type global_ordinal_type
The type of global indices in the input MatrixType.
Definition Ifpack2_RILUK_decl.hpp:227
const crs_matrix_type & getL() const
Return the L factor of the ILU factorization.
Definition Ifpack2_RILUK_def.hpp:162
node_type::device_type device_type
The Kokkos device type of the input MatrixType.
Definition Ifpack2_RILUK_decl.hpp:236
node_type::execution_space execution_space
The Kokkos execution space of the input MatrixType.
Definition Ifpack2_RILUK_decl.hpp:239
Teuchos::RCP< LocalSparseTriangularSolver< row_matrix_type > > U_solver_
Sparse triangular solver for U.
Definition Ifpack2_RILUK_decl.hpp:614
Teuchos::RCP< iluk_graph_type > Graph_
The ILU(k) graph.
Definition Ifpack2_RILUK_decl.hpp:592
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
Definition Ifpack2_RILUK_def.hpp:203
void compute()
Compute the (numeric) incomplete factorization.
Definition Ifpack2_RILUK_def.hpp:1085
static Teuchos::RCP< const row_matrix_type > makeLocalFilter(const Teuchos::RCP< const row_matrix_type > &A)
Return A, wrapped in a LocalFilter, if necessary.
Definition Ifpack2_RILUK_def.hpp:438
Teuchos::RCP< vec_type > D_
The diagonal entries of the ILU(k) factorization.
Definition Ifpack2_RILUK_decl.hpp:617
bool isKokkosKernelsSpiluk_
Optional KokkosKernels implementation.
Definition Ifpack2_RILUK_decl.hpp:639
bool isInitialized() const
Whether initialize() has been called on this object.
Definition Ifpack2_RILUK_decl.hpp:341
double getInitializeTime() const
Total time in seconds taken by all successful initialize() calls for this object.
Definition Ifpack2_RILUK_decl.hpp:363
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Tpetra::RowMatrix specialization used by this class.
Definition Ifpack2_RILUK_decl.hpp:246
Teuchos::RCP< Ifpack2::IlukGraph< Tpetra::CrsGraph< local_ordinal_type, global_ordinal_type, node_type >, kk_handle_type > > getGraph() const
Return the Ifpack2::IlukGraph associated with this factored matrix.
Definition Ifpack2_RILUK_decl.hpp:535
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40