69int main(
int argc,
char *argv[]) {
71 typedef std::complex<double> ST;
72 typedef ScalarTraits<ST> SCT;
73 typedef SCT::magnitudeType MT;
79 ST zero = SCT::zero();
83 bool norm_failure =
false;
85 Teuchos::GlobalMPISession session(&argc, &argv, NULL);
93bool proc_verbose =
false;
97 std::string filename(
"mhd1280b.cua");
100 CommandLineProcessor cmdp(
false,
true);
101 cmdp.setOption(
"verbose",
"quiet",&verbose,
"Print messages and results.");
102 cmdp.setOption(
"frequency",&frequency,
"Solvers frequency for printing residuals (#iters).");
103 cmdp.setOption(
"filename",&filename,
"Filename for Harwell-Boeing test matrix.");
104 cmdp.setOption(
"tol",&tol,
"Relative residual tolerance used by MINRES solver.");
105 cmdp.setOption(
"num-rhs",&numrhs,
"Number of right-hand sides to be solved for.");
106 if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
110 proc_verbose = verbose && (MyPID==0);
118#ifndef HAVE_BELOS_TRIUTILS
119 std::cout <<
"This test requires Triutils. Please configure with --enable-triutils." << std::endl;
121 std::cout <<
"End Result: TEST FAILED" << std::endl;
132 info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,
133 &colptr,&rowind,&dvals);
134 if (info == 0 || nnz < 0) {
136 std::cout <<
"Error reading '" << filename <<
"'" << std::endl;
137 std::cout <<
"End Result: TEST FAILED" << std::endl;
143 for (
int ii=0; ii<nnz; ii++) {
144 cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
147 RCP< MyBetterOperator<ST> > A
153 int maxits = dim/blocksize;
155 ParameterList belosList;
156 belosList.set(
"Maximum Iterations", maxits );
157 belosList.set(
"Convergence Tolerance", tol );
162 belosList.set(
"Output Frequency", frequency );
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 );
179 RCP<Belos::LinearProblem<ST,MV,OP> > problem =
181 bool set = problem->setProblem();
184 std::cout << std::endl <<
"ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
198 std::cout << std::endl << std::endl;
199 std::cout <<
"Dimension of matrix: " << dim << std::endl;
200 std::cout <<
"Number of right-hand sides: " << numrhs << std::endl;
201 std::cout <<
"Block size used by solver: " << blocksize << std::endl;
202 std::cout <<
"Max number of MINRES iterations: " << maxits << std::endl;
203 std::cout <<
"Relative residual tolerance: " << tol << std::endl;
204 std::cout << std::endl;
213 RCP<MyMultiVec<ST> > temp = rcp(
new MyMultiVec<ST>(dim,numrhs) );
214 OPT::Apply( *A, *soln, *temp );
215 MVT::MvAddMv( one, *rhs, -one, *temp, *temp );
216 std::vector<MT> norm_num(numrhs), norm_denom(numrhs);
217 MVT::MvNorm( *temp, norm_num );
218 MVT::MvNorm( *rhs, norm_denom );
219 for (
int i=0; i<numrhs; ++i) {
221 std::cout <<
"Relative residual "<<i<<
" : " << norm_num[i] / norm_denom[i] << std::endl;
222 if ( norm_num[i] / norm_denom[i] > tol ) {
237 std::cout <<
"End Result: TEST PASSED" << std::endl;
240 std::cout <<
"End Result: TEST FAILED" << std::endl;
243TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
245return ( success ? EXIT_SUCCESS : EXIT_FAILURE );