Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_single_belos_thyra_solver_driver.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stratimikos: Thyra-based strategies for linear solvers
4 //
5 // Copyright 2006 NTESS and the Stratimikos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
16 
17 
18 int main(int argc, char* argv[])
19 {
20 
22 
23  bool success = true;
24  bool verbose = true;
25 
26  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
27 
29  out = Teuchos::VerboseObjectBase::getDefaultOStream();
30 
31  try {
32 
33  //
34  // Read options from command-line
35  //
36 
37  std::string matrixFile = "";
38  bool testTranspose = false;
39  bool usePreconditioner = true;
40  int numRhs = 1;
41  int numRandomVectors = 1;
42  double maxFwdError = 1e-14;
43  int maxIterations = 400;
44  int maxRestarts = 25;
45  int gmresKrylovLength = 25;
46  int outputFrequency = 10;
47  bool outputMaxResOnly = true;
48  int blockSize = 1;
49  double maxResid = 1e-6;
50  double maxSolutionError = 1e-6;
51  bool showAllTests = false;
52  bool dumpAll = false;
53 
54  CommandLineProcessor clp;
55  clp.throwExceptions(false);
56  clp.addOutputSetupOptions(true);
57  clp.setOption( "matrix-file", &matrixFile, "Matrix input file [Required]." );
58  clp.setOption( "test-transpose", "no-test-transpose", &testTranspose, "Test the transpose solve or not." );
59  clp.setOption( "use-preconditioner", "no-use-preconditioner", &usePreconditioner, "Use the preconditioner or not." );
60  clp.setOption( "num-rhs", &numRhs, "Number of RHS in linear solve." );
61  clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
62  clp.setOption( "max-fwd-error", &maxFwdError, "The maximum relative error in the forward operator." );
63  clp.setOption( "max-iters", &maxIterations, "The maximum number of linear solver iterations to take." );
64  clp.setOption( "max-restarts", &maxRestarts, "???." );
65  clp.setOption( "gmres-krylov-length", &gmresKrylovLength, "???." );
66  clp.setOption( "output-frequency", &outputFrequency, "Number of linear solver iterations between output" );
67  clp.setOption( "output-max-res-only", "output-all-res", &outputMaxResOnly, "Determines if only the max residual is printed or if all residuals are printed per iteration." );
68  clp.setOption( "block-size", &blockSize, "???." );
69  clp.setOption( "max-resid", &maxResid, "The maximum relative error in the residual." );
70  clp.setOption( "max-solution-error", &maxSolutionError, "The maximum relative error in the solution of the linear system." );
71  clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
72  clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
73  clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
74  CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
75  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
76 
77  TEUCHOS_TEST_FOR_EXCEPT( matrixFile == "" );
78 
79  Teuchos::ParameterList belosLOWSFPL;
80 
81  belosLOWSFPL.set("Solver Type","Block GMRES");
82 
83  Teuchos::ParameterList& belosLOWSFPL_solver =
84  belosLOWSFPL.sublist("Solver Types");
85 
86  Teuchos::ParameterList& belosLOWSFPL_gmres =
87  belosLOWSFPL_solver.sublist("Block GMRES");
88 
89  belosLOWSFPL_gmres.set("Maximum Iterations",int(maxIterations));
90  belosLOWSFPL_gmres.set("Convergence Tolerance",double(maxResid));
91  belosLOWSFPL_gmres.set("Maximum Restarts",int(maxRestarts));
92  belosLOWSFPL_gmres.set("Block Size",int(blockSize));
93  belosLOWSFPL_gmres.set("Num Blocks",int(gmresKrylovLength));
94  belosLOWSFPL_gmres.set("Output Frequency",int(outputFrequency));
95  belosLOWSFPL_gmres.set("Show Maximum Residual Norm Only",bool(outputMaxResOnly));
96 
97  Teuchos::ParameterList precPL("Ifpack");
98  if(usePreconditioner) {
99  precPL.set("Overlap",int(2));
100  precPL.set("Prec Type","ILUT");
101  }
102 
103  success
104  = Thyra::test_single_belos_thyra_solver(
105  matrixFile,testTranspose,usePreconditioner,numRhs,numRandomVectors
106  ,maxFwdError,maxResid,maxSolutionError,showAllTests,dumpAll
107  ,&belosLOWSFPL,&precPL
108  ,verbose?&*out:0
109  );
110 
111  }
112  TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success)
113 
114  if (verbose) {
115  if(success) *out << "\nCongratulations! All of the tests checked out!\n";
116  else *out << "\nOh no! At least one of the tests failed!\n";
117  }
118 
119  return ( success ? 0 : 1 );
120 }
int main(int argc, char *argv[])
bool showAllTests
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
bool dumpAll
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)