10#ifndef IFPACK2_DETAILS_AMESOS2WRAPPER_DEF_HPP
11#define IFPACK2_DETAILS_AMESOS2WRAPPER_DEF_HPP
13#ifdef HAVE_IFPACK2_AMESOS2
15#include "Ifpack2_LocalFilter.hpp"
16#include "Trilinos_Details_LinearSolverFactory.hpp"
17#include "Trilinos_Details_LinearSolver.hpp"
18#include "Teuchos_TimeMonitor.hpp"
19#include "Teuchos_TypeNameTraits.hpp"
33template <
class MatrixType>
37 , InitializeTime_(0.0)
43 , IsInitialized_(
false)
47template <
class MatrixType>
50template <
class MatrixType>
52 using Teuchos::ParameterList;
62 if (
params.name() ==
"Amesos2") {
64 }
else if (
params.isSublist(
"Amesos2")) {
69 if (
params.isParameter(
"Amesos2 solver name")) {
70 SolverName_ =
params.get<std::string>(
"Amesos2 solver name");
76 true, std::runtime_error,
77 "The ParameterList passed to Amesos2 must be "
78 "called \"Amesos2\".");
83 if (solver_.is_null()) {
90 solver_->setParameters(
theList);
93template <
class MatrixType>
94Teuchos::RCP<const Teuchos::Comm<int> >
97 A_.is_null(), std::runtime_error,
98 "Ifpack2::Amesos2Wrapper::getComm: "
99 "The matrix is null. Please call setMatrix() with a nonnull input "
100 "before calling this method.");
101 return A_->getComm();
104template <
class MatrixType>
105Teuchos::RCP<const typename Amesos2Wrapper<MatrixType>::row_matrix_type>
110template <
class MatrixType>
111Teuchos::RCP<const typename Amesos2Wrapper<MatrixType>::map_type>
114 A_.is_null(), std::runtime_error,
115 "Ifpack2::Amesos2Wrapper::getDomainMap: "
116 "The matrix is null. Please call setMatrix() with a nonnull input "
117 "before calling this method.");
118 return A_->getDomainMap();
121template <
class MatrixType>
122Teuchos::RCP<const typename Amesos2Wrapper<MatrixType>::map_type>
125 A_.is_null(), std::runtime_error,
126 "Ifpack2::Amesos2Wrapper::getRangeMap: "
127 "The matrix is null. Please call setMatrix() with a nonnull input "
128 "before calling this method.");
129 return A_->getRangeMap();
132template <
class MatrixType>
137template <
class MatrixType>
139 return NumInitialize_;
142template <
class MatrixType>
147template <
class MatrixType>
152template <
class MatrixType>
154 return InitializeTime_;
157template <
class MatrixType>
162template <
class MatrixType>
167template <
class MatrixType>
173 IsInitialized_ =
false;
193template <
class MatrixType>
194Teuchos::RCP<const typename Amesos2Wrapper<MatrixType>::row_matrix_type>
198 using Teuchos::rcp_dynamic_cast;
199 using Teuchos::rcp_implicit_cast;
204 if (A->getRowMap()->getComm()->getSize() == 1 ||
205 A->getRowMap()->isSameAs(*(A->getColMap()))) {
212 RCP<const LocalFilter<row_matrix_type> > A_lf_r =
213 rcp_dynamic_cast<const LocalFilter<row_matrix_type> >(A);
214 if (!A_lf_r.is_null()) {
215 return rcp_implicit_cast<const row_matrix_type>(A_lf_r);
220 return rcp(
new LocalFilter<row_matrix_type>(A));
224template <
class MatrixType>
226 using Teuchos::Array;
227 using Teuchos::ArrayView;
230 using Teuchos::rcp_const_cast;
231 using Teuchos::rcp_dynamic_cast;
233 using Teuchos::TimeMonitor;
235 const std::string
timerName(
"Ifpack2::Amesos2Wrapper::initialize");
237 if (
timer.is_null()) {
248 A_.is_null(), std::runtime_error,
249 "Ifpack2::Amesos2Wrapper::initialize: "
250 "The matrix to precondition is null. Please call setMatrix() with a "
251 "nonnull input before calling this method.");
254 IsInitialized_ =
false;
259 A_local.is_null(), std::logic_error,
260 "Ifpack2::AmesosWrapper::initialize: "
261 "makeLocalFilter returned null; it failed to compute A_local. "
262 "Please report this bug to the Ifpack2 developers.");
269 if (A_local_crs_.is_null()) {
280 typename crs_matrix_type::nonconst_local_inds_host_view_type
indices(
"Indices",
A_local->getLocalMaxNumRowEntries());
281 typename crs_matrix_type::nonconst_values_host_view_type values(
"Values",
A_local->getLocalMaxNumRowEntries());
301 if (!Trilinos::Details::Impl::rememberRegisteredSomeLinearSolverFactory(
"Amesos2")) {
302 Amesos2::Details::registerLinearSolverFactory();
305 solver_ = Trilinos::Details::getLinearSolver<MV, OP, typename MV::mag_type>(
"Amesos2", SolverName_);
308 "Amesos2Wrapper::initialize: Failed to create Amesos2 solver!");
310 solver_->setMatrix(A_local_crs_);
312 if (parameterList_ != Teuchos::null) {
314 parameterList_ = Teuchos::null;
322 IsInitialized_ =
true;
328template <
class MatrixType>
332 using Teuchos::TimeMonitor;
335 if (!isInitialized()) {
339 const std::string
timerName(
"Ifpack2::Details::Amesos2Wrapper::compute");
341 if (
timer.is_null()) {
358template <
class MatrixType>
360 apply(
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
361 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
362 Teuchos::ETransp
mode,
365 using Teuchos::ArrayView;
368 using Teuchos::rcpFromRef;
370 using Teuchos::TimeMonitor;
375 const std::string
timerName(
"Ifpack2::Amesos2Wrapper::apply");
377 if (
timer.is_null()) {
387 !isComputed(), std::runtime_error,
388 "Ifpack2::Amesos2Wrapper::apply: You must call compute() to compute the "
389 "incomplete factorization, before calling apply().");
392 X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
393 "Ifpack2::Amesos2Wrapper::apply: X and Y must have the same number of columns. "
395 << X.getNumVectors() <<
" columns, but Y has "
396 << Y.getNumVectors() <<
" columns.");
399 mode != Teuchos::NO_TRANS, std::logic_error,
400 "Ifpack2::Amesos2Wrapper::apply: Solving with the transpose (mode == "
401 "Teuchos::TRANS) or conjugate transpose (Teuchos::CONJ_TRANS) is not "
428 const bool multipleProcs = (A_->getRowMap()->getComm()->getSize() > 1) || (X.getMap()->getComm()->getSize() > 1);
433 X_local =
X_temp->offsetView(A_local_crs_->getDomainMap(), 0);
434 Y_local =
Y_temp->offsetViewNonConst(A_local_crs_->getRangeMap(), 0);
444 if (alpha != STS::one() || beta != STS::zero()) {
445 Y.update(alpha, *
Y_temp, beta);
454template <
class MatrixType>
456 using Teuchos::TypeNameTraits;
457 std::ostringstream
os;
462 os <<
"\"Ifpack2::Amesos2Wrapper\": {";
466 os <<
"Initialized: " << (isInitialized() ?
"true" :
"false")
467 <<
", Computed: " << (isComputed() ?
"true" :
"false");
469 if (A_local_crs_.is_null()) {
470 os <<
", Matrix: null";
472 os <<
", Global matrix dimensions: ["
473 << A_local_crs_->getGlobalNumRows() <<
", " << A_local_crs_->getGlobalNumCols() <<
"]";
478 if (!solver_.is_null()) {
479 Teuchos::Describable*
d =
dynamic_cast<Teuchos::Describable*
>(solver_.getRawPtr());
490template <
class MatrixType>
493 const Teuchos::EVerbosityLevel
verbLevel)
const {
496 using Teuchos::OSTab;
498 using Teuchos::TypeNameTraits;
500 const Teuchos::EVerbosityLevel
vl = (
verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW :
verbLevel;
504 if (
vl > Teuchos::VERB_NONE) {
505 out <<
"\"Ifpack2::Amesos2Wrapper\":" <<
endl;
514 out <<
"Initialized: " << (isInitialized() ?
"true" :
"false") <<
endl;
515 out <<
"Computed: " << (isComputed() ?
"true" :
"false") <<
endl;
516 out <<
"Number of initialize calls: " << getNumInitialize() <<
endl;
517 out <<
"Number of compute calls: " << getNumCompute() <<
endl;
518 out <<
"Number of apply calls: " << getNumApply() <<
endl;
519 out <<
"Total time in seconds for initialize: " << getInitializeTime() <<
endl;
520 out <<
"Total time in seconds for compute: " << getComputeTime() <<
endl;
521 out <<
"Total time in seconds for apply: " << getApplyTime() <<
endl;
523 if (
vl > Teuchos::VERB_LOW) {
537#define IFPACK2_DETAILS_AMESOS2WRAPPER_INSTANT(S, LO, GO, N) \
538 template class Ifpack2::Details::Amesos2Wrapper<Tpetra::RowMatrix<S, LO, GO, N> >;
542#define IFPACK2_DETAILS_AMESOS2WRAPPER_INSTANT(S, LO, GO, N)
Wrapper class for direct solvers in Amesos2.
Definition Ifpack2_Details_Amesos2Wrapper_decl.hpp:75
double getComputeTime() const
The total time in seconds spent in successful calls to compute().
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:158
Teuchos::RCP< const map_type > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:123
Teuchos::RCP< const row_matrix_type > getMatrix() const
The input matrix; the matrix to be preconditioned.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:106
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition Ifpack2_Details_Amesos2Wrapper_decl.hpp:81
int getNumInitialize() const
The total number of successful calls to initialize().
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:138
double getApplyTime() const
The total time in seconds spent in successful calls to apply().
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:163
int getNumApply() const
The total number of successful calls to apply().
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:148
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition Ifpack2_Details_Amesos2Wrapper_decl.hpp:84
virtual ~Amesos2Wrapper()
Destructor.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:48
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to the given output stream.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:492
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, resulting in Y.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:360
std::string description() const
A one-line description of this object.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:455
void initialize()
Compute the preordering and symbolic factorization of the matrix.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:225
int getNumCompute() const
The total number of successful calls to compute().
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:143
void setParameters(const Teuchos::ParameterList ¶ms)
Set parameters.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:51
Tpetra::CrsMatrix< scalar_type, local_ordinal_type, global_ordinal_type, node_type > crs_matrix_type
Type of the Tpetra::CrsMatrix specialization that this class uses.
Definition Ifpack2_Details_Amesos2Wrapper_decl.hpp:116
Teuchos::RCP< const map_type > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:112
void compute()
Compute the numeric factorization of the matrix.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:329
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The input matrix's communicator.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:95
Amesos2Wrapper(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:35
double getInitializeTime() const
The total time in seconds spent in successful calls to initialize().
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:153
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:168
bool hasTransposeApply() const
Whether this object's apply() method can apply the transpose (or conjugate transpose,...
Definition Ifpack2_Details_Amesos2Wrapper_def.hpp:133
Ifpack2's implementation of Trilinos::Details::LinearSolver interface.
Definition Ifpack2_Details_LinearSolver_decl.hpp:75
void setParameters(const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Set the solver's parameters.
Definition Ifpack2_Details_LinearSolver_def.hpp:135
std::string description() const
Implementation of Teuchos::Describable::description.
Definition Ifpack2_Details_LinearSolver_def.hpp:168
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Implementation of Teuchos::Describable::describe.
Definition Ifpack2_Details_LinearSolver_def.hpp:178
void registerLinearSolverFactory()
Ifpack2 implementation details.
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40