Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
test_aztecoo_thyra_driver.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stratimikos: Thyra-based strategies for linear solvers
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
46 #include "az_aztec_defs.h"
47 
48 struct MatrixTestPacket {
50  std::string _matrixFile
51  ,double _maxFwdError
52  ,int _maxIters
53  ,double _maxResid
54  ,double _maxSolutionError
55  ,double _maxSlackErrorFrac
56  ,int _maxPrecIters
57  ,double _maxPrecResid
58  ,double _maxPrecSolutionError
59  ,double _maxPrecSlackErrorFrac
60  )
61  :matrixFile(_matrixFile)
62  ,maxFwdError(_maxFwdError)
63  ,maxIters(_maxIters)
64  ,maxResid(_maxResid)
65  ,maxSolutionError(_maxSolutionError)
66  ,maxSlackErrorFrac(_maxSlackErrorFrac)
67  ,maxPrecIters(_maxPrecIters)
68  ,maxPrecResid(_maxPrecResid)
69  ,maxPrecSolutionError(_maxPrecSolutionError)
70  ,maxPrecSlackErrorFrac(_maxPrecSlackErrorFrac)
71  {}
72  std::string matrixFile;
73  double maxFwdError;
74  int maxIters;
75  double maxResid;
76  double maxSolutionError;
77  double maxSlackErrorFrac;
78  int maxPrecIters;
79  double maxPrecResid;
80  double maxPrecSolutionError;
81  double maxPrecSlackErrorFrac;
82 };
83 
84 int main(int argc, char* argv[])
85 {
86 
87  Teuchos::GlobalMPISession mpiSession(&argc,&argv);
88 
90 
91  bool result, success = true;
92  bool verbose = true;
93 
94  Teuchos::FancyOStream out(Teuchos::rcp(&std::cout,false));
95 
96  try {
97 
98  //
99  // Read options from command-line
100  //
101 
102  std::string matrixDir = ".";
103  int numRandomVectors = 1;
104  bool showAllTests = false;
105  bool showAllTestsDetails = false;
106  bool dumpAll = false;
107  std::string aztecOutputLevel = "freq";
108  int aztecOutputFreq = 0;
109 
110  CommandLineProcessor clp(false); // Don't throw exceptions
111  clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" );
112  clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
113  clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
114  clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
115  clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." );
116  clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
117  clp.setOption( "aztec-output-level", &aztecOutputLevel, "Aztec output level (freq,last,summary,warnings,all)" );
118  clp.setOption( "aztec-output-freq", &aztecOutputFreq, "Aztec output freqency (> 0)" );
119  CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
120  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
121 
122  TEUCHOS_TEST_FOR_EXCEPT( matrixDir == "" );
123 
124  //
125  // Define the test matrices
126  //
127 
128  const int numTestMatrices = 9;
129 
130  typedef MatrixTestPacket MTP;
131 
132  // Set up the matices and the tolerances.
133  // Note, we may need to adjust these for bad platforms ...
134  const MTP testMatrices[numTestMatrices] =
135  {
136  MTP("bcsstk01.mtx" ,1e-12, 40 , 1e-4, 0.6, 1.0, 20 , 1e-10, 0.5, 1.0)
137  ,MTP("bcsstk02.mtx" ,1e-12, 40 , 1e-3, 0.5, 1.0, 2 , 1e-10, 0.5, 1.0)
138  ,MTP("bcsstk04.mtx" ,1e-12, 80 , 1e-4, 0.999990, 1.0, 40 , 1e-10, 0.999990, 1.0)
139  ,MTP("Diagonal.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
140  ,MTP("FourByFour.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
141  ,MTP("KheadK.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
142  ,MTP("KheadSorted.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
143  ,MTP("nos1.mtx" ,1e-11, 200, 1e-4, 0.8, 1.0, 237, 1e-2, 5.0, 1.0)
144  ,MTP("nos5.mtx" ,1e-12, 468, 1e-5, 0.5, 1.0, 468, 1e-10, 0.5, 1.0)
145  };
146  //
147  // Loop through all of the test matrices
148  //
149  for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) {
150  const MatrixTestPacket
151  mtp = testMatrices[matrix_i];
152  //
153  // Do unpreconditioned and preconditioned solves
154  //
155  for( int prec_i = 0; prec_i < 2; ++prec_i ) {
156  if(verbose)
157  out << std::endl<<matrix_i<<":"<<prec_i<<": Testing, matrixFile=\'"<<mtp.matrixFile<<"\', ";
158  bool testTranspose;
159  double maxResid;
160  double maxSolutionError;
161  double maxSlackErrorFrac;
163  paramList("AztecOOLinearOpWithSolveFactory");
165  &fwdSolvePL = paramList.sublist("Forward Solve"),
166  &adjSolvePL = paramList.sublist("Adjoint Solve");
168  &fwdAztecOOPL = fwdSolvePL.sublist("AztecOO Settings"),
169  &adjAztecOOPL = adjSolvePL.sublist("AztecOO Settings");
170  if( aztecOutputLevel != "freq" ) {
171  fwdAztecOOPL.set("Output Frequency",aztecOutputLevel);
172  adjAztecOOPL.set("Output Frequency",aztecOutputLevel);
173  }
174  else {
175  fwdAztecOOPL.set("Output Frequency",aztecOutputFreq);
176  adjAztecOOPL.set("Output Frequency",aztecOutputFreq);
177  }
178  if(prec_i==0) {
179  out << "no aztec preconditioning ... ";
180  fwdAztecOOPL.set("Aztec Preconditioner","none");
181  testTranspose = true;
182  fwdSolvePL.set("Max Iterations",mtp.maxIters);
183  adjSolvePL.set("Max Iterations",mtp.maxIters);
184  maxResid = mtp.maxResid;
185  maxSolutionError = mtp.maxSolutionError;
186  maxSlackErrorFrac = mtp.maxSlackErrorFrac;
187  }
188  else {
189  out << "using aztec preconditioning ... ";
190  fwdAztecOOPL.set("Aztec Preconditioner","ilu");
191  testTranspose = false;
192  fwdSolvePL.set("Max Iterations",mtp.maxPrecIters);
193  adjSolvePL.set("Max Iterations",mtp.maxPrecIters);
194  maxResid = mtp.maxPrecResid;
195  maxSolutionError = mtp.maxPrecSolutionError;
196  maxSlackErrorFrac = mtp.maxPrecSlackErrorFrac;
197  }
198  std::ostringstream oss;
199  Teuchos::FancyOStream fancy_oss(Teuchos::rcp(&oss,false));
200  result =
202  matrixDir+"/"+mtp.matrixFile,testTranspose,numRandomVectors
203  ,mtp.maxFwdError,maxResid,maxSolutionError
204  ,showAllTestsDetails,dumpAll,&paramList,&fancy_oss
205  );
206  if(!result) success = false;
207  if(verbose) {
208  if(result) {
209  if(showAllTests)
210  out << std::endl << oss.str();
211  else
212  out << " : passed!\n";
213  }
214  else {
215  if(showAllTests)
216  out << std::endl << oss.str();
217  else
218  out << " : failed!\n";
219  }
220  }
221  }
222  }
223 
224  }
225  catch( const std::exception &excpt ) {
226  std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
227  success = false;
228  }
229  catch( ... ) {
230  std::cerr << "*** Caught an unknown exception\n";
231  success = false;
232  }
233 
234  if (verbose) {
235  if(success) out << "\nCongratulations! All of the tests checked out!\n";
236  else out << "\nOh no! At least one of the tests failed!\n";
237  }
238 
239  return ( success ? 0 : 1 );
240 }
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool test_single_aztecoo_thyra_solver(const std::string matrixFile, const bool testTranspose, const int numRandomVectors, const double maxFwdError, const double maxResid, const double maxSolutionError, const bool showAllTests, const bool dumpAll, Teuchos::ParameterList *paramList, Teuchos::FancyOStream *out)
Testing function for a single aztecoo solver with a single matrix.
MatrixTestPacket(std::string _matrixFile, double _maxFwdError, int _maxIters, double _maxResid, double _maxSolutionError, double _maxSlackErrorFrac, int _maxPrecIters, double _maxPrecResid, double _maxPrecSolutionError, double _maxPrecSlackErrorFrac)
int main(int argc, char *argv[])
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)