45 #ifndef __IFPACK2_FASTILU_BASE_DEF_HPP__  
   46 #define __IFPACK2_FASTILU_BASE_DEF_HPP__  
   49 #include <impl/Kokkos_Timer.hpp> 
   59 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
   72   params_(Params::getDefaults()) {}
 
   74 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
   79   return mat_->getDomainMap();
 
   82 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
   87   return mat_->getRangeMap();
 
   90 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
   92 apply (
const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &X,
 
   93        Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
 
   98   const std::string timerName (
"Ifpack2::FastILU::apply");
 
  105   if(!isInitialized() || !isComputed())
 
  107     throw std::runtime_error(std::string(
"Called ") + getName() + 
"::apply() without first calling initialize() and/or compute().");
 
  109   if(X.getNumVectors() != Y.getNumVectors())
 
  111     throw std::invalid_argument(getName() + 
"::apply: X and Y have different numbers of vectors (pass X and Y with exactly matching dimensions)");
 
  113   if(X.getLocalLength() != Y.getLocalLength())
 
  115     throw std::invalid_argument(getName() + 
"::apply: X and Y have different lengths (pass X and Y with exactly matching dimensions)");
 
  119   int nvecs = X.getNumVectors();
 
  122     auto x2d = X.template getLocalView<execution_space>();
 
  123     auto y2d = Y.template getLocalView<execution_space>();
 
  124     auto x1d = Kokkos::subview(x2d, Kokkos::ALL(), 0);
 
  125     auto y1d = Kokkos::subview(y2d, Kokkos::ALL(), 0);
 
  126     applyLocalPrec(x1d, y1d);
 
  131     for(
int i = 0; i < nvecs; i++)
 
  133       auto Xcol = X.getVector(i);
 
  134       auto Ycol = Y.getVector(i);
 
  135       auto xColView2d = Xcol->template getLocalView<execution_space>();
 
  136       auto yColView2d = Ycol->template getLocalView<execution_space>();
 
  137       ScalarArray xColView1d = Kokkos::subview(xColView2d, Kokkos::ALL(), 0);
 
  138       ScalarArray yColView1d = Kokkos::subview(yColView2d, Kokkos::ALL(), 0);
 
  139       applyLocalPrec(xColView1d, yColView1d);
 
  144 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  149   params_ = Params(List, getName());
 
  152 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  157   const std::string timerName (
"Ifpack2::FastILU::initialize");
 
  165     throw std::runtime_error(std::string(
"Called ") + getName() + 
"::initialize() but matrix was null (call setMatrix() with a non-null matrix first)");
 
  167   Kokkos::Impl::Timer copyTimer;
 
  168   CrsArrayReader<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getStructure(mat_.get(), localRowPtrsHost_, localRowPtrs_, localColInds_);
 
  169   crsCopyTime_ = copyTimer.seconds();
 
  175 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  182 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  188     throw std::runtime_error(getName() + 
": initialize() must be called before compute()");
 
  191   const std::string timerName (
"Ifpack2::FastILU::compute");
 
  199   Kokkos::Impl::Timer copyTimer;
 
  200   CrsArrayReader<Scalar, LocalOrdinal, GlobalOrdinal, Node>::getValues(mat_.get(), localValues_, localRowPtrsHost_);
 
  201   crsCopyTime_ += copyTimer.seconds(); 
 
  203   computedFlag_ = 
true;
 
  207 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  211   return computedFlag_;
 
  214 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  222 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  229 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  236 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  243 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  250 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  257 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  264 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  271 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  276   throw std::runtime_error(std::string(
"Preconditioner type Ifpack2::Details::") + getName() + 
" doesn't support checkLocalILU().");
 
  279 template<
class Scalar, 
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  284   throw std::runtime_error(std::string(
"Preconditioner type Ifpack2::Details::") + getName() + 
" doesn't support checkLocalIC().");
 
  287 template<
typename Scalar, 
typename LocalOrdinal, 
typename GlobalOrdinal, 
typename Node>
 
  290   std::ostringstream os;
 
  292   os << 
"\"Ifpack2::Details::" << getName() << 
"\": {";
 
  293   os << 
"Initialized: " << (isInitialized() ? 
"true" : 
"false") << 
", ";
 
  294   os << 
"Computed: " << (isComputed() ? 
"true" : 
"false") << 
", ";
 
  295   os << 
"Sweeps: " << getSweeps() << 
", ";
 
  296   os << 
"# of triangular solve iterations: " << getNTrisol() << 
", ";
 
  299     os << 
"Matrix: null";
 
  303     os << 
"Global matrix dimensions: [" << mat_->getGlobalNumRows() << 
", " << mat_->getGlobalNumCols() << 
"]";
 
  304     os << 
", Global nnz: " << mat_->getGlobalNumEntries();
 
  309 template<
typename Scalar, 
typename LocalOrdinal, 
typename GlobalOrdinal, 
typename Node>
 
  315     throw std::invalid_argument(std::string(
"Ifpack2::Details::") + getName() + 
"::setMatrix() called with a null matrix. Pass a non-null matrix.");
 
  317   typedef Tpetra::RowGraph<LocalOrdinal, GlobalOrdinal, Node> RGraph;
 
  322     aGraph = A->getGraph();
 
  326     aGraph = Teuchos::null;
 
  332       matGraph = mat_->getGraph();
 
  336       matGraph = Teuchos::null;
 
  340   if(mat_.get() != A.
get())
 
  348     computedFlag_ = 
false;
 
  352 template<
typename Scalar, 
typename LocalOrdinal, 
typename GlobalOrdinal, 
typename Node>
 
  368 template<
typename Scalar, 
typename LocalOrdinal, 
typename GlobalOrdinal, 
typename Node>
 
  369 FastILU_Base<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
 
  372   *
this = getDefaults();
 
  378   #define TYPE_ERROR(name, correctTypeName) {throw std::invalid_argument(precType + "::setParameters(): parameter \"" + name + "\" has the wrong type (must be " + correctTypeName + ")");} 
  379   #define CHECK_VALUE(param, member, cond, msg) {if(cond) {throw std::invalid_argument(precType + "::setParameters(): parameter \"" + param + "\" has value " + std::to_string(member) + " but " + msg);}} 
  382     if(pL.
isType<
int>(
"sweeps"))
 
  384       nFact = pL.
get<
int>(
"sweeps");
 
  385       CHECK_VALUE(
"sweeps", nFact, nFact < 1, 
"must have a value of at least 1");
 
  388       TYPE_ERROR(
"sweeps", 
"int");
 
  393     if(pL.
isType<
int>(
"triangular solve iterations"))
 
  395       nTrisol = pL.
get<
int>(
"triangular solve iterations");
 
  396       CHECK_VALUE(
"triangular solve iterations", nTrisol, nTrisol < 1, 
"must have a value of at least 1");
 
  399       TYPE_ERROR(
"triangular solve iterations", 
"int");
 
  404     if(pL.
isType<
int>(
"level"))
 
  406       level = pL.
get<
int>(
"level");
 
  408     else if(pL.
isType<
double>(
"level"))
 
  412       double dval = pL.
get<
double>(
"level");
 
  414       double fpart = modf(dval, &ipart);
 
  416       CHECK_VALUE(
"level", level, fpart != 0, 
"must be an integral value");
 
  420       TYPE_ERROR(
"level", 
"int");
 
  422     CHECK_VALUE(
"level", level, level < 0, 
"must be nonnegative");
 
  427     if(pL.
isType<
double>(
"damping factor"))
 
  428       omega = pL.
get<
double>(
"damping factor");
 
  429     else if(pL.
isType<magnitude>(
"damping factor"))
 
  430       omega = pL.
get<magnitude>(
"damping factor");
 
  432       TYPE_ERROR(
"damping factor", 
"double or magnitude_type");
 
  433     CHECK_VALUE(
"damping factor", omega, omega <= 0 || omega > 1, 
"must be in the range (0, 1]");
 
  438     if(pL.
isType<
double>(
"shift"))
 
  439       shift = pL.
get<
double>(
"shift");
 
  440     else if(pL.
isType<magnitude>(
"shift"))
 
  441       shift = pL.
get<magnitude>(
"shift");
 
  443       TYPE_ERROR(
"shift", 
"double or magnitude_type");
 
  449     if(pL.
isType<
bool>(
"guess"))
 
  450       guessFlag = pL.
get<
bool>(
"guess");
 
  452       TYPE_ERROR(
"guess", 
"bool");
 
  457     if(pL.
isType<
int>(
"block size"))
 
  458       blockSize = pL.
get<
int>(
"block size");
 
  460       TYPE_ERROR(
"block size", 
"int");
 
  466 #define IFPACK2_DETAILS_FASTILU_BASE_INSTANT(S, L, G, N) \ 
  467 template class Ifpack2::Details::FastILU_Base<S, L, G, N>; 
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
 
T & get(const std::string &name, T def_value)
 
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
 
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
 
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
 
bool isParameter(const std::string &name) const 
 
Teuchos::RCP< const TRowMatrix > getMatrix() const 
Get the current matrix. 
Definition: Ifpack2_Details_FastILU_Base_def.hpp:217
 
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
 
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
 
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's values or structure were changed...
Definition: Ifpack2_Details_FastILU_Base_def.hpp:209
 
bool isInitialized() const 
Whether initialize() has been called since the last time the matrix's structure was changed...
Definition: Ifpack2_Details_FastILU_Base_def.hpp:177
 
void initialize()
Initialize the preconditioner. 
Definition: Ifpack2_Details_FastILU_Base_def.hpp:154
 
bool isType(const std::string &name) const 
 
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
 
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
 
Provides functions for retrieving local CRS arrays (row pointers, column indices, and values) from Tp...