12 #include "Tpetra_CrsMatrix.hpp"
13 #include "Thyra_Ifpack2PreconditionerFactory.hpp"
20 typedef map_type::local_ordinal_type
LO;
21 typedef map_type::global_ordinal_type
GO;
24 typedef Tpetra::Operator<ST, LO, GO>
op_type;
30 const Tpetra::global_size_t numGlobalElements = 100;
32 const GO indexBase = 0;
33 auto map =
rcp (
new map_type (numGlobalElements, indexBase, comm));
35 const LO numMyElements = map->getLocalNumElements ();
36 auto myGlobalElements = map->getLocalElementList ();
39 for (
LO lclRow = 0; lclRow < numMyElements; ++lclRow) {
40 const GO gblInd = map->getGlobalElement (lclRow);
41 const ST val =
static_cast<ST> (1.0) /
static_cast<ST> (gblInd + 1);
42 A->insertGlobalValues (gblInd,
43 Teuchos::tuple (gblInd),
44 Teuchos::tuple (val));
51 main (
int argc,
char *argv[])
53 using Teuchos::outArg;
55 using Teuchos::reduceAll;
62 auto out = Teuchos::VerboseObjectBase::getDefaultOStream ();
64 const int myRank = comm->getRank ();
66 *out <<
"Creating matrix" << endl;
71 catch (std::exception& e) {
73 std::ostringstream os;
74 os <<
"Proc " << myRank <<
": create_matrix(comm) threw an "
75 "exception: " << e.what () << endl;
80 std::ostringstream os;
81 os <<
"Proc " << myRank <<
": create_matrix(comm) threw an "
82 "exception not a subclass of std::exception." << endl;
86 reduceAll<int, int> (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
87 if (gblSuccess != 1) {
89 *out <<
"create_matrix(comm) threw an exception on some process."
92 *out <<
"End Result: TEST FAILED" << endl;
101 reduceAll<int, int> (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
102 if (gblSuccess != 1) {
104 *out <<
"The result of create_matrix(comm) is null on at least one "
107 *out <<
"End Result: TEST FAILED" << endl;
111 *out <<
"Creating vectors" << endl;
117 *out <<
"Creating Stratimikos linear solver builder" << endl;
123 catch (std::exception& e) {
125 std::ostringstream os;
126 os <<
"Proc " << myRank <<
": builder.setParameterList(p) threw an "
127 "exception: " << e.what () << endl;
132 std::ostringstream os;
133 os <<
"Proc " << myRank <<
": builder.setParameterList(p) threw an "
134 "exception not a subclass of std::exception." << endl;
138 reduceAll<int, int> (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
139 if (gblSuccess != 1) {
141 *out <<
"builder.setParameterList(p) threw an exception on some process."
144 *out <<
"End Result: TEST FAILED" << endl;
148 *out <<
"Calling builder.createLinearSolveStrategy" << endl;
152 *out <<
"Calling Thyra::createConstLinearOp" << endl;
160 if (thyraA.is_null ()) {
164 reduceAll<int, int> (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
165 if (gblSuccess != 1) {
167 *out <<
"The result of Thyra::createConstLinearOp is null on at least "
168 "one process." << endl;
170 *out <<
"End Result: TEST FAILED" << endl;
174 *out <<
"Creating Thyra Ifpack2 factory" << endl;
176 rcp (
new Thyra::Ifpack2PreconditionerFactory<crs_matrix_type> ());
178 *out <<
"Creating Ifpack2 preconditioner using factory" << endl;
179 typedef Thyra::PreconditionerBase<ST> prec_type;
182 prec = factory->createPrec ();
184 catch (std::exception& e) {
186 std::ostringstream os;
187 os <<
"Proc " << myRank <<
": factory->createPrec() threw an "
188 "exception: " << e.what () << endl;
193 std::ostringstream os;
194 os <<
"Proc " << myRank <<
": factory->createPrec() threw an "
195 "exception not a subclass of std::exception." << endl;
199 reduceAll<int, int> (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
200 if (gblSuccess != 1) {
202 *out <<
"factory->createPrec() threw an exception on some process."
205 *out <<
"End Result: TEST FAILED" << endl;
214 reduceAll<int, int> (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
215 if (gblSuccess != 1) {
217 *out <<
"The result of factory->createPrec() is null on at least one "
220 *out <<
"End Result: TEST FAILED" << endl;
224 Thyra::initializePrec (*factory, thyraA, prec.
ptr ());
230 *out <<
"End Result: TEST PASSED" << endl;
int main(int argc, char *argv[])
Tpetra::Map< int, int > map_type
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
RCP< const LinearOpBase< Scalar > > createConstLinearOp(const RCP< const Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraOperator, const RCP< const VectorSpaceBase< Scalar > > rangeSpace=Teuchos::null, const RCP< const VectorSpaceBase< Scalar > > domainSpace=Teuchos::null)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setParameterList(RCP< ParameterList > const ¶mList)
bool is_null(const RCP< T > &p)
Tpetra::Vector< ST, LO, GO > vec_type
Teuchos::RCP< const crs_matrix_type > create_matrix(const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Tpetra::CrsMatrix< ST, LO, GO > crs_matrix_type
RCP< Thyra::LinearOpWithSolveFactoryBase< Scalar > > createLinearSolveStrategy(const std::string &linearSolveStrategyName) const
Concrete subclass of Thyra::LinearSolverBuilderBase for creating Thyra::LinearOpWithSolveFactoryBase ...
Tpetra::Operator< ST, LO, GO > op_type
map_type::local_ordinal_type LO
map_type::global_ordinal_type GO