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;
82 typedef SCT::magnitudeType MT;
88 ST zero = SCT::zero();
91 bool norm_failure =
false;
100 bool verbose =
false;
102 bool proc_verbose =
false;
106 std::string
filename(
"mhd1280b.cua");
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.");
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]);
158 int maxits = dim/blocksize;
160 int numRecycledBlocks = 20;
161 int numIters1, numIters2, numIters3;
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 );
173 MVT::MvRandom( *soln );
174 OPT::Apply( *A, *soln, *rhs );
175 MVT::MvInit( *soln, zero );
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();
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::MvInit( *soln, zero );
220 ret = solver.solve();
221 numIters2=solver.getNumIters();
224 MVT::MvInit( *soln, zero );
226 ret = solver.solve();
227 numIters3=solver.getNumIters();
234 if ( ret!=
Belos::Converged || norm_failure || numIters1 < numIters2 || numIters2 < numIters3 ) {
237 std::cout <<
"End Result: TEST FAILED" << std::endl;
241 std::cout <<
"End Result: TEST PASSED" << std::endl;
246 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
std::string Belos_Version()
int main(int argc, char *argv[])
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Traits class which defines basic operations on multivectors.
Simple example of a user's defined Belos::MultiVec class.
Declaration and definition of Belos::GCRODRSolMgr, which implements the GCRODR (recycling GMRES) solv...
Alternative run-time polymorphic interface for operators.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Implementation of the GCRODR (Recycling GMRES) iterative linear 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...
Simple example of a user's defined Belos::Operator class.