Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_amesos_thyra_driver.cpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Stratimikos: Thyra-based strategies for linear solvers
6 // Copyright (2006) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
48 
49 struct MatrixTestPacket {
50  MatrixTestPacket(std::string _matrixFile, bool _unsymmetric, double _maxFwdError, double _maxError, double _maxResid)
51  :matrixFile(_matrixFile),unsymmetric(_unsymmetric),maxFwdError(_maxFwdError),maxError(_maxError),maxResid(_maxResid) {}
52  std::string matrixFile;
54  double maxFwdError;
55  double maxError;
56  double maxResid;
57 };
58 
59 int main(int argc, char* argv[])
60 {
61 
62  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
63 
65  using Teuchos::OSTab;
66 
67  bool result, success = true;
68  bool verbose = true;
69 
70 
72  out = Teuchos::VerboseObjectBase::getDefaultOStream();
73 
74  try {
75 
76  //
77  // Read options from command-line
78  //
79 
80  std::string matrixDir = ".";
81  bool testTranspose = true;
82  int numRandomVectors = 1;
83  bool showAllTests = false;
84  bool showAllTestsDetails = false;
85  bool dumpAll = false;
86 
87  CommandLineProcessor clp;
88  clp.throwExceptions(false);
89  clp.addOutputSetupOptions(true);
90  clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" );
91  clp.setOption( "test-transpose", "no-test-transpose", &testTranspose, "Test the transpose solve or not." );
92  clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
93  clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
94  clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
95  clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." );
96  clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
97  CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
98  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
99 
100  TEUCHOS_TEST_FOR_EXCEPT( matrixDir == "" );
101 
102  //
103  // Define the test matrices
104  //
105 
106  const int numTestMatrices = 9;
107 
108  typedef MatrixTestPacket MTP;
109 
110  // Set up the matices and the tolerances.
111  // Note, we may need to adjust these for bad platforms ...
112  const MTP testMatrices[numTestMatrices] =
113  {
114  MTP("bcsstk01.mtx",false,1e-12,1e-12,1e-12)
115  ,MTP("bcsstk02.mtx",false,1e-12,1e-12,1e-12)
116  ,MTP("bcsstk04.mtx",false,1e-12,1e-10,1e-12)
117  ,MTP("Diagonal.mtx",false,1e-12,1e-12,1e-12)
118  ,MTP("FourByFour.mtx",true,1e-12,1e-12,1e-12)
119  ,MTP("KheadK.mtx",false,1e-12,1e-12,1e-12)
120  ,MTP("KheadSorted.mtx",false,1e-12,1e-12,1e-12)
121  ,MTP("nos1.mtx",false,1e-11,1e-10,1e-12)
122  ,MTP("nos5.mtx",false,1e-12,1e-12,1e-12)
123  };
124  //
125  // Loop through all of the test matrices
126  //
127  for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) {
128  const MatrixTestPacket
129  mtp = testMatrices[matrix_i];
130  //
131  // Loop through all of the solvers
132  //
133  for( int solver_i = 0; solver_i < Thyra::Amesos::numSolverTypes; ++solver_i ) {
135  solverType = Thyra::Amesos::solverTypeValues[solver_i];
136 
137  // bug 1902 - Amesos_Superlu fails on bcsstk01.mtx
138  // bug 1903 - Amesos_Superlu fails on four matrices,
139  // when called from the thyra test
140  //
141  bool BadMatrixForSuperlu =
142  mtp.matrixFile == "bcsstk01.mtx" // bug 1902
143  || mtp.matrixFile == "bcsstk04.mtx" // bug 1903
144  || mtp.matrixFile == "KheadK.mtx" // bug 1903
145  || mtp.matrixFile == "KheadSorted.mtx" // bug 1903
146  || mtp.matrixFile == "nos1.mtx" ; // bug 1903
147  //
148  // Toggle the refactorization options
149  //
150  for( int factorizationPolicy_i = 0; factorizationPolicy_i < Thyra::Amesos::numRefactorizationPolices; ++factorizationPolicy_i ) {
152  refactorizationPolicy = Thyra::Amesos::refactorizationPolicyValues[factorizationPolicy_i];
153  if(verbose)
154  *out
155  << std::endl<<matrix_i<<"."<<solver_i<<"."<<factorizationPolicy_i<<": "
156  << "Testing, matrixFile=\'"<<mtp.matrixFile<<"\', solverType=\'"<<toString(solverType)<<"\', refactorizationPolicy=\'"<<toString(refactorizationPolicy)<<"\' ...";
157  if( mtp.unsymmetric && !Thyra::Amesos::supportsUnsymmetric[solver_i] ) {
158  *out << " : Skipping since unsymmetric and not supported!\n";
159  }
160  else {
161  // bug 1902 and bug 1903
162  std::string StrSolverType = toString(solverType) ;
163  std::string StrSuperlu = "Superlu";
164  if ( StrSolverType==StrSuperlu && BadMatrixForSuperlu ) {
165  *out << " : Skipping since Superlu fails on this matrix!\n";
166  }
167  else {
168  std::ostringstream ossStore;
170  oss = Teuchos::rcp(new Teuchos::FancyOStream(Teuchos::rcp(&ossStore,false)));
171  Teuchos::ParameterList amesosLOWSFPL;
172  amesosLOWSFPL.set("Solver Type",toString(solverType));
173  amesosLOWSFPL.set("Refactorization Policy",toString(refactorizationPolicy));
174  result =
175  Thyra::test_single_amesos_thyra_solver(
176  matrixDir+"/"+mtp.matrixFile,&amesosLOWSFPL,testTranspose,numRandomVectors
177  ,mtp.maxFwdError,mtp.maxError,mtp.maxResid,showAllTestsDetails,dumpAll,OSTab(oss).get()
178  );
179  if(!result) success = false;
180  if(verbose) {
181  if(result) {
182  if(showAllTests)
183  *out << std::endl << ossStore.str();
184  else
185  *out << " : passed!\n";
186  }
187  else {
188  if(showAllTests)
189  *out << std::endl << ossStore.str();
190  else
191  *out << " : failed!\n";
192  }
193  }
194  }
195  }
196  }
197  }
198  }
199 
200  }
201  catch( const std::exception &excpt ) {
202  std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
203  success = false;
204  }
205  catch( ... ) {
206  std::cerr << "*** Caught an unknown exception\n";
207  success = false;
208  }
209 
210  if (verbose) {
211  if(success) *out << "\nCongratulations! All of the tests checked out!\n";
212  else *out << "\nOh no! At least one of the tests failed!\n";
213  }
214 
215  return ( success ? 0 : 1 );
216 }
ERefactorizationPolicy
The policy used on refactoring a matrix.
int main(int argc, char *argv[])
const std::string toString(const EAdjointEpetraOp adjointEpetraOp)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool showAllTests
MatrixTestPacket(std::string _matrixFile, bool _unsymmetric, double _maxFwdError, double _maxError, double _maxResid)
basic_OSTab< char > OSTab
const ERefactorizationPolicy refactorizationPolicyValues[numRefactorizationPolices]
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const int numRefactorizationPolices
const int numSolverTypes
const ESolverType solverTypeValues[numSolverTypes]
const bool supportsUnsymmetric[numSolverTypes]
bool dumpAll
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)