51 #include "Teuchos_CommandLineProcessor.hpp" 52 #include "Teuchos_ParameterList.hpp" 59 #ifdef HAVE_BELOS_TRIUTILS 60 #include "Trilinos_Util_iohb.h" 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();
92 bool norm_failure =
false;
94 Teuchos::GlobalMPISession session(&argc, &argv, NULL);
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 MINRES 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);
127 #ifndef HAVE_BELOS_TRIUTILS 128 std::cout <<
"This test requires Triutils. Please configure with --enable-triutils." << std::endl;
130 std::cout <<
"End Result: TEST FAILED" << std::endl;
141 info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,
142 &colptr,&rowind,&dvals);
143 if (info == 0 || nnz < 0) {
145 std::cout <<
"Error reading '" << filename <<
"'" << std::endl;
146 std::cout <<
"End Result: TEST FAILED" << std::endl;
152 for (
int ii=0; ii<nnz; ii++) {
153 cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
156 RCP< MyBetterOperator<ST> > A
162 int maxits = dim/blocksize;
164 ParameterList belosList;
165 belosList.set(
"Maximum Iterations", maxits );
166 belosList.set(
"Convergence Tolerance", tol );
171 belosList.set(
"Output Frequency", frequency );
180 RCP<MyMultiVec<ST> > soln = rcp(
new MyMultiVec<ST>(dim,numrhs) );
182 MVT::MvRandom( *soln );
183 OPT::Apply( *A, *soln, *rhs );
184 MVT::MvInit( *soln, zero );
188 RCP<Belos::LinearProblem<ST,MV,OP> > problem =
190 bool set = problem->setProblem();
193 std::cout << std::endl <<
"ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
207 std::cout << std::endl << std::endl;
208 std::cout <<
"Dimension of matrix: " << dim << std::endl;
209 std::cout <<
"Number of right-hand sides: " << numrhs << std::endl;
210 std::cout <<
"Block size used by solver: " << blocksize << std::endl;
211 std::cout <<
"Max number of MINRES iterations: " << maxits << std::endl;
212 std::cout <<
"Relative residual tolerance: " << tol << std::endl;
213 std::cout << std::endl;
222 RCP<MyMultiVec<ST> > temp = rcp(
new MyMultiVec<ST>(dim,numrhs) );
223 OPT::Apply( *A, *soln, *temp );
224 MVT::MvAddMv( one, *rhs, -one, *temp, *temp );
225 std::vector<MT> norm_num(numrhs), norm_denom(numrhs);
226 MVT::MvNorm( *temp, norm_num );
227 MVT::MvNorm( *rhs, norm_denom );
228 for (
int i=0; i<numrhs; ++i) {
230 std::cout <<
"Relative residual "<<i<<
" : " << norm_num[i] / norm_denom[i] << std::endl;
231 if ( norm_num[i] / norm_denom[i] > tol ) {
246 std::cout <<
"End Result: TEST PASSED" << std::endl;
249 std::cout <<
"End Result: TEST FAILED" << std::endl;
252 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
254 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
Solver manager for the MINRES linear solver.
std::string Belos_Version()
int main(int argc, char *argv[])
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.
MINRES linear solver solution manager.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
ReturnType
Whether the Belos solve converged for all linear systems.
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...
ReturnType solve() override
Iterate until the status test tells us to stop.
Simple example of a user's defined Belos::Operator class.