52 #include "Teuchos_CommandLineProcessor.hpp" 53 #include "Teuchos_ParameterList.hpp" 54 #include "Teuchos_StandardCatchMacros.hpp" 65 int main(
int argc,
char *argv[]) {
68 typedef std::complex<double> ST;
70 typedef std::complex<double> ST;
72 std::cout <<
"Not compiled with std::complex support." << std::endl;
73 std::cout <<
"End Result: TEST FAILED" << std::endl;
77 typedef ScalarTraits<ST> SCT;
78 typedef SCT::magnitudeType MT;
84 ST zero = SCT::zero();
86 Teuchos::GlobalMPISession session(&argc, &argv, NULL);
87 int MyPID = session.getRank();
95 bool norm_failure =
false;
96 bool proc_verbose =
false;
101 int maxrestarts = 15;
105 CommandLineProcessor cmdp(
false,
true);
106 cmdp.setOption(
"verbose",
"quiet",&verbose,
"Print messages and results.");
107 cmdp.setOption(
"pseudo",
"regular",&pseudo,
"Use pseudo-block TFQMR to solve the linear systems.");
108 cmdp.setOption(
"frequency",&frequency,
"Solvers frequency for printing residuals (#iters).");
109 cmdp.setOption(
"tol",&
tol,
"Relative residual tolerance used by TFQMR solver.");
110 cmdp.setOption(
"num-rhs",&numrhs,
"Number of right-hand sides to be solved for.");
111 cmdp.setOption(
"num-restarts",&maxrestarts,
"Maximum number of restarts allowed for the TFQMR solver.");
112 cmdp.setOption(
"blocksize",&blocksize,
"Block size used by TFQMR.");
113 cmdp.setOption(
"subspace-length",&length,
"Maximum dimension of block-subspace used by TFQMR solver.");
114 if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
118 proc_verbose = verbose && (MyPID==0);
125 #ifndef HAVE_BELOS_TRIUTILS 126 std::cout <<
"This test requires Triutils. Please configure with --enable-triutils." << std::endl;
128 std::cout <<
"End Result: TEST FAILED" << std::endl;
137 std::vector<ST> diag( dim, (ST)4.0 );
138 RCP< MyOperator<ST> > A
144 int maxits = dim/blocksize;
146 ParameterList belosList;
147 belosList.set(
"Num Blocks", length );
148 belosList.set(
"Block Size", blocksize );
149 belosList.set(
"Maximum Iterations", maxits );
150 belosList.set(
"Maximum Restarts", maxrestarts );
151 belosList.set(
"Convergence Tolerance",
tol );
156 belosList.set(
"Output Frequency", frequency );
165 RCP<MyMultiVec<ST> > soln = rcp(
new MyMultiVec<ST>(dim,numrhs) );
167 MVT::MvInit( *rhs, 1.0 );
168 MVT::MvInit( *soln, zero );
172 RCP<Belos::LinearProblem<ST,MV,OP> > problem =
174 bool set = problem->setProblem();
177 std::cout << std::endl <<
"ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
186 Teuchos::RCP< Belos::SolverManager<ST,MV,OP> > solver;
196 std::cout << std::endl << std::endl;
197 std::cout <<
"Dimension of matrix: " << dim << std::endl;
198 std::cout <<
"Number of right-hand sides: " << numrhs << std::endl;
199 std::cout <<
"Block size used by solver: " << blocksize << std::endl;
200 std::cout <<
"Max number of TFQMR iterations: " << maxits << std::endl;
201 std::cout <<
"Relative residual tolerance: " <<
tol << std::endl;
202 std::cout << std::endl;
211 RCP<MyMultiVec<ST> > temp = rcp(
new MyMultiVec<ST>(dim,numrhs) );
212 OPT::Apply( *A, *soln, *temp );
213 MVT::MvAddMv( one, *rhs, -one, *temp, *temp );
214 std::vector<MT> norm_num(numrhs), norm_denom(numrhs);
215 MVT::MvNorm( *temp, norm_num );
216 MVT::MvNorm( *rhs, norm_denom );
217 for (
int i=0; i<numrhs; ++i) {
219 std::cout <<
"Relative residual "<<i<<
" : " << norm_num[i] / norm_denom[i] << std::endl;
220 if ( norm_num[i] / norm_denom[i] >
tol ) {
228 std::cout <<
"End Result: TEST PASSED" << std::endl;
231 std::cout <<
"End Result: TEST FAILED" << std::endl;
234 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
236 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
std::string Belos_Version()
int main(int argc, char *argv[])
The Belos::PseudoBlockTFQMRSolMgr provides a solver manager for the pseudo-block TFQMR linear solver...
Traits class which defines basic operations on multivectors.
Simple example of a user's defined Belos::MultiVec class.
Alternative run-time polymorphic interface for operators.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
The Belos::PseudoBlockTFQMRSolMgr provides a powerful and fully-featured solver manager over the pseu...
ReturnType
Whether the Belos solve converged for all linear systems.
The Belos::TFQMRSolMgr provides a powerful and fully-featured solver manager over the TFQMR linear so...
Simple example of a user's defined Belos::Operator class.
Interface for multivectors used by Belos' linear solvers.
Class which defines basic traits for the operator type.
Belos header file which uses auto-configuration information to include necessary C++ headers...
The Belos::TFQMRSolMgr provides a solver manager for the TFQMR linear solver.