Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_LocalSparseTriangularSolver_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 
43 #ifndef IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
44 #define IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
45 
48 #include "Tpetra_CrsMatrix_fwd.hpp"
49 #include "Teuchos_FancyOStream.hpp"
50 #include <type_traits>
51 
52 #include "KokkosSparse_sptrsv.hpp"
53 
54 namespace Ifpack2 {
55 
78 template<class MatrixType>
80  virtual public Ifpack2::Preconditioner<typename MatrixType::scalar_type,
81  typename MatrixType::local_ordinal_type,
82  typename MatrixType::global_ordinal_type,
83  typename MatrixType::node_type>,
84  virtual public Ifpack2::Details::CanChangeMatrix<Tpetra::RowMatrix<typename MatrixType::scalar_type,
85  typename MatrixType::local_ordinal_type,
86  typename MatrixType::global_ordinal_type,
87  typename MatrixType::node_type> >
88 {
89 public:
91  typedef typename MatrixType::scalar_type scalar_type;
93  typedef typename MatrixType::local_ordinal_type local_ordinal_type;
95  typedef typename MatrixType::global_ordinal_type global_ordinal_type;
97  typedef typename MatrixType::node_type node_type;
98 
100  typedef typename MatrixType::mag_type magnitude_type;
102  typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
104  typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type,
107  typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
109 
110  static_assert (std::is_same<MatrixType, row_matrix_type>::value,
111  "Ifpack2::LocalSparseTriangularSolver: The template parameter "
112  "MatrixType must be a Tpetra::RowMatrix specialization. "
113  "Please don't use Tpetra::CrsMatrix (a subclass of "
114  "Tpetra::RowMatrix) here anymore. The constructor can take "
115  "either a RowMatrix or a CrsMatrix just fine.");
116 
117  // Use the local matrix types
118  using local_matrix_device_type = typename crs_matrix_type::local_matrix_device_type;
119  using local_matrix_graph_device_type = typename local_matrix_device_type::StaticCrsGraphType;
120  using lno_row_view_t = typename local_matrix_graph_device_type::row_map_type;
121  using lno_nonzero_view_t = typename local_matrix_graph_device_type::entries_type;
122  using scalar_nonzero_view_t = typename local_matrix_device_type::values_type;
123  using TemporaryMemorySpace = typename local_matrix_graph_device_type::device_type::memory_space;
124  using PersistentMemorySpace = typename local_matrix_graph_device_type::device_type::memory_space;
125  using HandleExecSpace = typename local_matrix_graph_device_type::device_type::execution_space;
126  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 >;
127 
155  LocalSparseTriangularSolver (const Teuchos::RCP<const row_matrix_type>& A);
156 
165  LocalSparseTriangularSolver (const Teuchos::RCP<const row_matrix_type>& A,
166  const Teuchos::RCP<Teuchos::FancyOStream>& out);
167 
172 
184  LocalSparseTriangularSolver (const bool /* unused */, const Teuchos::RCP<Teuchos::FancyOStream>& out);
185 
187  virtual ~LocalSparseTriangularSolver ();
188 
201  void setParameters (const Teuchos::ParameterList& params);
202 
208  void initialize ();
209 
211  inline bool isInitialized () const {
212  return isInitialized_;
213  }
214 
219  void compute ();
220 
222  inline bool isComputed () const {
223  return isComputed_;
224  }
225 
227 
228 
244  void
245  apply (const Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& X,
246  Tpetra::MultiVector<scalar_type,local_ordinal_type,global_ordinal_type,node_type>& Y,
247  Teuchos::ETransp mode = Teuchos::NO_TRANS,
248  scalar_type alpha = Teuchos::ScalarTraits<scalar_type>::one (),
249  scalar_type beta = Teuchos::ScalarTraits<scalar_type>::zero ()) const;
250 
252  Teuchos::RCP<const map_type> getDomainMap () const;
253 
255  Teuchos::RCP<const map_type> getRangeMap () const;
256 
265  void
266  applyMat (const Tpetra::MultiVector<scalar_type, local_ordinal_type,
268  Tpetra::MultiVector<scalar_type, local_ordinal_type,
270  Teuchos::ETransp mode = Teuchos::NO_TRANS) const;
271 
273  Teuchos::RCP<const Teuchos::Comm<int> > getComm () const;
274 
276  Teuchos::RCP<const row_matrix_type> getMatrix () const {
277  return A_;
278  }
279 
281  double getComputeFlops () const;
282 
284  double getApplyFlops () const;
285 
287  int getNumInitialize () const;
288 
290  int getNumCompute () const;
291 
293  int getNumApply () const;
294 
296  double getInitializeTime () const;
297 
299  double getComputeTime () const;
300 
302  double getApplyTime () const;
303 
305 
307 
309  std::string description() const;
310 
332  void
333  describe (Teuchos::FancyOStream& out,
334  const Teuchos::EVerbosityLevel verbLevel =
335  Teuchos::Describable::verbLevel_default) const;
336 
341  virtual void setMatrix (const Teuchos::RCP<const row_matrix_type>& A);
342 
344 
345 private:
347  Teuchos::RCP<const row_matrix_type> A_;
349  Teuchos::RCP<Teuchos::FancyOStream> out_;
351  Teuchos::RCP<const crs_matrix_type> A_crs_;
352 
353  typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
354  mutable Teuchos::RCP<MV> X_colMap_;
355  mutable Teuchos::RCP<MV> Y_rowMap_;
356 
357  bool isInitialized_;
358  bool isComputed_;
368  bool isInternallyChanged_;
369  bool reverseStorage_;
370 
371  mutable int numInitialize_;
372  mutable int numCompute_;
373  mutable int numApply_;
374 
375  double initializeTime_;
376  double computeTime_;
377  double applyTime_;
378 
380  class HtsImpl;
381  Teuchos::RCP<HtsImpl> htsImpl_;
382 
384  bool isKokkosKernelsSptrsv_;
385  Teuchos::RCP<k_handle> kh_;
386 
390  std::string uplo_;
393  std::string diag_;
394 
413  void
414  localApply (const MV& X,
415  MV& Y,
416  const Teuchos::ETransp mode,
417  const scalar_type& alpha,
418  const scalar_type& beta) const;
419 
421  void
422  localTriangularSolve (const MV& Y,
423  MV& X,
424  const Teuchos::ETransp mode) const;
425 
426  void initializeState();
427 };
428 
429 } // namespace Ifpack2
430 
431 #endif // IFPACK2_LOCALSPARSETRIANGULARSOLVER_DECL_HPP
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
Teuchos::RCP< const row_matrix_type > getMatrix() const
The original input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:276
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:596
bool isInitialized() const
Return true if the preconditioner has been successfully initialized.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:211
int getNumInitialize() const
Return the number of calls to initialize().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:829
Teuchos::RCP< const map_type > getDomainMap() const
The domain of this operator.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:942
Teuchos::RCP< const map_type > getRangeMap() const
The range of this operator.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:955
int getNumCompute() const
Return the number of calls to compute().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:836
double getApplyTime() const
Return the time spent in apply().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:864
void compute()
"Numeric" phase of setup
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:533
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:904
MatrixType::global_ordinal_type global_ordinal_type
Type of the global indices of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:95
MatrixType::node_type node_type
Node type of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:97
bool isComputed() const
Return true if compute() has been called.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:222
double getComputeTime() const
Return the time spent in compute().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:857
int getNumApply() const
Return the number of calls to apply().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:843
double getComputeFlops() const
Return the number of flops in the computation phase.
"Preconditioner" that solves local sparse triangular systems.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:79
void initialize()
"Symbolic" phase of setup
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:375
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
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:102
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Set this preconditioner&#39;s matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:967
Declaration of interface for preconditioners that can change their matrix after construction.
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.
double getInitializeTime() const
Return the time spent in initialize().
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:850
double getApplyFlops() const
Return the number of flops for the application of the preconditioner.
MatrixType::local_ordinal_type local_ordinal_type
Type of the local indices of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:93
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
This operator&#39;s communicator.
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:108
void setParameters(const Teuchos::ParameterList &params)
Set this object&#39;s parameters.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:331
MatrixType::scalar_type scalar_type
Type of the entries of the input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:91
std::string description() const
A one-line description of this object.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:871
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:73
MatrixType::mag_type magnitude_type
Type of the absolute value (magnitude) of a scalar_type value.
Definition: Ifpack2_LocalSparseTriangularSolver_decl.hpp:100
virtual ~LocalSparseTriangularSolver()
Destructor (virtual for memory safety).
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:320
LocalSparseTriangularSolver()
Constructor that takes no input matrix.
Definition: Ifpack2_LocalSparseTriangularSolver_def.hpp:283
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:105