Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_LocalSparseTriangularSolver_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
10#ifndef IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
11#define IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
12
15#include "Tpetra_CrsMatrix_fwd.hpp"
16#include "Teuchos_FancyOStream.hpp"
17#include <type_traits>
18
19#include "KokkosKernels_Handle.hpp"
20#include "KokkosSparse_sptrsv_handle.hpp"
21
22namespace Ifpack2 {
23
46template <class MatrixType>
47class LocalSparseTriangularSolver : virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
48 typename MatrixType::local_ordinal_type,
49 typename MatrixType::global_ordinal_type,
50 typename MatrixType::node_type>,
51 virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
52 typename MatrixType::local_ordinal_type,
53 typename MatrixType::global_ordinal_type,
54 typename MatrixType::node_type> > {
55 public:
57 typedef typename MatrixType::scalar_type scalar_type;
59 typedef typename MatrixType::impl_scalar_type impl_scalar_type;
61 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
63 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
65 typedef typename MatrixType::node_type node_type;
66
68 typedef typename MatrixType::mag_type magnitude_type;
70 typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
72 typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
76 typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
79
80 static_assert(std::is_same<MatrixType, row_matrix_type>::value,
81 "Ifpack2::LocalSparseTriangularSolver: The template parameter "
82 "MatrixType must be a Tpetra::RowMatrix specialization. "
83 "Please don't use Tpetra::CrsMatrix (a subclass of "
84 "Tpetra::RowMatrix) here anymore. The constructor can take "
85 "either a RowMatrix or a CrsMatrix just fine.");
86
87 // Use the local matrix types
88 using local_matrix_device_type = typename crs_matrix_type::local_matrix_device_type;
89 using local_matrix_graph_device_type = typename local_matrix_device_type::StaticCrsGraphType;
90 using lno_row_view_t = typename local_matrix_graph_device_type::row_map_type;
91 using lno_nonzero_view_t = typename local_matrix_graph_device_type::entries_type;
92 using scalar_nonzero_view_t = typename local_matrix_device_type::values_type;
93 using TemporaryMemorySpace = typename local_matrix_graph_device_type::device_type::memory_space;
94 using PersistentMemorySpace = typename local_matrix_graph_device_type::device_type::memory_space;
95 using HandleExecSpace = typename local_matrix_graph_device_type::device_type::execution_space;
96 using k_handle = 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, HandleExecSpace, TemporaryMemorySpace, PersistentMemorySpace>;
97
125 LocalSparseTriangularSolver(const Teuchos::RCP<const row_matrix_type>& A);
126
135 LocalSparseTriangularSolver(const Teuchos::RCP<const row_matrix_type>& A,
136 const Teuchos::RCP<Teuchos::FancyOStream>& out);
137
142
154 LocalSparseTriangularSolver(const bool /* unused */, const Teuchos::RCP<Teuchos::FancyOStream>& out);
155
158
171 void setParameters(const Teuchos::ParameterList& params);
172
178 void initialize();
179
181 inline bool isInitialized() const {
182 return isInitialized_;
183 }
184
189 void compute();
190
192 inline bool isComputed() const {
193 return isComputed_;
194 }
195
197
198
214 void
215 apply(const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
216 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
217 Teuchos::ETransp mode = Teuchos::NO_TRANS,
218 scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one(),
219 scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero()) const;
220
222 Teuchos::RCP<const map_type> getDomainMap() const;
223
225 Teuchos::RCP<const map_type> getRangeMap() const;
226
235 void
236 applyMat(const Tpetra::MultiVector<scalar_type, local_ordinal_type,
238 Tpetra::MultiVector<scalar_type, local_ordinal_type,
240 Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
241
243 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const;
244
246 Teuchos::RCP<const row_matrix_type> getMatrix() const {
247 return A_;
248 }
249
251 double getComputeFlops() const;
252
254 double getApplyFlops() const;
255
257 int getNumInitialize() const;
258
260 int getNumCompute() const;
261
263 int getNumApply() const;
264
266 double getInitializeTime() const;
267
269 double getComputeTime() const;
270
272 double getApplyTime() const;
273
275
277
279 std::string description() const;
280
302 void
303 describe(Teuchos::FancyOStream& out,
304 const Teuchos::EVerbosityLevel verbLevel =
305 Teuchos::Describable::verbLevel_default) const;
306
311 virtual void setMatrix(const Teuchos::RCP<const row_matrix_type>& A);
312
315 void setStreamInfo(const bool& isKokkosKernelsStream, const int& num_streams, const std::vector<HandleExecSpace>& exec_space_instances);
316
321 void setMatrices(const std::vector<Teuchos::RCP<crs_matrix_type> >& A_crs_v);
322
324
325 private:
327 Teuchos::RCP<const row_matrix_type> A_;
329 Teuchos::RCP<Teuchos::FancyOStream> out_;
331 Teuchos::RCP<const crs_matrix_type> A_crs_;
332 std::vector<Teuchos::RCP<crs_matrix_type> > A_crs_v_;
333
334 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
335 mutable Teuchos::RCP<MV> X_colMap_;
336 mutable Teuchos::RCP<MV> Y_rowMap_;
337
338 bool isInitialized_;
339 bool isComputed_;
349 bool isInternallyChanged_;
350 bool reverseStorage_;
351
352 mutable int numInitialize_;
353 mutable int numCompute_;
354 mutable int numApply_;
355
356 double initializeTime_;
357 double computeTime_;
358 double applyTime_;
359
361 class HtsImpl;
362 Teuchos::RCP<HtsImpl> htsImpl_;
363
365 bool isKokkosKernelsSptrsv_;
366 Teuchos::RCP<k_handle> kh_;
367 std::vector<Teuchos::RCP<k_handle> > kh_v_;
368 int num_streams_;
369 bool isKokkosKernelsStream_;
370 bool kh_v_nonnull_;
371 std::vector<HandleExecSpace> exec_space_instances_;
372
376 std::string uplo_;
379 std::string diag_;
380
399 void
400 localApply(const MV& X,
401 MV& Y,
402 const Teuchos::ETransp mode,
403 const scalar_type& alpha,
404 const scalar_type& beta) const;
405
407 void
408 localTriangularSolve(const MV& Y,
409 MV& X,
410 const Teuchos::ETransp mode) const;
411
412 void initializeState();
413
414 KokkosSparse::Experimental::SPTRSVAlgorithm kokkosKernelsAlgorithm() const;
415};
416
417} // namespace Ifpack2
418
419#endif // IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_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
"Preconditioner" that solves local sparse triangular systems.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:54
bool isComputed() const
Return true if compute() has been called.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:192
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with given verbosity to the given output stream.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1094
std::string description() const
A one-line description of this object.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1061
Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > map_type
Specialization of Tpetra::Map used by this class.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:70
LocalSparseTriangularSolver()
Constructor that takes no input matrix.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:297
MatrixType::local_ordinal_type local_ordinal_type
Type of the local indices of the input matrix.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:61
void setParameters(const Teuchos::ParameterList &params)
Set this object's parameters.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:349
double getComputeFlops() const
Return the number of flops in the computation phase.
bool isInitialized() const
Return true if the preconditioner has been successfully initialized.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:181
double getComputeTime() const
Return the time spent in compute().
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1047
Tpetra::RowMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > row_matrix_type
Specialization of Tpetra::RowMatrix used by this class.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:74
void initialize()
"Symbolic" phase of setup
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:393
MatrixType::global_ordinal_type global_ordinal_type
Type of the global indices of the input matrix.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:63
int getNumCompute() const
Return the number of calls to compute().
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1027
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
This operator's communicator.
double getInitializeTime() const
Return the time spent in initialize().
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1040
Teuchos::RCP< const map_type > getDomainMap() const
The domain of this operator.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1128
MatrixType::scalar_type scalar_type
Scalar type of the entries of the input matrix.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:57
MatrixType::node_type node_type
Node type of the input matrix.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:65
MatrixType::mag_type magnitude_type
Type of the absolute value (magnitude) of a scalar_type value.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:68
int getNumInitialize() const
Return the number of calls to initialize().
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1021
MatrixType::impl_scalar_type impl_scalar_type
Implementation scalar type of the entries of the input matrix.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:59
void setStreamInfo(const bool &isKokkosKernelsStream, const int &num_streams, const std::vector< HandleExecSpace > &exec_space_instances)
Set this triangular solver's stream information.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1188
Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > crs_matrix_type
Specialization of Tpetra::CrsMatrix used by this class.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:78
double getApplyFlops() const
Return the number of flops for the application of the preconditioner.
Teuchos::RCP< const map_type > getRangeMap() const
The range of this operator.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1139
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set this preconditioner's matrix.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1149
void setMatrices(const std::vector< Teuchos::RCP< crs_matrix_type > > &A_crs_v)
Set this preconditioner's matrices (used by stream interface of triangular solve).
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1198
Teuchos::RCP< const row_matrix_type > getMatrix() const
The original input matrix.
Definition Ifpack2_LocalSparseTriangularSolver_decl.hpp:246
void applyMat(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) const
Apply the original input matrix.
virtual ~LocalSparseTriangularSolver()
Destructor (virtual for memory safety).
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:333
double getApplyTime() const
Return the time spent in apply().
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1054
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 preconditioner to X, and put the result in Y.
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:720
int getNumApply() const
Return the number of calls to apply().
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:1033
void compute()
"Numeric" phase of setup
Definition Ifpack2_LocalSparseTriangularSolver_def.hpp:643
Interface for all Ifpack2 preconditioners.
Definition Ifpack2_Preconditioner.hpp:74
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40