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 //
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 
47 #include "az_aztec_defs.h"
48 
49 struct MatrixTestPacket {
51  std::string _matrixFile
52  ,double _maxFwdError
53  ,int _maxIters
54  ,double _maxResid
55  ,double _maxSolutionError
56  ,double _maxSlackErrorFrac
57  ,int _maxPrecIters
58  ,double _maxPrecResid
59  ,double _maxPrecSolutionError
60  ,double _maxPrecSlackErrorFrac
61  )
62  :matrixFile(_matrixFile)
63  ,maxFwdError(_maxFwdError)
64  ,maxIters(_maxIters)
65  ,maxResid(_maxResid)
66  ,maxSolutionError(_maxSolutionError)
67  ,maxSlackErrorFrac(_maxSlackErrorFrac)
68  ,maxPrecIters(_maxPrecIters)
69  ,maxPrecResid(_maxPrecResid)
70  ,maxPrecSolutionError(_maxPrecSolutionError)
71  ,maxPrecSlackErrorFrac(_maxPrecSlackErrorFrac)
72  {}
73  std::string matrixFile;
74  double maxFwdError;
75  int maxIters;
76  double maxResid;
77  double maxSolutionError;
78  double maxSlackErrorFrac;
79  int maxPrecIters;
80  double maxPrecResid;
81  double maxPrecSolutionError;
82  double maxPrecSlackErrorFrac;
83 };
84 
85 int main(int argc, char* argv[])
86 {
87 
88  Teuchos::GlobalMPISession mpiSession(&argc,&argv);
89 
91 
92  bool result, success = true;
93  bool verbose = true;
94 
95  Teuchos::FancyOStream out(Teuchos::rcp(&std::cout,false));
96 
97  try {
98 
99  //
100  // Read options from command-line
101  //
102 
103  std::string matrixDir = ".";
104  int numRandomVectors = 1;
105  bool showAllTests = false;
106  bool showAllTestsDetails = false;
107  bool dumpAll = false;
108  std::string aztecOutputLevel = "freq";
109  int aztecOutputFreq = 0;
110 
111  CommandLineProcessor clp(false); // Don't throw exceptions
112  clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" );
113  clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
114  clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
115  clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
116  clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." );
117  clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
118  clp.setOption( "aztec-output-level", &aztecOutputLevel, "Aztec output level (freq,last,summary,warnings,all)" );
119  clp.setOption( "aztec-output-freq", &aztecOutputFreq, "Aztec output freqency (> 0)" );
120  CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
121  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
122 
123  TEUCHOS_TEST_FOR_EXCEPT( matrixDir == "" );
124 
125  //
126  // Define the test matrices
127  //
128 
129  const int numTestMatrices = 9;
130 
131  typedef MatrixTestPacket MTP;
132 
133  // Set up the matices and the tolerances.
134  // Note, we may need to adjust these for bad platforms ...
135  const MTP testMatrices[numTestMatrices] =
136  {
137  MTP("bcsstk01.mtx" ,1e-12, 40 , 1e-4, 0.6, 1.0, 20 , 1e-10, 0.5, 1.0)
138  ,MTP("bcsstk02.mtx" ,1e-12, 40 , 1e-3, 0.5, 1.0, 2 , 1e-10, 0.5, 1.0)
139  ,MTP("bcsstk04.mtx" ,1e-12, 80 , 1e-4, 0.999990, 1.0, 40 , 1e-10, 0.999990, 1.0)
140  ,MTP("Diagonal.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
141  ,MTP("FourByFour.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
142  ,MTP("KheadK.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
143  ,MTP("KheadSorted.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
144  ,MTP("nos1.mtx" ,1e-11, 200, 1e-4, 0.8, 1.0, 237, 1e-2, 5.0, 1.0)
145  ,MTP("nos5.mtx" ,1e-12, 468, 1e-5, 0.5, 1.0, 468, 1e-10, 0.5, 1.0)
146  };
147  //
148  // Loop through all of the test matrices
149  //
150  for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) {
151  const MatrixTestPacket
152  mtp = testMatrices[matrix_i];
153  //
154  // Do unpreconditioned and preconditioned solves
155  //
156  for( int prec_i = 0; prec_i < 2; ++prec_i ) {
157  if(verbose)
158  out << std::endl<<matrix_i<<":"<<prec_i<<": Testing, matrixFile=\'"<<mtp.matrixFile<<"\', ";
159  bool testTranspose;
160  double maxResid;
161  double maxSolutionError;
162  //double maxSlackErrorFrac;
164  paramList("AztecOOLinearOpWithSolveFactory");
166  &fwdSolvePL = paramList.sublist("Forward Solve"),
167  &adjSolvePL = paramList.sublist("Adjoint Solve");
169  &fwdAztecOOPL = fwdSolvePL.sublist("AztecOO Settings"),
170  &adjAztecOOPL = adjSolvePL.sublist("AztecOO Settings");
171  if( aztecOutputLevel != "freq" ) {
172  fwdAztecOOPL.set("Output Frequency",aztecOutputLevel);
173  adjAztecOOPL.set("Output Frequency",aztecOutputLevel);
174  }
175  else {
176  fwdAztecOOPL.set("Output Frequency",aztecOutputFreq);
177  adjAztecOOPL.set("Output Frequency",aztecOutputFreq);
178  }
179  if(prec_i==0) {
180  out << "no aztec preconditioning ... ";
181  fwdAztecOOPL.set("Aztec Preconditioner","none");
182  testTranspose = true;
183  fwdSolvePL.set("Max Iterations",mtp.maxIters);
184  adjSolvePL.set("Max Iterations",mtp.maxIters);
185  maxResid = mtp.maxResid;
186  maxSolutionError = mtp.maxSolutionError;
187  //maxSlackErrorFrac = mtp.maxSlackErrorFrac;
188  }
189  else {
190  out << "using aztec preconditioning ... ";
191  fwdAztecOOPL.set("Aztec Preconditioner","ilu");
192  testTranspose = false;
193  fwdSolvePL.set("Max Iterations",mtp.maxPrecIters);
194  adjSolvePL.set("Max Iterations",mtp.maxPrecIters);
195  maxResid = mtp.maxPrecResid;
196  maxSolutionError = mtp.maxPrecSolutionError;
197  //maxSlackErrorFrac = mtp.maxPrecSlackErrorFrac;
198  }
199  std::ostringstream oss;
200  Teuchos::FancyOStream fancy_oss(Teuchos::rcp(&oss,false));
201  result =
202  Thyra::test_single_aztecoo_thyra_solver(
203  matrixDir+"/"+mtp.matrixFile,testTranspose,numRandomVectors
204  ,mtp.maxFwdError,maxResid,maxSolutionError
205  ,showAllTestsDetails,dumpAll,&paramList,&fancy_oss
206  );
207  if(!result) success = false;
208  if(verbose) {
209  if(result) {
210  if(showAllTests)
211  out << std::endl << oss.str();
212  else
213  out << " : passed!\n";
214  }
215  else {
216  if(showAllTests)
217  out << std::endl << oss.str();
218  else
219  out << " : failed!\n";
220  }
221  }
222  }
223  }
224 
225  }
226  TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
227 
228  if (verbose) {
229  if(success) out << "\nCongratulations! All of the tests checked out!\n";
230  else out << "\nOh no! At least one of the tests failed!\n";
231  }
232 
233  return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
234 }
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)
bool showAllTests
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)
#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)