51 #include "Teuchos_CommandLineProcessor.hpp"
52 #include "Teuchos_ParameterList.hpp"
59 #ifdef HAVE_BELOS_TRIUTILS
60 #include "Trilinos_Util_iohb.h"
67 using namespace Teuchos;
69 int main(
int argc,
char *argv[]) {
72 typedef std::complex<double> ST;
74 typedef std::complex<double> ST;
76 std::cout <<
"Not compiled with std::complex support." << std::endl;
77 std::cout <<
"End Result: TEST FAILED" << std::endl;
81 typedef ScalarTraits<ST> SCT;
82 typedef SCT::magnitudeType MT;
88 ST zero = SCT::zero();
91 bool norm_failure =
false;
93 Teuchos::GlobalMPISession session(&argc, &argv, NULL);
94 int MyPID = session.getRank();
100 bool verbose =
false;
102 bool proc_verbose =
false;
106 std::string filename(
"mhd1280b.cua");
109 CommandLineProcessor cmdp(
false,
true);
110 cmdp.setOption(
"verbose",
"quiet",&verbose,
"Print messages and results.");
111 cmdp.setOption(
"frequency",&frequency,
"Solvers frequency for printing residuals (#iters).");
112 cmdp.setOption(
"filename",&filename,
"Filename for Harwell-Boeing test matrix.");
113 cmdp.setOption(
"tol",&tol,
"Relative residual tolerance used by GCRODR solver.");
114 cmdp.setOption(
"num-rhs",&numrhs,
"Number of right-hand sides to be solved for.");
115 if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
119 proc_verbose = verbose && (MyPID==0);
126 #ifndef HAVE_BELOS_TRIUTILS
127 std::cout <<
"This test requires Triutils. Please configure with --enable-triutils." << std::endl;
129 std::cout <<
"End Result: TEST FAILED" << std::endl;
139 info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,
140 &colptr,&rowind,&dvals);
141 if (info == 0 || nnz < 0) {
143 std::cout <<
"Error reading '" << filename <<
"'" << std::endl;
144 std::cout <<
"End Result: TEST FAILED" << std::endl;
150 for (
int ii=0; ii<nnz; ii++) {
151 cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
154 RCP< MyBetterOperator<ST> > A
158 int maxits = dim/blocksize;
160 int numRecycledBlocks = 80;
161 int numIters1, numIters2, numIters3;
162 ParameterList belosList;
163 belosList.set(
"Maximum Iterations", maxits );
164 belosList.set(
"Convergence Tolerance", tol );
166 belosList.set(
"Num Blocks", numBlocks );
167 belosList.set(
"Num Recycled Blocks", numRecycledBlocks );
171 RCP<MyMultiVec<ST> > soln = rcp(
new MyMultiVec<ST>(dim,numrhs) );
173 MVT::MvRandom( *soln );
174 OPT::Apply( *A, *soln, *rhs );
175 MVT::MvInit( *soln, zero );
177 RCP<Belos::LinearProblem<ST,MV,OP> > problem =
179 bool set = problem->setProblem();
182 std::cout << std::endl <<
"ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
191 std::cout << std::endl << std::endl;
192 std::cout <<
"Dimension of matrix: " << dim << std::endl;
193 std::cout <<
"Number of right-hand sides: " << numrhs << std::endl;
194 std::cout <<
"Block size used by solver: " << blocksize << std::endl;
195 std::cout <<
"Max number of GCRODR iterations: " << maxits << std::endl;
196 std::cout <<
"Relative residual tolerance: " << tol << std::endl;
197 std::cout << std::endl;
202 numIters1=solver.getNumIters();
204 RCP<MyMultiVec<ST> > temp = rcp(
new MyMultiVec<ST>(dim,numrhs) );
205 std::vector<MT> norm_num(numrhs), norm_denom(numrhs);
206 OPT::Apply( *A, *soln, *temp );
207 MVT::MvAddMv( one, *rhs, -one, *temp, *temp );
208 MVT::MvNorm( *temp, norm_num );
209 MVT::MvNorm( *rhs, norm_denom );
210 for (
int i=0; i<numrhs; ++i) {
212 std::cout <<
"Relative residual "<<i<<
" : " << norm_num[i] / norm_denom[i] << std::endl;
213 if ( norm_num[i] / norm_denom[i] > tol ) {
218 MVT::MvRandom( *soln );
219 OPT::Apply( *A, *soln, *rhs );
220 MVT::MvInit( *soln, zero );
222 ret = solver.solve();
223 numIters2=solver.getNumIters();
225 MVT::MvRandom( *soln );
226 OPT::Apply( *A, *soln, *rhs );
227 MVT::MvInit( *soln, zero );
229 ret = solver.solve();
230 numIters3=solver.getNumIters();
237 if ( ret!=
Belos::Converged || norm_failure || numIters1 < numIters2 || numIters1 < numIters3 ) {
240 std::cout <<
"End Result: TEST FAILED" << std::endl;
244 std::cout <<
"End Result: TEST PASSED" << std::endl;
247 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
249 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );