Ifpack2 Templated Preconditioning Package  Version 1.0
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 <KokkosCompat_DefaultNode.hpp>
54 #include <KokkosSparse_CrsMatrix.hpp>
57 #include <shylu_fastutil.hpp>
58 
59 #ifdef HAVE_IFPACK2_METIS
60 #include "metis.h"
61 #endif
62 
63 namespace Ifpack2
64 {
65 namespace Details
66 {
67 
70 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
71  class FastILU_Base : public Ifpack2::Preconditioner<Scalar, LocalOrdinal, GlobalOrdinal, Node>,
73  Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
74 {
75  public:
77  typedef typename Node::device_type device_type;
79  typedef typename device_type::execution_space execution_space;
81  typedef typename Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>::impl_scalar_type ImplScalar;
83  typedef Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> TRowMatrix;
85  typedef Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> TCrsMatrix;
87  typedef Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> TMultiVec;
89  typedef KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, execution_space> KCrsMatrix;
91  typedef Kokkos::View<LocalOrdinal *, execution_space> OrdinalArray;
93  typedef typename Kokkos::View<LocalOrdinal *, execution_space>::HostMirror OrdinalArrayHost;
95  typedef Kokkos::View< ImplScalar *, execution_space> ImplScalarArray;
96  typedef Kokkos::View< Scalar *, execution_space> ScalarArray;
97  typedef Kokkos::View<const Scalar *, execution_space> ConstScalarArray;
98  #ifdef HAVE_IFPACK2_METIS
99  typedef Kokkos::View<idx_t*, Kokkos::HostSpace> MetisArrayHost;
100  #endif
101 
103  FastILU_Base(Teuchos::RCP<const TRowMatrix> mat_);
104 
106  Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
107  getDomainMap () const;
108 
110  Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
111  getRangeMap () const;
112 
114  void
115  apply (const TMultiVec& X,
116  TMultiVec& Y,
117  Teuchos::ETransp mode = Teuchos::NO_TRANS,
118  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
119  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
121 
132  void setParameters (const Teuchos::ParameterList& List);
133 
135  void initialize();
136 
138  bool isInitialized() const;
139 
141  void compute();
142 
144  bool isComputed() const;
145 
147  Teuchos::RCP<const TRowMatrix> getMatrix() const;
148 
150  int getNumInitialize() const;
151 
153  int getNumCompute() const;
154 
156  int getNumApply() const;
157 
159  double getInitializeTime() const;
160 
162  double getComputeTime() const;
163 
165  double getApplyTime() const;
166 
168  double getCopyTime() const;
169 
171  virtual int getSweeps() const = 0;
172 
174  virtual std::string getSpTrsvType() const = 0;
175 
177  virtual int getNTrisol() const = 0;
178 
180  virtual void checkLocalILU() const;
181 
183  virtual void checkLocalIC() const;
184 
186  std::string description() const;
187 
191  void setMatrix(const Teuchos::RCP<const TRowMatrix>& A);
192 
193  protected:
194  Teuchos::RCP<const TRowMatrix> mat_;
195  bool initFlag_;
196  bool computedFlag_;
197  int nInit_;
198  int nComputed_;
199  mutable int nApply_;
200  //store the local CRS components
201  ImplScalarArray localValues_; //set at beginning of compute()
202  OrdinalArray localRowPtrs_; //set in initialize()
203  OrdinalArray localColInds_; //set in initialize()
204  OrdinalArrayHost localRowPtrsHost_; //set in initialize() and used to get localValues_ in compute()
205  double initTime_;
206  double computeTime_;
207  mutable double applyTime_;
208  double crsCopyTime_; //total time spent deep copying values, rowptrs, colinds out of mat
209 
210  //Store validated parameter values (instead of keeping a ParameterList around)
211  struct Params
212  {
213  Params() {}
214  Params(const Teuchos::ParameterList& pL, std::string precType);
215  bool use_metis;
216  FastILU::SpTRSV sptrsv_algo;
217  int nFact;
218  int nTrisol;
219  int level;
220  int blkSize;
221  double omega;
222  double shift;
223  bool guessFlag;
224  int blockSizeILU;
225  int blockSize;
226  static Params getDefaults();
227  };
228 
229  Params params_;
230 
231  #ifdef HAVE_IFPACK2_METIS
232  MetisArrayHost metis_perm_;
233  MetisArrayHost metis_iperm_;
234  #endif
235 
237  // \pre !mat_.is_null()
238  virtual void initLocalPrec() = 0;
240  virtual void computeLocalPrec() = 0;
242  virtual void applyLocalPrec(ImplScalarArray x, ImplScalarArray y) const = 0;
244  virtual std::string getName() const = 0;
245 };
246 
247 } //namespace Details
248 } //namespace Ifpack2
249 
250 #endif
251 
virtual std::string getName() const =0
Get the name of the underlying preconditioner ("Filu", "Fildl" or "Fic")
Mix-in interface for preconditioners that can change their matrix after construction.
Definition: Ifpack2_Details_CanChangeMatrix.hpp:93
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
Kokkos::View< LocalOrdinal *, execution_space >::HostMirror OrdinalArrayHost
Array of LocalOrdinal on host.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:93
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
virtual int getNTrisol() const =0
Get the "triangular solve iterations" parameter.
virtual void applyLocalPrec(ImplScalarArray x, ImplScalarArray y) const =0
Apply the local preconditioner with 1-D views of the local parts of X and Y (one vector only) ...
device_type::execution_space execution_space
Kokkos execution space.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:79
double getApplyTime() const
Get the time spent in the last apply() call.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:337
Teuchos::RCP< const TRowMatrix > getMatrix() const
Get the current matrix.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:295
virtual int getSweeps() const =0
Get the "sweeps" parameter.
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:255
Ifpack2 implementation details.
Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > TCrsMatrix
Tpetra CRS matrix.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:85
int getNumInitialize() const
Get the number of times initialize() was called.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:302
virtual void checkLocalIC() const
Verify and print debug information about the underlying IC preconditioner.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:359
Kokkos::View< LocalOrdinal *, execution_space > OrdinalArray
Array of LocalOrdinal on device.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:91
The base class of the Ifpack2 FastILU wrappers (Filu, Fildl and Fic)
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:71
void setParameters(const Teuchos::ParameterList &List)
Validate parameters, and set defaults when parameters are not provided.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:150
double getInitializeTime() const
Get the time spent in the last initialize() call.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:323
void compute()
Compute the preconditioner.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:262
Node::device_type device_type
Kokkos device type.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:77
Interface for all Ifpack2 preconditioners.
Definition: Ifpack2_Preconditioner.hpp:107
Kokkos::View< ImplScalar *, execution_space > ImplScalarArray
Array of Scalar on device.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:95
FastILU_Base(Teuchos::RCP< const TRowMatrix > mat_)
Constructor.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:61
Declaration of interface for preconditioners that can change their matrix after construction.
KokkosSparse::CrsMatrix< Scalar, LocalOrdinal, execution_space > KCrsMatrix
Kokkos CRS matrix.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:89
std::string description() const
Return a brief description of the preconditioner, in YAML format.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:366
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:351
void initialize()
Initialize the preconditioner.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:158
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > TMultiVec
Tpetra multivector.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:87
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >::impl_scalar_type ImplScalar
Kokkos scalar type.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:81
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 getCopyTime() const
Get the time spent deep copying local 3-array CRS out of the matrix.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:344
int getNumApply() const
Get the number of times apply() was called.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:316
Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > TRowMatrix
Tpetra row matrix.
Definition: Ifpack2_Details_FastILU_Base_decl.hpp:83
void setMatrix(const Teuchos::RCP< const TRowMatrix > &A)
Definition: Ifpack2_Details_FastILU_Base_def.hpp:392
double getComputeTime() const
Get the time spent in the last compute() call.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:330
virtual void initLocalPrec()=0
Construct the underlying preconditioner (localPrec_) using given params and then call localPrec_->ini...
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:74
int getNumCompute() const
Get the number of times compute() was called.
Definition: Ifpack2_Details_FastILU_Base_def.hpp:309
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:287
virtual void computeLocalPrec()=0
Get values array from the matrix and then call compute() on the underlying preconditioner.
virtual std::string getSpTrsvType() const =0
Get the name of triangular solve algorithm.