62 #ifdef HAVE_BELOS_TRIUTILS 
   63 #include "Trilinos_Util_iohb.h" 
   70 using namespace Teuchos;
 
   72 int main(
int argc, 
char *argv[]) {
 
   75   typedef std::complex<double> ST;
 
   77   typedef std::complex<double> ST;
 
   79   std::cout << 
"Not compiled with std::complex support." << std::endl;
 
   80   std::cout << 
"End Result: TEST FAILED" << std::endl;
 
   85   typedef SCT::magnitudeType                MT;
 
   91   ST zero = SCT::zero();
 
  100   bool verbose = 
false;
 
  103     bool norm_failure = 
false;
 
  104     bool proc_verbose = 
false;
 
  105     bool userandomrhs = 
true;
 
  111     int maxsubspace = 50;      
 
  112     int maxrestarts = 15;      
 
  113     std::string outersolver(
"Block Gmres");
 
  114     std::string 
filename(
"mhd1280b.cua");
 
  115     std::string polyType(
"Arnoldi");
 
  120     cmdp.
setOption(
"verbose",
"quiet",&verbose,
"Print messages and results.");
 
  121     cmdp.
setOption(
"use-random-rhs",
"use-rhs",&userandomrhs,
"Use linear system RHS or random RHS to generate polynomial.");
 
  122     cmdp.
setOption(
"frequency",&frequency,
"Solvers frequency for printing residuals (#iters).");
 
  123     cmdp.
setOption(
"filename",&filename,
"Filename for test matrix.  Acceptable file extensions: *.hb,*.mtx,*.triU,*.triS");
 
  124     cmdp.
setOption(
"outersolver",&outersolver,
"Name of outer solver to be used with GMRES poly");
 
  125     cmdp.
setOption(
"tol",&tol,
"Relative residual tolerance used by GMRES solver.");
 
  126     cmdp.
setOption(
"poly-tol",&polytol,
"Relative residual tolerance used to construct the GMRES polynomial.");
 
  127     cmdp.
setOption(
"poly-type",&polyType,
"Polynomial type (Roots, Arnoldi, or Gmres).");
 
  128     cmdp.
setOption(
"num-rhs",&numrhs,
"Number of right-hand sides to be solved for.");
 
  129     cmdp.
setOption(
"block-size",&blocksize,
"Block size used by GMRES.");
 
  130     cmdp.
setOption(
"max-iters",&maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");
 
  131     cmdp.
setOption(
"max-degree",&maxdegree,
"Maximum degree of the GMRES polynomial.");
 
  132     cmdp.
setOption(
"max-subspace",&maxsubspace,
"Maximum number of blocks the solver can use for the subspace.");
 
  133     cmdp.
setOption(
"max-restarts",&maxrestarts,
"Maximum number of restarts allowed for GMRES solver.");
 
  138     proc_verbose = verbose && (MyPID==0);  
 
  145 #ifndef HAVE_BELOS_TRIUTILS 
  146     std::cout << 
"This test requires Triutils. Please configure with --enable-triutils." << std::endl;
 
  148       std::cout << 
"End Result: TEST FAILED" << std::endl;
 
  159     info = readHB_newmat_double(filename.c_str(),&dim,&dim2,&nnz,
 
  160         &colptr,&rowind,&dvals);
 
  161     if (info == 0 || nnz < 0) {
 
  163         std::cout << 
"Error reading '" << filename << 
"'" << std::endl;
 
  164         std::cout << 
"End Result: TEST FAILED" << std::endl;
 
  170     for (
int ii=0; ii<nnz; ii++) {
 
  171       cvals[ii] = ST(dvals[ii*2],dvals[ii*2+1]);
 
  183     MVT::MvRandom( *soln );
 
  184     OPT::Apply( *A, *soln, *rhs );
 
  185     MVT::MvInit( *soln, zero );
 
  191     problem->setInitResVec( rhs );
 
  192     bool set = problem->setProblem();
 
  195         std::cout << std::endl << 
"ERROR:  Belos::LinearProblem failed to set up correctly!" << std::endl;
 
  203       maxiters = dim/blocksize - 1; 
 
  206     belosList.
set( 
"Num Blocks", maxsubspace);             
 
  207     belosList.
set( 
"Block Size", blocksize );              
 
  208     belosList.
set( 
"Maximum Iterations", maxiters );       
 
  209     belosList.
set( 
"Maximum Restarts", maxrestarts );      
 
  210     belosList.
set( 
"Convergence Tolerance", tol );         
 
  215         belosList.
set( 
"Output Frequency", frequency );
 
  217     belosList.
set( 
"Verbosity", verbosity );
 
  220     polyList.
set( 
"Maximum Degree", maxdegree );          
 
  221     polyList.
set( 
"Polynomial Tolerance", polytol );      
 
  222     polyList.
set( 
"Polynomial Type", polyType );          
 
  223     polyList.
set( 
"Verbosity", verbosity );               
 
  224     polyList.
set( 
"Random RHS", userandomrhs );           
 
  225     if ( outersolver != 
"" ) {
 
  226       polyList.
set( 
"Outer Solver", outersolver );
 
  227       polyList.
set( 
"Outer Solver Params", belosList );
 
  248       std::cout << std::endl << std::endl;
 
  249       std::cout << 
"Dimension of matrix: " << dim << std::endl;
 
  250       std::cout << 
"Number of right-hand sides: " << numrhs << std::endl;
 
  251       std::cout << 
"Block size used by solver: " << blocksize << std::endl;
 
  252       std::cout << 
"Max number of Gmres iterations: " << maxiters << std::endl;
 
  253       std::cout << 
"Relative residual tolerance: " << tol << std::endl;
 
  254       std::cout << std::endl;
 
  264     OPT::Apply( *A, *soln, *temp );
 
  265     MVT::MvAddMv( one, *rhs, -one, *temp, *temp );
 
  266     std::vector<MT> norm_num(numrhs), norm_denom(numrhs);
 
  267     MVT::MvNorm( *temp, norm_num );
 
  268     MVT::MvNorm( *rhs, norm_denom );
 
  269     for (
int i=0; i<numrhs; ++i) {
 
  271         std::cout << 
"Relative residual "<<i<<
" : " << norm_num[i] / norm_denom[i] << std::endl;
 
  272       if ( norm_num[i] / norm_denom[i] > tol ) {
 
  278     const std::vector<MT> residualLog = debugTest.
getLogResNorm();
 
  279     if (numrhs==1 && proc_verbose && residualLog.size())
 
  281       std::cout << 
"Absolute residual 2-norm [ " << residualLog.size() << 
" ] : ";
 
  282       for (
unsigned int i=0; i<residualLog.size(); i++)
 
  283         std::cout << residualLog[i] << 
" ";
 
  284       std::cout << std::endl;
 
  285       std::cout << 
"Final abs 2-norm / rhs 2-norm : " << residualLog[residualLog.size()-1] / norm_denom[0] << std::endl;
 
  297         std::cout << 
"End Result: TEST PASSED" << std::endl;
 
  300         std::cout << 
"End Result: TEST FAILED" << std::endl;
 
  305   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)
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...
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)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Declaration and definition of Belos::GmresPolySolMgr (hybrid block GMRES linear solver). 
#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 
The GMRES polynomial can be created in conjunction with any standard preconditioner. 
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.