51 #include "Teuchos_CommandLineProcessor.hpp" 52 #include "Teuchos_ParameterList.hpp" 53 #include "Teuchos_StandardCatchMacros.hpp" 60 #ifdef HAVE_BELOS_TRIUTILS 61 #include "Trilinos_Util_iohb.h" 70 int main(
int argc,
char *argv[]) {
73 typedef std::complex<double> ST;
75 typedef std::complex<double> ST;
77 std::cout <<
"Not compiled with std::complex support." << std::endl;
78 std::cout <<
"End Result: TEST FAILED" << std::endl;
82 typedef ScalarTraits<ST> SCT;
83 typedef SCT::magnitudeType MT;
89 ST zero = SCT::zero();
91 Teuchos::GlobalMPISession session(&argc, &argv, NULL);
101 bool norm_failure =
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 CG solver.");
114 cmdp.setOption(
"num-rhs",&numrhs,
"Number of right-hand sides to be solved for.");
115 cmdp.setOption(
"blocksize",&blocksize,
"Block size used by CG .");
116 if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) {
120 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;
142 info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,
143 &colptr,&rowind,&dvals);
144 if (info == 0 || nnz < 0) {
146 std::cout <<
"Error reading '" << filename <<
"'" << std::endl;
147 std::cout <<
"End Result: TEST FAILED" << std::endl;
153 for (
int ii=0; ii<nnz; ii++) {
154 cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
157 RCP< MyBetterOperator<ST> > A
163 int maxits = dim/blocksize;
165 ParameterList belosList;
166 belosList.set(
"Block Size", blocksize );
167 belosList.set(
"Maximum Iterations", maxits );
168 belosList.set(
"Convergence Tolerance", tol );
173 belosList.set(
"Output Frequency", frequency );
182 RCP<MyMultiVec<ST> > soln = rcp(
new MyMultiVec<ST>(dim,numrhs) );
184 MVT::MvRandom( *soln );
185 OPT::Apply( *A, *soln, *rhs );
186 MVT::MvInit( *soln, zero );
190 RCP<Belos::LinearProblem<ST,MV,OP> > problem =
192 bool set = problem->setProblem();
195 std::cout << std::endl <<
"ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
204 std::cout <<
"Attempt to create Belos::BlockCGSolMgr" << std::endl;
212 std::cout << std::endl << std::endl;
213 std::cout <<
"Dimension of matrix: " << dim << std::endl;
214 std::cout <<
"Number of right-hand sides: " << numrhs << std::endl;
215 std::cout <<
"Block size used by solver: " << blocksize << std::endl;
216 std::cout <<
"Max number of CG iterations: " << maxits << std::endl;
217 std::cout <<
"Relative residual tolerance: " << tol << std::endl;
218 std::cout << std::endl;
227 RCP<MyMultiVec<ST> > temp = rcp(
new MyMultiVec<ST>(dim,numrhs) );
228 OPT::Apply( *A, *soln, *temp );
229 MVT::MvAddMv( one, *rhs, -one, *temp, *temp );
230 std::vector<MT> norm_num(numrhs), norm_denom(numrhs);
231 MVT::MvNorm( *temp, norm_num );
232 MVT::MvNorm( *rhs, norm_denom );
233 for (
int i=0; i<numrhs; ++i) {
235 std::cout <<
"Relative residual "<<i<<
" : " << norm_num[i] / norm_denom[i] << std::endl;
236 if ( norm_num[i] / norm_denom[i] > tol ) {
242 MT ach_tol = solver.achievedTol();
244 std::cout <<
"Achieved tol : "<<ach_tol<<std::endl;
256 std::cout <<
"End Result: TEST PASSED" << std::endl;
259 std::cout <<
"End Result: TEST FAILED" << std::endl;
262 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
264 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
std::string Belos_Version()
int main(int argc, char *argv[])
The Belos::BlockCGSolMgr provides a powerful and fully-featured solver manager over the CG and BlockC...
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.
ReturnType
Whether the Belos solve converged for all linear systems.
The Belos::BlockCGSolMgr provides a solver manager for the BlockCG linear solver. ...
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...
Simple example of a user's defined Belos::Operator class.