53 #include "Teuchos_CommandLineProcessor.hpp" 54 #include "Teuchos_ParameterList.hpp" 55 #include "Teuchos_StandardCatchMacros.hpp" 66 int main(
int argc,
char *argv[]) {
69 typedef std::complex<double> ST;
71 typedef std::complex<double> ST;
73 std::cout <<
"Not compiled with std::complex support." << std::endl;
74 std::cout <<
"End Result: TEST FAILED" << std::endl;
78 typedef ScalarTraits<ST> SCT;
79 typedef SCT::magnitudeType MT;
85 ST zero = SCT::zero();
87 Teuchos::GlobalMPISession session(&argc, &argv, NULL);
88 int MyPID = session.getRank();
96 bool norm_failure =
false;
97 bool proc_verbose =
false;
102 int maxrestarts = 15;
104 std::string ortho(
"DGKS");
107 CommandLineProcessor cmdp(
false,
true);
108 cmdp.setOption(
"verbose",
"quiet",&verbose,
"Print messages and results.");
109 cmdp.setOption(
"pseudo",
"regular",&pseudo,
"Use pseudo-block GMRES to solve the linear systems.");
110 cmdp.setOption(
"frequency",&frequency,
"Solvers frequency for printing residuals (#iters).");
111 cmdp.setOption(
"tol",&
tol,
"Relative residual tolerance used by GMRES solver.");
112 cmdp.setOption(
"num-rhs",&numrhs,
"Number of right-hand sides to be solved for.");
113 cmdp.setOption(
"num-restarts",&maxrestarts,
"Maximum number of restarts allowed for the GMRES solver.");
114 cmdp.setOption(
"blocksize",&blocksize,
"Block size used by GMRES.");
115 cmdp.setOption(
"subspace-length",&length,
"Maximum dimension of block-subspace used by GMRES solver.");
116 cmdp.setOption(
"ortho-type",&ortho,
"Orthogonalization type, either DGKS, ICGS or IMGS");
117 if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
121 proc_verbose = verbose && (MyPID==0);
128 #ifndef HAVE_BELOS_TRIUTILS 129 std::cout <<
"This test requires Triutils. Please configure with --enable-triutils." << std::endl;
131 std::cout <<
"End Result: TEST FAILED" << std::endl;
140 std::vector<ST> diag( dim, (ST)4.0 );
141 RCP< MyOperator<ST> > A
147 int maxits = dim/blocksize;
149 ParameterList belosList;
150 belosList.set(
"Num Blocks", length );
151 belosList.set(
"Block Size", blocksize );
152 belosList.set(
"Maximum Iterations", maxits );
153 belosList.set(
"Maximum Restarts", maxrestarts );
154 belosList.set(
"Convergence Tolerance",
tol );
155 belosList.set(
"Orthogonalization", ortho );
160 belosList.set(
"Output Frequency", frequency );
169 RCP<MyMultiVec<ST> > soln = rcp(
new MyMultiVec<ST>(dim,numrhs) );
171 MVT::MvInit( *rhs, 1.0 );
172 MVT::MvInit( *soln, zero );
176 RCP<Belos::LinearProblem<ST,MV,OP> > problem =
178 bool set = problem->setProblem();
181 std::cout << std::endl <<
"ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
194 Teuchos::RCP< Belos::SolverManager<ST,MV,OP> > solver;
200 solver->setDebugStatusTest( Teuchos::rcp(&debugTest,
false) );
206 std::cout << std::endl << std::endl;
207 std::cout <<
"Dimension of matrix: " << dim << std::endl;
208 std::cout <<
"Number of right-hand sides: " << numrhs << std::endl;
209 std::cout <<
"Block size used by solver: " << blocksize << std::endl;
210 std::cout <<
"Max number of Gmres iterations: " << maxits << std::endl;
211 std::cout <<
"Relative residual tolerance: " <<
tol << std::endl;
212 std::cout << std::endl;
221 RCP<MyMultiVec<ST> > temp = rcp(
new MyMultiVec<ST>(dim,numrhs) );
222 OPT::Apply( *A, *soln, *temp );
223 MVT::MvAddMv( one, *rhs, -one, *temp, *temp );
224 std::vector<MT> norm_num(numrhs), norm_denom(numrhs);
225 MVT::MvNorm( *temp, norm_num );
226 MVT::MvNorm( *rhs, norm_denom );
227 for (
int i=0; i<numrhs; ++i) {
229 std::cout <<
"Relative residual "<<i<<
" : " << norm_num[i] / norm_denom[i] << std::endl;
230 if ( norm_num[i] / norm_denom[i] >
tol ) {
236 const std::vector<MT> residualLog = debugTest.
getLogResNorm();
237 if (numrhs==1 && proc_verbose && residualLog.size())
239 std::cout <<
"Absolute residual 2-norm [ " << residualLog.size() <<
" ] : ";
240 for (
unsigned int i=0; i<residualLog.size(); i++)
241 std::cout << residualLog[i] <<
" ";
242 std::cout << std::endl;
243 std::cout <<
"Final abs 2-norm / rhs 2-norm : " << residualLog[residualLog.size()-1] / norm_denom[0] << std::endl;
249 std::cout <<
"End Result: TEST PASSED" << std::endl;
252 std::cout <<
"End Result: TEST FAILED" << std::endl;
255 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
257 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
std::string Belos_Version()
A Belos::StatusTest debugging class for storing the absolute residual norms generated during a solve...
Interface to Block GMRES and Flexible GMRES.
Belos::StatusTest debugging class for storing the absolute residual norms generated during a solve...
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.
The Belos::BlockGmresSolMgr provides a solver manager for the BlockGmres linear solver.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
Interface to standard and "pseudoblock" GMRES.
ReturnType
Whether the Belos solve converged for all linear systems.
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.
The Belos::PseudoBlockGmresSolMgr provides a solver manager for the BlockGmres linear solver...
int main(int argc, char *argv[])
const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > & getLogResNorm() const
Returns the log of the absolute residual norm from the iteration.
Belos header file which uses auto-configuration information to include necessary C++ headers...