31 #ifdef HAVE_BELOS_TRIUTILS
32 #include "Trilinos_Util_iohb.h"
39 using namespace Teuchos;
41 int main(
int argc,
char *argv[]) {
43 typedef std::complex<double> ST;
45 typedef SCT::magnitudeType MT;
51 ST zero = SCT::zero();
64 bool norm_failure =
false;
65 bool proc_verbose =
false;
72 std::string
filename(
"mhd1280b.cua");
73 std::string ortho(
"ICGS");
77 cmdp.
setOption(
"verbose",
"quiet",&verbose,
"Print messages and results.");
78 cmdp.
setOption(
"debug",
"no-debug",&debug,
"Print debug messages.");
79 cmdp.
setOption(
"pseudo",
"regular",&pseudo,
"Use pseudo-block GMRES to solve the linear systems.");
80 cmdp.
setOption(
"frequency",&frequency,
"Solvers frequency for printing residuals (#iters).");
81 cmdp.
setOption(
"filename",&filename,
"Filename for Harwell-Boeing test matrix.");
82 cmdp.
setOption(
"tol",&tol,
"Relative residual tolerance used by GMRES solver.");
83 cmdp.
setOption(
"num-rhs",&numrhs,
"Number of right-hand sides to be solved for.");
84 cmdp.
setOption(
"num-restarts",&maxrestarts,
"Maximum number of restarts allowed for the GMRES solver.");
85 cmdp.
setOption(
"blocksize",&blocksize,
"Block size used by GMRES.");
86 cmdp.
setOption(
"subspace-length",&length,
"Maximum dimension of block-subspace used by GMRES solver.");
87 cmdp.
setOption(
"ortho-type",&ortho,
"Orthogonalization type, either DGKS, ICGS or IMGS");
92 proc_verbose = verbose && (MyPID==0);
99 #ifndef HAVE_BELOS_TRIUTILS
100 std::cout <<
"This test requires Triutils. Please configure with --enable-triutils." << std::endl;
102 std::cout <<
"End Result: TEST FAILED" << std::endl;
113 info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,
114 &colptr,&rowind,&dvals);
115 if (info == 0 || nnz < 0) {
117 std::cout <<
"Error reading '" << filename <<
"'" << std::endl;
118 std::cout <<
"End Result: TEST FAILED" << std::endl;
124 for (
int ii=0; ii<nnz; ii++) {
125 cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
134 int maxits = dim/blocksize;
137 belosList.
set(
"Num Blocks", length );
138 belosList.
set(
"Block Size", blocksize );
139 belosList.
set(
"Maximum Iterations", maxits );
140 belosList.
set(
"Maximum Restarts", maxrestarts );
141 belosList.
set(
"Convergence Tolerance", tol );
142 belosList.
set(
"Orthogonalization", ortho );
148 belosList.
set(
"Verbosity", verbosity );
150 belosList.
set(
"Output Frequency", frequency );
161 MVT::MvRandom( *soln );
162 OPT::Apply( *A, *soln, *rhs );
163 MVT::MvInit( *soln, zero );
169 bool set = problem->setProblem();
172 std::cout << std::endl <<
"ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
191 solver->setDebugStatusTest(
Teuchos::rcp(&debugTest,
false) );
197 std::cout << std::endl << std::endl;
198 std::cout <<
"Dimension of matrix: " << dim << std::endl;
199 std::cout <<
"Number of right-hand sides: " << numrhs << std::endl;
200 std::cout <<
"Block size used by solver: " << blocksize << std::endl;
201 std::cout <<
"Max number of Gmres iterations: " << maxits << std::endl;
202 std::cout <<
"Relative residual tolerance: " << tol << std::endl;
203 std::cout << std::endl;
213 OPT::Apply( *A, *soln, *temp );
214 MVT::MvAddMv( one, *rhs, -one, *temp, *temp );
215 std::vector<MT> norm_num(numrhs), norm_denom(numrhs);
216 MVT::MvNorm( *temp, norm_num );
217 MVT::MvNorm( *rhs, norm_denom );
218 for (
int i=0; i<numrhs; ++i) {
220 std::cout <<
"Relative residual "<<i<<
" : " << norm_num[i] / norm_denom[i] << std::endl;
221 if ( norm_num[i] / norm_denom[i] > tol ) {
227 const std::vector<MT> residualLog = debugTest.
getLogResNorm();
228 if (numrhs==1 && proc_verbose && residualLog.size())
230 std::cout <<
"Absolute residual 2-norm [ " << residualLog.size() <<
" ] : ";
231 for (
unsigned int i=0; i<residualLog.size(); i++)
232 std::cout << residualLog[i] <<
" ";
233 std::cout << std::endl;
234 std::cout <<
"Final abs 2-norm / rhs 2-norm : " << residualLog[residualLog.size()-1] / norm_denom[0] << std::endl;
246 std::cout <<
"End Result: TEST PASSED" << std::endl;
249 std::cout <<
"End Result: TEST FAILED" << std::endl;
254 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
std::string Belos_Version()
int main(int argc, char *argv[])
const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > & getLogResNorm() const
Returns the log of the absolute residual norm from the iteration.
A Belos::StatusTest debugging class for storing the absolute residual norms generated during a solve...
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Interface to Block GMRES and Flexible GMRES.
Belos::StatusTest debugging class for storing the absolute residual norms generated during a solve...
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
The Belos::BlockGmresSolMgr provides a solver manager for the BlockGmres linear solver.
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
Interface to standard and "pseudoblock" GMRES.
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.
The Belos::PseudoBlockGmresSolMgr provides a solver manager for the BlockGmres linear solver...
Belos header file which uses auto-configuration information to include necessary C++ headers...
Simple example of a user's defined Belos::Operator class.