10 #ifndef IFPACK2_DETAILS_AMESOS2WRAPPER_DEF_HPP
11 #define IFPACK2_DETAILS_AMESOS2WRAPPER_DEF_HPP
13 #ifdef HAVE_IFPACK2_AMESOS2
15 #include "Ifpack2_LocalFilter.hpp"
33 template <
class MatrixType>
37 InitializeTime_ (0.0),
43 IsInitialized_ (false),
48 template <
class MatrixType>
52 template <
class MatrixType>
64 RCP<ParameterList> theList;
65 if (params.
name () ==
"Amesos2") {
66 theList =
rcp (
new ParameterList (params));
67 }
else if (params.
isSublist (
"Amesos2")) {
69 ParameterList subpl = params.
sublist (
"Amesos2");
70 theList =
rcp (
new ParameterList (subpl));
71 theList->setName (
"Amesos2");
73 SolverName_ = params.
get<std::string>(
"Amesos2 solver name");
79 true, std::runtime_error,
"The ParameterList passed to Amesos2 must be "
80 "called \"Amesos2\".");
85 if (solver_.is_null ()) {
86 parameterList_ = theList;
92 solver_->setParameters(theList);
96 template <
class MatrixType>
100 A_.
is_null (), std::runtime_error,
"Ifpack2::Amesos2Wrapper::getComm: "
101 "The matrix is null. Please call setMatrix() with a nonnull input "
102 "before calling this method.");
103 return A_->getComm ();
107 template <
class MatrixType>
114 template <
class MatrixType>
119 A_.
is_null (), std::runtime_error,
"Ifpack2::Amesos2Wrapper::getDomainMap: "
120 "The matrix is null. Please call setMatrix() with a nonnull input "
121 "before calling this method.");
122 return A_->getDomainMap ();
126 template <
class MatrixType>
131 A_.
is_null (), std::runtime_error,
"Ifpack2::Amesos2Wrapper::getRangeMap: "
132 "The matrix is null. Please call setMatrix() with a nonnull input "
133 "before calling this method.");
134 return A_->getRangeMap ();
138 template <
class MatrixType>
144 template <
class MatrixType>
146 return NumInitialize_;
150 template <
class MatrixType>
156 template <
class MatrixType>
162 template <
class MatrixType>
164 return InitializeTime_;
168 template<
class MatrixType>
174 template<
class MatrixType>
179 template<
class MatrixType>
186 IsInitialized_ =
false;
207 template<
class MatrixType>
213 using Teuchos::rcp_dynamic_cast;
214 using Teuchos::rcp_implicit_cast;
219 if (A->getRowMap ()->getComm ()->getSize () == 1 ||
220 A->getRowMap ()->isSameAs (* (A->getColMap ()))) {
227 RCP<const LocalFilter<row_matrix_type> > A_lf_r =
229 if (! A_lf_r.is_null ()) {
230 return rcp_implicit_cast<
const row_matrix_type> (A_lf_r);
236 return rcp (
new LocalFilter<row_matrix_type> (A));
241 template<
class MatrixType>
246 using Teuchos::rcp_const_cast;
247 using Teuchos::rcp_dynamic_cast;
253 const std::string timerName (
"Ifpack2::Amesos2Wrapper::initialize");
254 RCP<Time> timer = TimeMonitor::lookupCounter (timerName);
255 if (timer.is_null ()) {
256 timer = TimeMonitor::getNewCounter (timerName);
259 double startTime = timer->wallTime();
262 TimeMonitor timeMon (*timer);
266 A_.
is_null (), std::runtime_error,
"Ifpack2::Amesos2Wrapper::initialize: "
267 "The matrix to precondition is null. Please call setMatrix() with a "
268 "nonnull input before calling this method.");
271 IsInitialized_ =
false;
274 RCP<const row_matrix_type> A_local = makeLocalFilter (A_);
276 A_local.is_null (), std::logic_error,
"Ifpack2::AmesosWrapper::initialize: "
277 "makeLocalFilter returned null; it failed to compute A_local. "
278 "Please report this bug to the Ifpack2 developers.");
285 if (A_local_crs_.is_null ()) {
287 Array<size_t> entriesPerRow(numRows);
290 entriesPerRow[i] = A_local->getNumEntriesInLocalRow(i);
292 RCP<crs_matrix_type> A_local_crs_nc =
294 A_local->getColMap (),
297 typename crs_matrix_type::nonconst_local_inds_host_view_type indices(
"Indices",A_local->getLocalMaxNumRowEntries() );
298 typename crs_matrix_type::nonconst_values_host_view_type values(
"Values", A_local->getLocalMaxNumRowEntries());
301 size_t numEntries = 0;
302 A_local->getLocalRowCopy(i, indices, values, numEntries);
303 ArrayView<const local_ordinal_type> indicesInsert(indices.data(), numEntries);
304 ArrayView<const scalar_type> valuesInsert((
const scalar_type*)values.data(), numEntries);
305 A_local_crs_nc->insertLocalValues(i, indicesInsert, valuesInsert);
307 A_local_crs_nc->fillComplete (A_local->getDomainMap (), A_local->getRangeMap ());
321 Amesos2::Details::registerLinearSolverFactory ();
324 solver_ = Trilinos::Details::getLinearSolver<MV, OP, typename MV::mag_type> (
"Amesos2", SolverName_);
326 (solver_.is_null (), std::runtime_error,
"Ifpack2::Details::"
327 "Amesos2Wrapper::initialize: Failed to create Amesos2 solver!");
329 solver_->setMatrix (A_local_crs_);
331 if (parameterList_ != Teuchos::null) {
332 setParameters (*parameterList_);
333 parameterList_ = Teuchos::null;
338 solver_->symbolic ();
341 IsInitialized_ =
true;
344 InitializeTime_ += (timer->wallTime() - startTime);
347 template<
class MatrixType>
355 if (! isInitialized ()) {
359 const std::string timerName (
"Ifpack2::Details::Amesos2Wrapper::compute");
360 RCP<Time> timer = TimeMonitor::lookupCounter (timerName);
361 if (timer.is_null ()) {
362 timer = TimeMonitor::getNewCounter (timerName);
365 double startTime = timer->wallTime();
368 TimeMonitor timeMon (*timer);
375 ComputeTime_ += (timer->wallTime() - startTime);
379 template <
class MatrixType>
381 apply (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
382 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
390 using Teuchos::rcpFromRef;
397 const std::string timerName (
"Ifpack2::Amesos2Wrapper::apply");
398 RCP<Time> timer = TimeMonitor::lookupCounter (timerName);
399 if (timer.is_null ()) {
400 timer = TimeMonitor::getNewCounter (timerName);
403 double startTime = timer->wallTime();
406 TimeMonitor timeMon (*timer);
409 ! isComputed (), std::runtime_error,
410 "Ifpack2::Amesos2Wrapper::apply: You must call compute() to compute the "
411 "incomplete factorization, before calling apply().");
414 X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
415 "Ifpack2::Amesos2Wrapper::apply: X and Y must have the same number of columns. "
416 "X has " << X.getNumVectors () <<
" columns, but Y has "
417 << Y.getNumVectors () <<
" columns.");
421 "Ifpack2::Amesos2Wrapper::apply: Solving with the transpose (mode == "
422 "Teuchos::TRANS) or conjugate transpose (Teuchos::CONJ_TRANS) is not "
428 RCP<MV> Y_temp = (alpha != STS::one () || beta != STS::zero ()) ?
429 rcp (
new MV (Y.getMap (), Y.getNumVectors ())) :
435 RCP<const MV> X_temp;
440 X_temp = rcpFromRef (X);
445 RCP<const MV> X_local;
451 const bool multipleProcs = (A_->getRowMap ()->getComm ()->getSize () > 1) || (X.getMap ()->getComm ()->getSize () > 1);
456 X_local = X_temp->offsetView (A_local_crs_->getDomainMap (), 0);
457 Y_local = Y_temp->offsetViewNonConst (A_local_crs_->getRangeMap (), 0);
466 solver_->solve (*Y_local, *X_local);
468 if (alpha != STS::one () || beta != STS::zero ()) {
469 Y.update (alpha, *Y_temp, beta);
475 ApplyTime_ += (timer->wallTime() - startTime);
479 template <
class MatrixType>
482 std::ostringstream os;
487 os <<
"\"Ifpack2::Amesos2Wrapper\": {";
488 if (this->getObjectLabel () !=
"") {
489 os <<
"Label: \"" << this->getObjectLabel () <<
"\", ";
491 os <<
"Initialized: " << (isInitialized () ?
"true" :
"false")
492 <<
", Computed: " << (isComputed () ?
"true" :
"false");
494 if (A_local_crs_.is_null ()) {
495 os <<
", Matrix: null";
498 os <<
", Global matrix dimensions: ["
499 << A_local_crs_->getGlobalNumRows () <<
", " << A_local_crs_->getGlobalNumCols () <<
"]";
504 if (! solver_.is_null ()) {
517 template <
class MatrixType>
535 out <<
"\"Ifpack2::Amesos2Wrapper\":" << endl;
537 out <<
"MatrixType: \"" << TypeNameTraits<MatrixType>::name ()
540 if (this->getObjectLabel () !=
"") {
541 out <<
"Label: \"" << this->getObjectLabel () <<
"\"" << endl;
544 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") << endl;
545 out <<
"Computed: " << (isComputed () ?
"true" :
"false") << endl;
546 out <<
"Number of initialize calls: " << getNumInitialize () << endl;
547 out <<
"Number of compute calls: " << getNumCompute () << endl;
548 out <<
"Number of apply calls: " << getNumApply () << endl;
549 out <<
"Total time in seconds for initialize: " << getInitializeTime () << endl;
550 out <<
"Total time in seconds for compute: " << getComputeTime () << endl;
551 out <<
"Total time in seconds for apply: " << getApplyTime () << endl;
554 out <<
"Matrix:" << endl;
555 A_local_crs_->describe (out, vl);
567 #define IFPACK2_DETAILS_AMESOS2WRAPPER_INSTANT(S,LO,GO,N) \
568 template class Ifpack2::Details::Amesos2Wrapper< Tpetra::RowMatrix<S, LO, GO, N> >;
572 #define IFPACK2_DETAILS_AMESOS2WRAPPER_INSTANT(S,LO,GO,N)
574 #endif // HAVE_IFPACK2_AMESOS2
575 #endif // IFPACK2_DETAILS_AMESOS2WRAPPER_DEF_HPP
double getInitializeTime() const
The total time in seconds spent in successful calls to initialize().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:163
const std::string & name() const
double getApplyTime() const
The total time in seconds spent in successful calls to apply().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:175
basic_OSTab< char > OSTab
void setParameters(const Teuchos::ParameterList ¶ms)
Set parameters.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:53
T & get(const std::string &name, T def_value)
bool rememberRegisteredSomeLinearSolverFactory(const std::string &packageName)
bool hasTransposeApply() const
Whether this object's apply() method can apply the transpose (or conjugate transpose, if applicable).
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:139
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int getNumApply() const
The total number of successful calls to apply().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:157
void initialize()
Compute the preordering and symbolic factorization of the matrix.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:242
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The input matrix's communicator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:98
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:520
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:145
bool isParameter(const std::string &name) const
MatrixType::scalar_type scalar_type
The type of the entries of the input MatrixType.
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:84
Teuchos::RCP< const map_type > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:116
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_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Wrapper class for direct solvers in Amesos2.
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:69
Teuchos::RCP< const map_type > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:128
bool isSublist(const std::string &name) const
virtual std::string description() const
virtual ~Amesos2Wrapper()
Destructor.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:49
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:87
Amesos2Wrapper(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:35
Teuchos::RCP< const row_matrix_type > getMatrix() const
The input matrix; the matrix to be preconditioned.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:109
double getComputeTime() const
The total time in seconds spent in successful calls to compute().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:169
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:151
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:381
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void compute()
Compute the numeric factorization of the matrix.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:348
Access only local rows and columns of a sparse matrix.
Definition: Ifpack2_LocalFilter_decl.hpp:128
void registerLinearSolverFactory()
std::string description() const
A one-line description of this object.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:480
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:180