44 #ifndef MULTIPREC_DRIVER_HPP
45 #define MULTIPREC_DRIVER_HPP
47 #include <Teuchos_TypeNameTraits.hpp>
48 #include <Teuchos_TimeMonitor.hpp>
49 #include <Teuchos_ParameterList.hpp>
50 #include <Teuchos_FancyOStream.hpp>
52 #include <Tpetra_Version.hpp>
53 #include <Tpetra_MatrixIO.hpp>
54 #include <Tpetra_RTI.hpp>
55 #include <Tpetra_CrsMatrix.hpp>
56 #include <Tpetra_Vector.hpp>
58 #include "MultiPrecCG.hpp"
60 template <
class MPStack>
61 class MultiPrecDriver {
64 Teuchos::RCP<Teuchos::FancyOStream> out;
65 Teuchos::RCP<Teuchos::ParameterList> params;
66 std::string matrixFile;
72 void run(Teuchos::ParameterList &myMachPL,
const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
const Teuchos::RCP<Node> &node)
80 using Teuchos::ParameterList;
81 using Teuchos::parameterList;
89 typedef typename MPStack::type S;
96 *out <<
"Running test with Node==" << Teuchos::typeName(*node) <<
" on rank " << comm->getRank() <<
"/" << comm->getSize() << std::endl;
100 RCP<const Map> rowMap = null;
101 RCP<ParameterList> fillParams = parameterList();
102 fillParams->set(
"Preserve Local Graph",
true);
104 Tpetra::Utils::readHBMatrix(matrixFile,comm,node,A,rowMap,fillParams);
105 rowMap = A->getRowMap();
109 RCP<ParameterList> db = Tpetra::Ext::initStackDB<MPStack>(*params,init);
114 auto x = Tpetra::createVector<S>(rowMap),
115 b = Tpetra::createVector<S>(rowMap);
120 auto bx = db->get<RCP<Vector>>(
"bx");
125 TpetraExamples::recursiveFPCG<MPStack,LO,GO,Node>(out,*db);
129 auto xhat = db->get<RCP<Vector>>(
"bx"),
130 bhat = Tpetra::createVector<S>(rowMap);
131 A->apply(*xhat,*bhat);
134 reductionGlob<ZeroOp<pair<S,S>>>(
135 [](S bhati, S bi){
return bi-bhati;},
136 [](S bhati, S bi){
return make_pair(bhati*bhati, bi*bi); },
137 make_pair_op<S,S>(plus<S>())) );
138 const S enrm = Teuchos::ScalarTraits<S>::squareroot(nrms.first),
139 bnrm = Teuchos::ScalarTraits<S>::squareroot(nrms.second);
141 *out <<
"|b - A*x|/|b|: " << enrm / bnrm << endl;
142 const double tolerance = db->get<
double>(
"tolerance");
143 if (MPStack::bottom) {
145 if (enrm / bnrm > 5*tolerance) testPassed =
false;
148 if (enrm / bnrm > tolerance) testPassed =
false;
157 auto bx = db->get<RCP<Vector>>(
"bx");
160 TpetraExamples::recursiveFPCGUnfused<MPStack,LO,GO,Node>(out,*db);
163 auto xhat = db->get<RCP<Vector>>(
"bx"),
164 bhat = Tpetra::createVector<S>(rowMap);
165 A->apply(*xhat,*bhat);
168 reductionGlob<ZeroOp<pair<S,S>>>(
169 [](S bhati, S bi){
return bi-bhati;},
170 [](S bhati, S bi){
return make_pair(bhati*bhati, bi*bi); },
171 make_pair_op<S,S>(plus<S>())) );
172 const S enrm = Teuchos::ScalarTraits<S>::squareroot(nrms.first),
173 bnrm = Teuchos::ScalarTraits<S>::squareroot(nrms.second);
175 *out <<
"|b - A*x|/|b|: " << enrm / bnrm << endl;
176 const double tolerance = db->get<
double>(
"tolerance");
177 if (MPStack::bottom) {
179 if (enrm / bnrm > 5*tolerance) testPassed =
false;
182 if (enrm / bnrm > tolerance) testPassed =
false;
188 Teuchos::TimeMonitor::summarize( *out );
192 #endif // MULTIPREC_DRIVER_HPP
Initialization for a database stack for the recursiveFPCG() algorithm, to be used with Tpetra::Ext::i...
Sparse matrix that presents a compressed sparse row interface.
pair_op< T1, T2, Op > make_pair_op(Op op)
Non-member constructor to create a pair_op.
void binary_transform(Vector< S1, LO, GO, Node > &vec_inout, const Vector< S2, LO, GO, Node > &vec_in2, OP op)
Transform values of vec_inout using vec_inout, vec_in2 and operator op.
Glob::RedOP::result_type binary_pre_transform_reduce(Vector< S1, LO, GO, Node > &vec_inout, const Vector< S2, LO, GO, Node > &vec_in2, Glob glob)
Transforms values of vec_inout while simultaneously performing a parallel reduction.
ReductionGlob< GOP, ROP, IOP > reductionGlob(GOP gop, ROP rop)
Non-member constructor to instantiate a type glob of a static identity functor and generation and red...
Describes a parallel distribution of objects over processes.
A distributed dense vector.
A static identity functor, providing a static method identity() that returns zero.