Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_FastILU_Base_decl.hpp
Go to the documentation of this file.
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 
47 
48 #ifndef __IFPACK2_FASTILU_BASE_DECL_HPP__
49 #define __IFPACK2_FASTILU_BASE_DECL_HPP__
50 
51 #include <Tpetra_RowMatrix.hpp>
52 #include <Tpetra_CrsMatrix.hpp>
53 #include <Kokkos_DefaultNode.hpp>
54 #include <KokkosSparse_CrsMatrix.hpp>
57 
58 namespace Ifpack2
59 {
60 namespace Details
61 {
62 
65 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
66  class FastILU_Base : public Ifpack2::Preconditioner<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
68  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
69 {
70  public:
72  typedef typename Node::device_type device_type;
74  typedef typename device_type::execution_space execution_space;
76  typedef Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> TRowMatrix;
78  typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> TCrsMatrix;
80  typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TMultiVec;
82  typedef KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, execution_space> KCrsMatrix;
84  typedef Kokkos::View<LocalOrdinal *, execution_space> OrdinalArray;
86  typedef Kokkos::View<LocalOrdinal *, Kokkos::HostSpace> OrdinalArrayHost;
88  typedef Kokkos::View<Scalar *, execution_space> ScalarArray;
90  typedef Kokkos::View<Scalar *, Kokkos::HostSpace> ScalarArrayHost;
91 
94 
97  getDomainMap () const;
98 
101  getRangeMap () const;
102 
104  void
105  apply (const TMultiVec& X,
106  TMultiVec& Y,
108  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
109  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
111 
122  void setParameters (const Teuchos::ParameterList& List);
123 
125  void initialize();
126 
128  bool isInitialized() const;
129 
131  void compute();
132 
134  bool isComputed() const;
135 
138 
140  int getNumInitialize() const;
141 
143  int getNumCompute() const;
144 
146  int getNumApply() const;
147 
149  double getInitializeTime() const;
150 
152  double getComputeTime() const;
153 
155  double getApplyTime() const;
156 
158  double getCopyTime() const;
159 
161  virtual int getSweeps() const = 0;
162 
164  virtual int getNTrisol() const = 0;
165 
167  virtual void checkLocalILU() const;
168 
170  virtual void checkLocalIC() const;
171 
173  std::string description() const;
174 
179 
180  protected:
182  bool initFlag_;
183  bool computedFlag_;
184  int nInit_;
185  int nComputed_;
186  mutable int nApply_;
187  //store the local CRS components
188  ScalarArray localValues_; //set at beginning of compute()
189  OrdinalArray localRowPtrs_; //set in initialize()
190  OrdinalArray localColInds_; //set in initialize()
191  OrdinalArrayHost localRowPtrsHost_; //set in initialize() and used to get localValues_ in compute()
192  double initTime_;
193  double computeTime_;
194  mutable double applyTime_;
195  double crsCopyTime_; //total time spent deep copying values, rowptrs, colinds out of mat
196 
197  //Store validated parameter values (instead of keeping a ParameterList around)
198  struct Params
199  {
200  Params() {}
201  Params(const Teuchos::ParameterList& pL, std::string precType);
202  int nFact;
203  int nTrisol;
204  int level;
205  double omega;
206  double shift;
207  bool guessFlag;
208  int blockSize;
209  static Params getDefaults();
210  };
211 
212  Params params_;
213 
215  // \pre !mat_.is_null()
216  virtual void initLocalPrec() = 0;
218  virtual void computeLocalPrec() = 0;
220  virtual void applyLocalPrec(ScalarArray x, ScalarArray y) const = 0;
222  virtual std::string getName() const = 0;
223 };
224 
225 } //namespace Details
226 } //namespace Ifpack2
227 
228 #endif
229 
virtual std::string getName() const =0
Get the name of the underlying preconditioner (&quot;Filu&quot;, &quot;Fildl&quot; or &quot;Fic&quot;)
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
int getNumCompute() const
Get the number of times compute() was called.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:231
virtual void checkLocalIC() const
Verify and print debug information about the underlying IC preconditioner.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:281
double getComputeTime() const
Get the time spent in the last compute() call.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:252
virtual int getNTrisol() const =0
Get the &quot;triangular solve iterations&quot; parameter.
device_type::execution_space execution_space
Kokkos execution space.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:74
double getCopyTime() const
Get the time spent deep copying local 3-array CRS out of the matrix.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:266
virtual int getSweeps() const =0
Get the &quot;sweeps&quot; parameter.
double getInitializeTime() const
Get the time spent in the last initialize() call.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:245
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Get the range map of the matrix.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:85
double getApplyTime() const
Get the time spent in the last apply() call.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:259
Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > TCrsMatrix
Tpetra CRS matrix.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:78
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Get the domain map of the matrix.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:77
Teuchos::RCP< const TRowMatrix > getMatrix() const
Get the current matrix.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:217
Kokkos::View< Scalar *, Kokkos::HostSpace > ScalarArrayHost
Array of Scalar on host.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:90
virtual void checkLocalILU() const
Verify and print debug information about the underlying ILU preconditioner (only supported if this is...
Definition: Ifpack2_Details_FastILU_Base_def.hpp:273
Kokkos::View< LocalOrdinal *, execution_space > OrdinalArray
Array of LocalOrdinal on device.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:84
int getNumApply() const
Get the number of times apply() was called.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:238
The base class of the Ifpack2 FastILU wrappers (Filu, Fildl and Fic)
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:66
void setParameters(const Teuchos::ParameterList &List)
Validate parameters, and set defaults when parameters are not provided.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:146
std::string description() const
Return a brief description of the preconditioner, in YAML format.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:288
void compute()
Compute the preconditioner.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:184
Node::device_type device_type
Kokkos device type.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:72
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
FastILU_Base(Teuchos::RCP< const TRowMatrix > mat_)
Constructor.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:61
bool isComputed() const
Whether compute() has been called since the last time the matrix&#39;s values or structure were changed...
Definition: Ifpack2_Details_FastILU_Base_def.hpp:209
Declaration of interface for preconditioners that can change their matrix after construction.
bool isInitialized() const
Whether initialize() has been called since the last time the matrix&#39;s structure was changed...
Definition: Ifpack2_Details_FastILU_Base_def.hpp:177
KokkosSparse::CrsMatrix< Scalar, LocalOrdinal, execution_space > KCrsMatrix
Kokkos CRS matrix.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:82
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:154
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > TMultiVec
Tpetra multivector.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:80
virtual void applyLocalPrec(ScalarArray x, ScalarArray y) const =0
Apply the local preconditioner with 1-D views of the local parts of X and Y (one vector only) ...
Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > TRowMatrix
Tpetra row matrix.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:76
Kokkos::View< LocalOrdinal *, Kokkos::HostSpace > OrdinalArrayHost
Array of LocalOrdinal on host.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:86
void setMatrix(const Teuchos::RCP< const TRowMatrix > &A)
Definition: Ifpack2_Details_FastILU_Base_def.hpp:311
Kokkos::View< Scalar *, execution_space > ScalarArray
Array of Scalar on device.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:88
virtual void initLocalPrec()=0
Construct the underlying preconditioner (localPrec_) using given params and then call localPrec_-&gt;ini...
void apply(const TMultiVec &X, TMultiVec &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Apply the preconditioner.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:92
int getNumInitialize() const
Get the number of times initialize() was called.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:224
virtual void computeLocalPrec()=0
Get values array from the matrix and then call compute() on the underlying preconditioner.