43 #ifndef IFPACK2_DETAILS_AMESOS2WRAPPER_DEF_HPP
44 #define IFPACK2_DETAILS_AMESOS2WRAPPER_DEF_HPP
46 #ifdef HAVE_IFPACK2_AMESOS2
48 #include "Ifpack2_LocalFilter.hpp"
66 template <
class MatrixType>
70 InitializeTime_ (0.0),
76 IsInitialized_ (false),
81 template <
class MatrixType>
85 template <
class MatrixType>
97 RCP<ParameterList> theList;
98 if (params.
name () ==
"Amesos2") {
99 theList =
rcp (
new ParameterList (params));
100 }
else if (params.
isSublist (
"Amesos2")) {
102 ParameterList subpl = params.
sublist (
"Amesos2");
103 theList =
rcp (
new ParameterList (subpl));
104 theList->setName (
"Amesos2");
106 SolverName_ = params.
get<std::string>(
"Amesos2 solver name");
112 true, std::runtime_error,
"The ParameterList passed to Amesos2 must be "
113 "called \"Amesos2\".");
118 if (solver_.is_null ()) {
119 parameterList_ = theList;
125 solver_->setParameters(theList);
129 template <
class MatrixType>
133 A_.
is_null (), std::runtime_error,
"Ifpack2::Amesos2Wrapper::getComm: "
134 "The matrix is null. Please call setMatrix() with a nonnull input "
135 "before calling this method.");
136 return A_->getComm ();
140 template <
class MatrixType>
147 template <
class MatrixType>
152 A_.
is_null (), std::runtime_error,
"Ifpack2::Amesos2Wrapper::getDomainMap: "
153 "The matrix is null. Please call setMatrix() with a nonnull input "
154 "before calling this method.");
155 return A_->getDomainMap ();
159 template <
class MatrixType>
164 A_.
is_null (), std::runtime_error,
"Ifpack2::Amesos2Wrapper::getRangeMap: "
165 "The matrix is null. Please call setMatrix() with a nonnull input "
166 "before calling this method.");
167 return A_->getRangeMap ();
171 template <
class MatrixType>
177 template <
class MatrixType>
179 return NumInitialize_;
183 template <
class MatrixType>
189 template <
class MatrixType>
195 template <
class MatrixType>
197 return InitializeTime_;
201 template<
class MatrixType>
207 template<
class MatrixType>
212 template<
class MatrixType>
219 IsInitialized_ =
false;
240 template<
class MatrixType>
246 using Teuchos::rcp_dynamic_cast;
247 using Teuchos::rcp_implicit_cast;
252 if (A->getRowMap ()->getComm ()->getSize () == 1 ||
253 A->getRowMap ()->isSameAs (* (A->getColMap ()))) {
260 RCP<const LocalFilter<row_matrix_type> > A_lf_r =
262 if (! A_lf_r.is_null ()) {
263 return rcp_implicit_cast<
const row_matrix_type> (A_lf_r);
269 return rcp (
new LocalFilter<row_matrix_type> (A));
274 template<
class MatrixType>
279 using Teuchos::rcp_const_cast;
280 using Teuchos::rcp_dynamic_cast;
286 const std::string timerName (
"Ifpack2::Amesos2Wrapper::initialize");
287 RCP<Time> timer = TimeMonitor::lookupCounter (timerName);
288 if (timer.is_null ()) {
289 timer = TimeMonitor::getNewCounter (timerName);
292 double startTime = timer->wallTime();
295 TimeMonitor timeMon (*timer);
299 A_.
is_null (), std::runtime_error,
"Ifpack2::Amesos2Wrapper::initialize: "
300 "The matrix to precondition is null. Please call setMatrix() with a "
301 "nonnull input before calling this method.");
304 IsInitialized_ =
false;
307 RCP<const row_matrix_type> A_local = makeLocalFilter (A_);
309 A_local.is_null (), std::logic_error,
"Ifpack2::AmesosWrapper::initialize: "
310 "makeLocalFilter returned null; it failed to compute A_local. "
311 "Please report this bug to the Ifpack2 developers.");
318 if (A_local_crs_.is_null ()) {
320 Array<size_t> entriesPerRow(numRows);
323 entriesPerRow[i] = A_local->getNumEntriesInLocalRow(i);
325 RCP<crs_matrix_type> A_local_crs_nc =
327 A_local->getColMap (),
330 typename crs_matrix_type::nonconst_local_inds_host_view_type indices(
"Indices",A_local->getLocalMaxNumRowEntries() );
331 typename crs_matrix_type::nonconst_values_host_view_type values(
"Values", A_local->getLocalMaxNumRowEntries());
334 size_t numEntries = 0;
335 A_local->getLocalRowCopy(i, indices, values, numEntries);
336 ArrayView<const local_ordinal_type> indicesInsert(indices.data(), numEntries);
337 ArrayView<const scalar_type> valuesInsert((
const scalar_type*)values.data(), numEntries);
338 A_local_crs_nc->insertLocalValues(i, indicesInsert, valuesInsert);
340 A_local_crs_nc->fillComplete (A_local->getDomainMap (), A_local->getRangeMap ());
354 Amesos2::Details::registerLinearSolverFactory ();
357 solver_ = Trilinos::Details::getLinearSolver<MV, OP, typename MV::mag_type> (
"Amesos2", SolverName_);
359 (solver_.is_null (), std::runtime_error,
"Ifpack2::Details::"
360 "Amesos2Wrapper::initialize: Failed to create Amesos2 solver!");
362 solver_->setMatrix (A_local_crs_);
364 if (parameterList_ != Teuchos::null) {
365 setParameters (*parameterList_);
366 parameterList_ = Teuchos::null;
371 solver_->symbolic ();
374 IsInitialized_ =
true;
377 InitializeTime_ += (timer->wallTime() - startTime);
380 template<
class MatrixType>
388 if (! isInitialized ()) {
392 const std::string timerName (
"Ifpack2::Details::Amesos2Wrapper::compute");
393 RCP<Time> timer = TimeMonitor::lookupCounter (timerName);
394 if (timer.is_null ()) {
395 timer = TimeMonitor::getNewCounter (timerName);
398 double startTime = timer->wallTime();
401 TimeMonitor timeMon (*timer);
408 ComputeTime_ += (timer->wallTime() - startTime);
412 template <
class MatrixType>
414 apply (
const Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& X,
415 Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>& Y,
423 using Teuchos::rcpFromRef;
430 const std::string timerName (
"Ifpack2::Amesos2Wrapper::apply");
431 RCP<Time> timer = TimeMonitor::lookupCounter (timerName);
432 if (timer.is_null ()) {
433 timer = TimeMonitor::getNewCounter (timerName);
436 double startTime = timer->wallTime();
439 TimeMonitor timeMon (*timer);
442 ! isComputed (), std::runtime_error,
443 "Ifpack2::Amesos2Wrapper::apply: You must call compute() to compute the "
444 "incomplete factorization, before calling apply().");
447 X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
448 "Ifpack2::Amesos2Wrapper::apply: X and Y must have the same number of columns. "
449 "X has " << X.getNumVectors () <<
" columns, but Y has "
450 << Y.getNumVectors () <<
" columns.");
454 "Ifpack2::Amesos2Wrapper::apply: Solving with the transpose (mode == "
455 "Teuchos::TRANS) or conjugate transpose (Teuchos::CONJ_TRANS) is not "
461 RCP<MV> Y_temp = (alpha != STS::one () || beta != STS::zero ()) ?
462 rcp (
new MV (Y.getMap (), Y.getNumVectors ())) :
468 RCP<const MV> X_temp;
473 X_temp = rcpFromRef (X);
478 RCP<const MV> X_local;
484 const bool multipleProcs = (A_->getRowMap ()->getComm ()->getSize () > 1) || (X.getMap ()->getComm ()->getSize () > 1);
489 X_local = X_temp->offsetView (A_local_crs_->getDomainMap (), 0);
490 Y_local = Y_temp->offsetViewNonConst (A_local_crs_->getRangeMap (), 0);
499 solver_->solve (*Y_local, *X_local);
501 if (alpha != STS::one () || beta != STS::zero ()) {
502 Y.update (alpha, *Y_temp, beta);
508 ApplyTime_ += (timer->wallTime() - startTime);
512 template <
class MatrixType>
515 std::ostringstream os;
520 os <<
"\"Ifpack2::Amesos2Wrapper\": {";
521 if (this->getObjectLabel () !=
"") {
522 os <<
"Label: \"" << this->getObjectLabel () <<
"\", ";
524 os <<
"Initialized: " << (isInitialized () ?
"true" :
"false")
525 <<
", Computed: " << (isComputed () ?
"true" :
"false");
527 if (A_local_crs_.is_null ()) {
528 os <<
", Matrix: null";
531 os <<
", Global matrix dimensions: ["
532 << A_local_crs_->getGlobalNumRows () <<
", " << A_local_crs_->getGlobalNumCols () <<
"]";
537 if (! solver_.is_null ()) {
550 template <
class MatrixType>
568 out <<
"\"Ifpack2::Amesos2Wrapper\":" << endl;
570 out <<
"MatrixType: \"" << TypeNameTraits<MatrixType>::name ()
573 if (this->getObjectLabel () !=
"") {
574 out <<
"Label: \"" << this->getObjectLabel () <<
"\"" << endl;
577 out <<
"Initialized: " << (isInitialized () ?
"true" :
"false") << endl;
578 out <<
"Computed: " << (isComputed () ?
"true" :
"false") << endl;
579 out <<
"Number of initialize calls: " << getNumInitialize () << endl;
580 out <<
"Number of compute calls: " << getNumCompute () << endl;
581 out <<
"Number of apply calls: " << getNumApply () << endl;
582 out <<
"Total time in seconds for initialize: " << getInitializeTime () << endl;
583 out <<
"Total time in seconds for compute: " << getComputeTime () << endl;
584 out <<
"Total time in seconds for apply: " << getApplyTime () << endl;
587 out <<
"Matrix:" << endl;
588 A_local_crs_->describe (out, vl);
600 #define IFPACK2_DETAILS_AMESOS2WRAPPER_INSTANT(S,LO,GO,N) \
601 template class Ifpack2::Details::Amesos2Wrapper< Tpetra::RowMatrix<S, LO, GO, N> >;
605 #define IFPACK2_DETAILS_AMESOS2WRAPPER_INSTANT(S,LO,GO,N)
607 #endif // HAVE_IFPACK2_AMESOS2
608 #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:196
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:208
basic_OSTab< char > OSTab
void setParameters(const Teuchos::ParameterList ¶ms)
Set parameters.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:86
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:172
#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:190
void initialize()
Compute the preordering and symbolic factorization of the matrix.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:275
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The input matrix's communicator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:131
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:553
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:178
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:117
Teuchos::RCP< const map_type > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:149
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:149
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:102
Teuchos::RCP< const map_type > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:161
bool isSublist(const std::string &name) const
virtual std::string description() const
virtual ~Amesos2Wrapper()
Destructor.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:82
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:120
Amesos2Wrapper(const Teuchos::RCP< const row_matrix_type > &A)
Constructor.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:68
Teuchos::RCP< const row_matrix_type > getMatrix() const
The input matrix; the matrix to be preconditioned.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:142
double getComputeTime() const
The total time in seconds spent in successful calls to compute().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:202
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:184
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:414
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:381
Access only local rows and columns of a sparse matrix.
Definition: Ifpack2_LocalFilter_decl.hpp:161
void registerLinearSolverFactory()
std::string description() const
A one-line description of this object.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:513
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:213