Debian Codegraph @

packages/stratimikos/adapters/amesos/test/test_amesos_thyra_driver.cpp

raw
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
10 #include "test_single_amesos_thyra_solver.hpp"
11 #include "Teuchos_CommandLineProcessor.hpp"
12 #include "Teuchos_GlobalMPISession.hpp"
13 #include "Teuchos_VerboseObject.hpp"
14
15 struct MatrixTestPacket {
16 MatrixTestPacket(std::string _matrixFile, bool _unsymmetric, double _maxFwdError, double _maxError, double _maxResid)
17 :matrixFile(_matrixFile),unsymmetric(_unsymmetric),maxFwdError(_maxFwdError),maxError(_maxError),maxResid(_maxResid) {}
18 std::string matrixFile;
19 bool unsymmetric;
20 double maxFwdError;
21 double maxError;
22 double maxResid;
23 };
24
25 int main(int argc, char* argv[])
26 {
27
28 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
29
30 using Teuchos::CommandLineProcessor;
31 using Teuchos::OSTab;
32
33 bool result, success = true;
34 bool verbose = true;
35
36
37 Teuchos::RCP<Teuchos::FancyOStream>
38 out = Teuchos::VerboseObjectBase::getDefaultOStream();
39
40 try {
41
42 //
43 // Read options from command-line
44 //
45
46 std::string matrixDir = ".";
47 bool testTranspose = true;
48 int numRandomVectors = 1;
49 bool showAllTests = false;
50 bool showAllTestsDetails = false;
51 bool dumpAll = false;
52
53 CommandLineProcessor clp;
54 clp.throwExceptions(false);
55 clp.addOutputSetupOptions(true);
56 clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" );
57 clp.setOption( "test-transpose", "no-test-transpose", &testTranspose, "Test the transpose solve or not." );
58 clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
59 clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
60 clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
61 clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." );
62 clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
63 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
64 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
65
66 TEUCHOS_TEST_FOR_EXCEPT( matrixDir == "" );
67
68 //
69 // Define the test matrices
70 //
71
72 const int numTestMatrices = 9;
73
74 typedef MatrixTestPacket MTP;
75
76 // Set up the matices and the tolerances.
77 // Note, we may need to adjust these for bad platforms ...
78 const MTP testMatrices[numTestMatrices] =
79 {
80 MTP("bcsstk01.mtx",false,1e-12,1e-12,1e-12)
81 ,MTP("bcsstk02.mtx",false,1e-12,1e-12,1e-12)
82 ,MTP("bcsstk04.mtx",false,1e-12,1e-10,1e-12)
83 ,MTP("Diagonal.mtx",false,1e-12,1e-12,1e-12)
84 ,MTP("FourByFour.mtx",true,1e-12,1e-12,1e-12)
85 ,MTP("KheadK.mtx",false,1e-12,1e-12,1e-12)
86 ,MTP("KheadSorted.mtx",false,1e-12,1e-12,1e-12)
87 ,MTP("nos1.mtx",false,1e-11,1e-10,1e-12)
88 ,MTP("nos5.mtx",false,1e-12,1e-12,1e-12)
89 };
90 //
91 // Loop through all of the test matrices
92 //
93 for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) {
94 const MatrixTestPacket
95 mtp = testMatrices[matrix_i];
96 //
97 // Loop through all of the solvers
98 //
99 for( int solver_i = 0; solver_i < Thyra::Amesos::numSolverTypes; ++solver_i ) {
100 const Thyra::Amesos::ESolverType
101 solverType = Thyra::Amesos::solverTypeValues[solver_i];
102
103 // bug 1902 - Amesos_Superlu fails on bcsstk01.mtx
104 // bug 1903 - Amesos_Superlu fails on four matrices,
105 // when called from the thyra test
106 //
107 bool BadMatrixForSuperlu =
108 mtp.matrixFile == "bcsstk01.mtx" // bug 1902
109 || mtp.matrixFile == "bcsstk04.mtx" // bug 1903
110 || mtp.matrixFile == "KheadK.mtx" // bug 1903
111 || mtp.matrixFile == "KheadSorted.mtx" // bug 1903
112 || mtp.matrixFile == "nos1.mtx" ; // bug 1903
113 //
114 // Toggle the refactorization options
115 //
116 for( int factorizationPolicy_i = 0; factorizationPolicy_i < Thyra::Amesos::numRefactorizationPolices; ++factorizationPolicy_i ) {
117 const Thyra::Amesos::ERefactorizationPolicy
118 refactorizationPolicy = Thyra::Amesos::refactorizationPolicyValues[factorizationPolicy_i];
119 if(verbose)
120 *out
121 << std::endl<<matrix_i<<"."<<solver_i<<"."<<factorizationPolicy_i<<": "
122 << "Testing, matrixFile=\'"<<mtp.matrixFile<<"\', solverType=\'"<<toString(solverType)<<"\', refactorizationPolicy=\'"<<toString(refactorizationPolicy)<<"\' ...";
123 if( mtp.unsymmetric && !Thyra::Amesos::supportsUnsymmetric[solver_i] ) {
124 *out << " : Skipping since unsymmetric and not supported!\n";
125 }
126 else {
127 // bug 1902 and bug 1903
128 std::string StrSolverType = toString(solverType) ;
129 std::string StrSuperlu = "Superlu";
130 if ( StrSolverType==StrSuperlu && BadMatrixForSuperlu ) {
131 *out << " : Skipping since Superlu fails on this matrix!\n";
132 }
133 else {
134 std::ostringstream ossStore;
135 Teuchos::RCP<Teuchos::FancyOStream>
136 oss = Teuchos::rcp(new Teuchos::FancyOStream(Teuchos::rcp(&ossStore,false)));
137 Teuchos::ParameterList amesosLOWSFPL;
138 amesosLOWSFPL.set("Solver Type",toString(solverType));
139 amesosLOWSFPL.set("Refactorization Policy",toString(refactorizationPolicy));
140 result =
141 Thyra::test_single_amesos_thyra_solver(
142 matrixDir+"/"+mtp.matrixFile,&amesosLOWSFPL,testTranspose,numRandomVectors
143 ,mtp.maxFwdError,mtp.maxError,mtp.maxResid,showAllTestsDetails,dumpAll,OSTab(oss).get()
144 );
145 if(!result) success = false;
146 if(verbose) {
147 if(result) {
148 if(showAllTests)
149 *out << std::endl << ossStore.str();
150 else
151 *out << " : passed!\n";
152 }
153 else {
154 if(showAllTests)
155 *out << std::endl << ossStore.str();
156 else
157 *out << " : failed!\n";
158 }
159 }
160 }
161 }
162 }
163 }
164 }
165
166 }
167 catch( const std::exception &excpt ) {
168 std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
169 success = false;
170 }
171 catch( ... ) {
172 std::cerr << "*** Caught an unknown exception\n";
173 success = false;
174 }
175
176 if (verbose) {
177 if(success) *out << "\nCongratulations! All of the tests checked out!\n";
178 else *out << "\nOh no! At least one of the tests failed!\n";
179 }
180
181 return ( success ? 0 : 1 );
182 }