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)
47 template <
class MatrixType>
50 template <
class MatrixType>
61 RCP<ParameterList> theList;
62 if (params.
name() ==
"Amesos2") {
63 theList =
rcp(
new ParameterList(params));
66 ParameterList subpl = params.
sublist(
"Amesos2");
67 theList =
rcp(
new ParameterList(subpl));
68 theList->setName(
"Amesos2");
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()) {
84 parameterList_ = theList;
90 solver_->setParameters(theList);
93 template <
class MatrixType>
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();
104 template <
class MatrixType>
110 template <
class MatrixType>
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();
121 template <
class MatrixType>
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();
132 template <
class MatrixType>
137 template <
class MatrixType>
139 return NumInitialize_;
142 template <
class MatrixType>
147 template <
class MatrixType>
152 template <
class MatrixType>
154 return InitializeTime_;
157 template <
class MatrixType>
162 template <
class MatrixType>
167 template <
class MatrixType>
173 IsInitialized_ =
false;
193 template <
class MatrixType>
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 =
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));
224 template <
class MatrixType>
230 using Teuchos::rcp_const_cast;
231 using Teuchos::rcp_dynamic_cast;
235 const std::string timerName(
"Ifpack2::Amesos2Wrapper::initialize");
236 RCP<Time> timer = TimeMonitor::lookupCounter(timerName);
237 if (timer.is_null()) {
238 timer = TimeMonitor::getNewCounter(timerName);
241 double startTime = timer->wallTime();
244 TimeMonitor timeMon(*timer);
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;
257 RCP<const row_matrix_type> A_local = makeLocalFilter(A_);
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()) {
271 Array<size_t> entriesPerRow(numRows);
273 entriesPerRow[i] = A_local->getNumEntriesInLocalRow(i);
275 RCP<crs_matrix_type> A_local_crs_nc =
277 A_local->getColMap(),
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());
283 size_t numEntries = 0;
284 A_local->getLocalRowCopy(i, indices, values, numEntries);
285 ArrayView<const local_ordinal_type> indicesInsert(indices.data(), numEntries);
286 ArrayView<const scalar_type> valuesInsert((
const scalar_type*)values.data(), numEntries);
287 A_local_crs_nc->insertLocalValues(i, indicesInsert, valuesInsert);
289 A_local_crs_nc->fillComplete(A_local->getDomainMap(), A_local->getRangeMap());
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) {
313 setParameters(*parameterList_);
314 parameterList_ = Teuchos::null;
322 IsInitialized_ =
true;
325 InitializeTime_ += (timer->wallTime() - startTime);
328 template <
class MatrixType>
335 if (!isInitialized()) {
339 const std::string timerName(
"Ifpack2::Details::Amesos2Wrapper::compute");
340 RCP<Time> timer = TimeMonitor::lookupCounter(timerName);
341 if (timer.is_null()) {
342 timer = TimeMonitor::getNewCounter(timerName);
345 double startTime = timer->wallTime();
348 TimeMonitor timeMon(*timer);
355 ComputeTime_ += (timer->wallTime() - startTime);
358 template <
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,
368 using Teuchos::rcpFromRef;
375 const std::string timerName(
"Ifpack2::Amesos2Wrapper::apply");
376 RCP<Time> timer = TimeMonitor::lookupCounter(timerName);
377 if (timer.is_null()) {
378 timer = TimeMonitor::getNewCounter(timerName);
381 double startTime = timer->wallTime();
384 TimeMonitor timeMon(*timer);
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.");
400 "Ifpack2::Amesos2Wrapper::apply: Solving with the transpose (mode == "
401 "Teuchos::TRANS) or conjugate transpose (Teuchos::CONJ_TRANS) is not "
407 RCP<MV> Y_temp = (alpha != STS::one() || beta != STS::zero()) ?
rcp(
new MV(Y.getMap(), Y.getNumVectors())) : rcpFromRef(Y);
412 RCP<const MV> X_temp;
417 X_temp = rcpFromRef(X);
422 RCP<const MV> X_local;
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);
442 solver_->solve(*Y_local, *X_local);
444 if (alpha != STS::one() || beta != STS::zero()) {
445 Y.update(alpha, *Y_temp, beta);
451 ApplyTime_ += (timer->wallTime() - startTime);
454 template <
class MatrixType>
457 std::ostringstream os;
462 os <<
"\"Ifpack2::Amesos2Wrapper\": {";
463 if (this->getObjectLabel() !=
"") {
464 os <<
"Label: \"" << this->getObjectLabel() <<
"\", ";
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()) {
490 template <
class MatrixType>
505 out <<
"\"Ifpack2::Amesos2Wrapper\":" << endl;
507 out <<
"MatrixType: \"" << TypeNameTraits<MatrixType>::name()
510 if (this->getObjectLabel() !=
"") {
511 out <<
"Label: \"" << this->getObjectLabel() <<
"\"" << 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;
524 out <<
"Matrix:" << endl;
525 A_local_crs_->describe(out, vl);
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)
544 #endif // HAVE_IFPACK2_AMESOS2
545 #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:153
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:163
basic_OSTab< char > OSTab
void setParameters(const Teuchos::ParameterList ¶ms)
Set parameters.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:51
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:133
#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:148
void initialize()
Compute the preordering and symbolic factorization of the matrix.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:225
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The input matrix's communicator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:95
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
int getNumInitialize() const
The total number of successful calls to initialize().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:138
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:81
Teuchos::RCP< const map_type > getDomainMap() const
Tpetra::Map representing the domain of this operator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:112
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:68
Teuchos::RCP< const map_type > getRangeMap() const
Tpetra::Map representing the range of this operator.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:123
bool isSublist(const std::string &name) const
virtual std::string description() const
virtual ~Amesos2Wrapper()
Destructor.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:48
MatrixType::local_ordinal_type local_ordinal_type
The type of local indices in the input MatrixType.
Definition: Ifpack2_Details_Amesos2Wrapper_decl.hpp:84
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:106
double getComputeTime() const
The total time in seconds spent in successful calls to compute().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:158
int getNumCompute() const
The total number of successful calls to compute().
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:143
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
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:329
Access only local rows and columns of a sparse matrix.
Definition: Ifpack2_LocalFilter_decl.hpp:127
void registerLinearSolverFactory()
std::string description() const
A one-line description of this object.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:455
virtual void setMatrix(const Teuchos::RCP< const row_matrix_type > &A)
Change the matrix to be preconditioned.
Definition: Ifpack2_Details_Amesos2Wrapper_def.hpp:168