Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_aztecoo_thyra_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 
15 #include "az_aztec_defs.h"
16 
17 struct MatrixTestPacket {
19  std::string _matrixFile
20  ,double _maxFwdError
21  ,int _maxIters
22  ,double _maxResid
23  ,double _maxSolutionError
24  ,double _maxSlackErrorFrac
25  ,int _maxPrecIters
26  ,double _maxPrecResid
27  ,double _maxPrecSolutionError
28  ,double _maxPrecSlackErrorFrac
29  )
30  :matrixFile(_matrixFile)
31  ,maxFwdError(_maxFwdError)
32  ,maxIters(_maxIters)
33  ,maxResid(_maxResid)
34  ,maxSolutionError(_maxSolutionError)
35  ,maxSlackErrorFrac(_maxSlackErrorFrac)
36  ,maxPrecIters(_maxPrecIters)
37  ,maxPrecResid(_maxPrecResid)
38  ,maxPrecSolutionError(_maxPrecSolutionError)
39  ,maxPrecSlackErrorFrac(_maxPrecSlackErrorFrac)
40  {}
41  std::string matrixFile;
42  double maxFwdError;
43  int maxIters;
44  double maxResid;
48  double maxPrecResid;
51 };
52 
53 int main(int argc, char* argv[])
54 {
55 
56  Teuchos::GlobalMPISession mpiSession(&argc,&argv);
57 
59 
60  bool result, success = true;
61  bool verbose = true;
62 
63  Teuchos::FancyOStream out(Teuchos::rcp(&std::cout,false));
64 
65  try {
66 
67  //
68  // Read options from command-line
69  //
70 
71  std::string matrixDir = ".";
72  int numRandomVectors = 1;
73  bool showAllTests = false;
74  bool showAllTestsDetails = false;
75  bool dumpAll = false;
76  std::string aztecOutputLevel = "freq";
77  int aztecOutputFreq = 0;
78 
79  CommandLineProcessor clp(false); // Don't throw exceptions
80  clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" );
81  clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
82  clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
83  clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
84  clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." );
85  clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
86  clp.setOption( "aztec-output-level", &aztecOutputLevel, "Aztec output level (freq,last,summary,warnings,all)" );
87  clp.setOption( "aztec-output-freq", &aztecOutputFreq, "Aztec output freqency (> 0)" );
88  CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
89  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
90 
91  TEUCHOS_TEST_FOR_EXCEPT( matrixDir == "" );
92 
93  //
94  // Define the test matrices
95  //
96 
97  const int numTestMatrices = 9;
98 
99  typedef MatrixTestPacket MTP;
100 
101  // Set up the matices and the tolerances.
102  // Note, we may need to adjust these for bad platforms ...
103  const MTP testMatrices[numTestMatrices] =
104  {
105  MTP("bcsstk01.mtx" ,1e-12, 40 , 1e-4, 0.6, 1.0, 20 , 1e-10, 0.5, 1.0)
106  ,MTP("bcsstk02.mtx" ,1e-12, 40 , 1e-3, 0.5, 1.0, 2 , 1e-10, 0.5, 1.0)
107  ,MTP("bcsstk04.mtx" ,1e-12, 80 , 1e-4, 0.999990, 1.0, 40 , 1e-10, 0.999990, 1.0)
108  ,MTP("Diagonal.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
109  ,MTP("FourByFour.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
110  ,MTP("KheadK.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
111  ,MTP("KheadSorted.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
112  ,MTP("nos1.mtx" ,1e-11, 200, 1e-4, 0.8, 1.0, 237, 1e-2, 5.0, 1.0)
113  ,MTP("nos5.mtx" ,1e-12, 468, 1e-5, 0.5, 1.0, 468, 1e-10, 0.5, 1.0)
114  };
115  //
116  // Loop through all of the test matrices
117  //
118  for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) {
119  const MatrixTestPacket
120  mtp = testMatrices[matrix_i];
121  //
122  // Do unpreconditioned and preconditioned solves
123  //
124  for( int prec_i = 0; prec_i < 2; ++prec_i ) {
125  if(verbose)
126  out << std::endl<<matrix_i<<":"<<prec_i<<": Testing, matrixFile=\'"<<mtp.matrixFile<<"\', ";
127  bool testTranspose;
128  double maxResid;
129  double maxSolutionError;
130  //double maxSlackErrorFrac;
132  paramList("AztecOOLinearOpWithSolveFactory");
134  &fwdSolvePL = paramList.sublist("Forward Solve"),
135  &adjSolvePL = paramList.sublist("Adjoint Solve");
137  &fwdAztecOOPL = fwdSolvePL.sublist("AztecOO Settings"),
138  &adjAztecOOPL = adjSolvePL.sublist("AztecOO Settings");
139  if( aztecOutputLevel != "freq" ) {
140  fwdAztecOOPL.set("Output Frequency",aztecOutputLevel);
141  adjAztecOOPL.set("Output Frequency",aztecOutputLevel);
142  }
143  else {
144  fwdAztecOOPL.set("Output Frequency",aztecOutputFreq);
145  adjAztecOOPL.set("Output Frequency",aztecOutputFreq);
146  }
147  if(prec_i==0) {
148  out << "no aztec preconditioning ... ";
149  fwdAztecOOPL.set("Aztec Preconditioner","none");
150  testTranspose = true;
151  fwdSolvePL.set("Max Iterations",mtp.maxIters);
152  adjSolvePL.set("Max Iterations",mtp.maxIters);
153  maxResid = mtp.maxResid;
154  maxSolutionError = mtp.maxSolutionError;
155  //maxSlackErrorFrac = mtp.maxSlackErrorFrac;
156  }
157  else {
158  out << "using aztec preconditioning ... ";
159  fwdAztecOOPL.set("Aztec Preconditioner","ilu");
160  testTranspose = false;
161  fwdSolvePL.set("Max Iterations",mtp.maxPrecIters);
162  adjSolvePL.set("Max Iterations",mtp.maxPrecIters);
163  maxResid = mtp.maxPrecResid;
164  maxSolutionError = mtp.maxPrecSolutionError;
165  //maxSlackErrorFrac = mtp.maxPrecSlackErrorFrac;
166  }
167  std::ostringstream oss;
168  Teuchos::FancyOStream fancy_oss(Teuchos::rcp(&oss,false));
169  result =
170  Thyra::test_single_aztecoo_thyra_solver(
171  matrixDir+"/"+mtp.matrixFile,testTranspose,numRandomVectors
172  ,mtp.maxFwdError,maxResid,maxSolutionError
173  ,showAllTestsDetails,dumpAll,&paramList,&fancy_oss
174  );
175  if(!result) success = false;
176  if(verbose) {
177  if(result) {
178  if(showAllTests)
179  out << std::endl << oss.str();
180  else
181  out << " : passed!\n";
182  }
183  else {
184  if(showAllTests)
185  out << std::endl << oss.str();
186  else
187  out << " : failed!\n";
188  }
189  }
190  }
191  }
192 
193  }
194  TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
195 
196  if (verbose) {
197  if(success) out << "\nCongratulations! All of the tests checked out!\n";
198  else out << "\nOh no! At least one of the tests failed!\n";
199  }
200 
201  return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
202 }
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)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
bool dumpAll
MatrixTestPacket(std::string _matrixFile, double _maxFwdError, int _maxIters, double _maxResid, double _maxSolutionError, double _maxSlackErrorFrac, int _maxPrecIters, double _maxPrecResid, double _maxPrecSolutionError, double _maxPrecSlackErrorFrac)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)