Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 "KokkosSparse_sptrsv.hpp"
20 
21 namespace Ifpack2 {
22 
45 template<class MatrixType>
47  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 {
56 public:
58  typedef typename MatrixType::scalar_type scalar_type;
60  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
62  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
64  typedef typename MatrixType::node_type node_type;
65 
67  typedef typename MatrixType::mag_type magnitude_type;
69  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
71  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
74  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
76 
77  static_assert (std::is_same<MatrixType, row_matrix_type>::value,
78  "Ifpack2::LocalSparseTriangularSolver: The template parameter "
79  "MatrixType must be a Tpetra::RowMatrix specialization. "
80  "Please don't use Tpetra::CrsMatrix (a subclass of "
81  "Tpetra::RowMatrix) here anymore. The constructor can take "
82  "either a RowMatrix or a CrsMatrix just fine.");
83 
84  // Use the local matrix types
85  using local_matrix_device_type = typename crs_matrix_type::local_matrix_device_type;
86  using local_matrix_graph_device_type = typename local_matrix_device_type::StaticCrsGraphType;
87  using lno_row_view_t = typename local_matrix_graph_device_type::row_map_type;
88  using lno_nonzero_view_t = typename local_matrix_graph_device_type::entries_type;
89  using scalar_nonzero_view_t = typename local_matrix_device_type::values_type;
90  using TemporaryMemorySpace = typename local_matrix_graph_device_type::device_type::memory_space;
91  using PersistentMemorySpace = typename local_matrix_graph_device_type::device_type::memory_space;
92  using HandleExecSpace = typename local_matrix_graph_device_type::device_type::execution_space;
93  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 >;
94 
123 
134 
139 
151  LocalSparseTriangularSolver (const bool /* unused */, const Teuchos::RCP<Teuchos::FancyOStream>& out);
152 
154  virtual ~LocalSparseTriangularSolver ();
155 
168  void setParameters (const Teuchos::ParameterList& params);
169 
175  void initialize ();
176 
178  inline bool isInitialized () const {
179  return isInitialized_;
180  }
181 
186  void compute ();
187 
189  inline bool isComputed () const {
190  return isComputed_;
191  }
192 
194 
195 
211  void
212  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
213  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
217 
220 
223 
232  void
233  applyMat (const Tpetra::MultiVector<scalar_type, local_ordinal_type,
235  Tpetra::MultiVector<scalar_type, local_ordinal_type,
237  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
238 
241 
244  return A_;
245  }
246 
248  double getComputeFlops () const;
249 
251  double getApplyFlops () const;
252 
254  int getNumInitialize () const;
255 
257  int getNumCompute () const;
258 
260  int getNumApply () const;
261 
263  double getInitializeTime () const;
264 
266  double getComputeTime () const;
267 
269  double getApplyTime () const;
270 
272 
274 
276  std::string description() const;
277 
299  void
301  const Teuchos::EVerbosityLevel verbLevel =
303 
308  virtual void setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
309 
312  void setStreamInfo (const bool& isKokkosKernelsStream, const int& num_streams, const std::vector<HandleExecSpace>& exec_space_instances);
313 
318  void setMatrices (const std::vector< Teuchos::RCP<crs_matrix_type> >& A_crs_v);
319 
321 
322 private:
329  std::vector< Teuchos::RCP<crs_matrix_type> > A_crs_v_;
330 
331  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
332  mutable Teuchos::RCP<MV> X_colMap_;
333  mutable Teuchos::RCP<MV> Y_rowMap_;
334 
335  bool isInitialized_;
336  bool isComputed_;
346  bool isInternallyChanged_;
347  bool reverseStorage_;
348 
349  mutable int numInitialize_;
350  mutable int numCompute_;
351  mutable int numApply_;
352 
353  double initializeTime_;
354  double computeTime_;
355  double applyTime_;
356 
358  class HtsImpl;
359  Teuchos::RCP<HtsImpl> htsImpl_;
360 
362  bool isKokkosKernelsSptrsv_;
364  std::vector< Teuchos::RCP<k_handle> > kh_v_;
365  int num_streams_;
366  bool isKokkosKernelsStream_;
367  bool kh_v_nonnull_;
368  std::vector<HandleExecSpace> exec_space_instances_;
369 
373  std::string uplo_;
376  std::string diag_;
377 
396  void
397  localApply (const MV& X,
398  MV& Y,
399  const Teuchos::ETransp mode,
400  const scalar_type& alpha,
401  const scalar_type& beta) const;
402 
404  void
405  localTriangularSolve (const MV& Y,
406  MV& X,
407  const Teuchos::ETransp mode) const;
408 
409  void initializeState();
410 
411  KokkosSparse::Experimental::SPTRSVAlgorithm kokkosKernelsAlgorithm() const;
412 };
413 
414 } // namespace Ifpack2
415 
416 #endif // IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:60
double getApplyFlops() const
Return the number of flops for the application of the preconditioner.
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:706
int getNumCompute() const
Return the number of calls to compute().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1050
std::string description() const
A one-line description of this object.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1085
void compute()
&quot;Numeric&quot; phase of setup
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:602
Teuchos::RCP< const row_matrix_type > getMatrix() const
The original input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:243
MatrixType::global_ordinal_type global_ordinal_type
Type of the global indices of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:62
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:189
double getApplyTime() const
Return the time spent in apply().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1078
double getComputeTime() const
Return the time spent in compute().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1071
double getInitializeTime() const
Return the time spent in initialize().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1064
double getComputeFlops() const
Return the number of flops in the computation phase.
MatrixType::node_type node_type
Node type of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:64
void setMatrices(const std::vector< Teuchos::RCP< crs_matrix_type > > &A_crs_v)
Set this preconditioner&#39;s matrices (used by stream interface of triangular solve).
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1240
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.
Teuchos::RCP< const map_type > getDomainMap() const
The domain of this operator.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1158
&quot;Preconditioner&quot; that solves local sparse triangular systems.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:46
void initialize()
&quot;Symbolic&quot; phase of setup
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:355
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:74
int getNumInitialize() const
Return the number of calls to initialize().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1043
void setStreamInfo(const bool &isKokkosKernelsStream, const int &num_streams, const std::vector< HandleExecSpace > &exec_space_instances)
Set this triangular solver&#39;s stream information.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1229
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:69
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set this preconditioner&#39;s matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1183
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
This operator&#39;s communicator.
Declaration of interface for preconditioners that can change their matrix after construction.
static const EVerbosityLevel verbLevel_default
int getNumApply() const
Return the number of calls to apply().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1057
MatrixType::local_ordinal_type local_ordinal_type
Type of the local indices of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:60
Teuchos::RCP< const map_type > getRangeMap() const
The range of this operator.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:1171
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:75
void setParameters(const Teuchos::ParameterList &params)
Set this object&#39;s parameters.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:308
MatrixType::scalar_type scalar_type
Type of the entries of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:58
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:1120
MatrixType::mag_type magnitude_type
Type of the absolute value (magnitude) of a scalar_type value.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:67
virtual ~LocalSparseTriangularSolver()
Destructor (virtual for memory safety).
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:289
LocalSparseTriangularSolver()
Constructor that takes no input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:250
bool isInitialized() const
Return true if the preconditioner has been successfully initialized.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:178
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:72