|
Stratimikos Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Stratimikos: Thyra-based strategies for linear solvers 00005 // Copyright (2006) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include "test_single_aztecoo_thyra_solver.hpp" 00043 #include "Teuchos_GlobalMPISession.hpp" 00044 #include "Teuchos_CommandLineProcessor.hpp" 00045 #include "Teuchos_ParameterList.hpp" 00046 #include "Teuchos_StandardCatchMacros.hpp" 00047 #include "az_aztec_defs.h" 00048 00049 struct MatrixTestPacket { 00050 MatrixTestPacket( 00051 std::string _matrixFile 00052 ,double _maxFwdError 00053 ,int _maxIters 00054 ,double _maxResid 00055 ,double _maxSolutionError 00056 ,double _maxSlackErrorFrac 00057 ,int _maxPrecIters 00058 ,double _maxPrecResid 00059 ,double _maxPrecSolutionError 00060 ,double _maxPrecSlackErrorFrac 00061 ) 00062 :matrixFile(_matrixFile) 00063 ,maxFwdError(_maxFwdError) 00064 ,maxIters(_maxIters) 00065 ,maxResid(_maxResid) 00066 ,maxSolutionError(_maxSolutionError) 00067 ,maxSlackErrorFrac(_maxSlackErrorFrac) 00068 ,maxPrecIters(_maxPrecIters) 00069 ,maxPrecResid(_maxPrecResid) 00070 ,maxPrecSolutionError(_maxPrecSolutionError) 00071 ,maxPrecSlackErrorFrac(_maxPrecSlackErrorFrac) 00072 {} 00073 std::string matrixFile; 00074 double maxFwdError; 00075 int maxIters; 00076 double maxResid; 00077 double maxSolutionError; 00078 double maxSlackErrorFrac; 00079 int maxPrecIters; 00080 double maxPrecResid; 00081 double maxPrecSolutionError; 00082 double maxPrecSlackErrorFrac; 00083 }; 00084 00085 int main(int argc, char* argv[]) 00086 { 00087 00088 Teuchos::GlobalMPISession mpiSession(&argc,&argv); 00089 00090 using Teuchos::CommandLineProcessor; 00091 00092 bool result, success = true; 00093 bool verbose = true; 00094 00095 Teuchos::FancyOStream out(Teuchos::rcp(&std::cout,false)); 00096 00097 try { 00098 00099 // 00100 // Read options from command-line 00101 // 00102 00103 std::string matrixDir = "."; 00104 int numRandomVectors = 1; 00105 bool showAllTests = false; 00106 bool showAllTestsDetails = false; 00107 bool dumpAll = false; 00108 std::string aztecOutputLevel = "freq"; 00109 int aztecOutputFreq = 0; 00110 00111 CommandLineProcessor clp(false); // Don't throw exceptions 00112 clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" ); 00113 clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." ); 00114 clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." ); 00115 clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." ); 00116 clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." ); 00117 clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." ); 00118 clp.setOption( "aztec-output-level", &aztecOutputLevel, "Aztec output level (freq,last,summary,warnings,all)" ); 00119 clp.setOption( "aztec-output-freq", &aztecOutputFreq, "Aztec output freqency (> 0)" ); 00120 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv); 00121 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return; 00122 00123 TEUCHOS_TEST_FOR_EXCEPT( matrixDir == "" ); 00124 00125 // 00126 // Define the test matrices 00127 // 00128 00129 const int numTestMatrices = 9; 00130 00131 typedef MatrixTestPacket MTP; 00132 00133 // Set up the matices and the tolerances. 00134 // Note, we may need to adjust these for bad platforms ... 00135 const MTP testMatrices[numTestMatrices] = 00136 { 00137 MTP("bcsstk01.mtx" ,1e-12, 40 , 1e-4, 0.6, 1.0, 20 , 1e-10, 0.5, 1.0) 00138 ,MTP("bcsstk02.mtx" ,1e-12, 40 , 1e-3, 0.5, 1.0, 2 , 1e-10, 0.5, 1.0) 00139 ,MTP("bcsstk04.mtx" ,1e-12, 80 , 1e-4, 0.999990, 1.0, 40 , 1e-10, 0.999990, 1.0) 00140 ,MTP("Diagonal.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0) 00141 ,MTP("FourByFour.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0) 00142 ,MTP("KheadK.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0) 00143 ,MTP("KheadSorted.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0) 00144 ,MTP("nos1.mtx" ,1e-11, 200, 1e-4, 0.8, 1.0, 237, 1e-2, 5.0, 1.0) 00145 ,MTP("nos5.mtx" ,1e-12, 468, 1e-5, 0.5, 1.0, 468, 1e-10, 0.5, 1.0) 00146 }; 00147 // 00148 // Loop through all of the test matrices 00149 // 00150 for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) { 00151 const MatrixTestPacket 00152 mtp = testMatrices[matrix_i]; 00153 // 00154 // Do unpreconditioned and preconditioned solves 00155 // 00156 for( int prec_i = 0; prec_i < 2; ++prec_i ) { 00157 if(verbose) 00158 out << std::endl<<matrix_i<<":"<<prec_i<<": Testing, matrixFile=\'"<<mtp.matrixFile<<"\', "; 00159 bool testTranspose; 00160 double maxResid; 00161 double maxSolutionError; 00162 double maxSlackErrorFrac; 00163 Teuchos::ParameterList 00164 paramList("AztecOOLinearOpWithSolveFactory"); 00165 Teuchos::ParameterList 00166 &fwdSolvePL = paramList.sublist("Forward Solve"), 00167 &adjSolvePL = paramList.sublist("Adjoint Solve"); 00168 Teuchos::ParameterList 00169 &fwdAztecOOPL = fwdSolvePL.sublist("AztecOO Settings"), 00170 &adjAztecOOPL = adjSolvePL.sublist("AztecOO Settings"); 00171 if( aztecOutputLevel != "freq" ) { 00172 fwdAztecOOPL.set("Output Frequency",aztecOutputLevel); 00173 adjAztecOOPL.set("Output Frequency",aztecOutputLevel); 00174 } 00175 else { 00176 fwdAztecOOPL.set("Output Frequency",aztecOutputFreq); 00177 adjAztecOOPL.set("Output Frequency",aztecOutputFreq); 00178 } 00179 if(prec_i==0) { 00180 out << "no aztec preconditioning ... "; 00181 fwdAztecOOPL.set("Aztec Preconditioner","none"); 00182 testTranspose = true; 00183 fwdSolvePL.set("Max Iterations",mtp.maxIters); 00184 adjSolvePL.set("Max Iterations",mtp.maxIters); 00185 maxResid = mtp.maxResid; 00186 maxSolutionError = mtp.maxSolutionError; 00187 maxSlackErrorFrac = mtp.maxSlackErrorFrac; 00188 } 00189 else { 00190 out << "using aztec preconditioning ... "; 00191 fwdAztecOOPL.set("Aztec Preconditioner","ilu"); 00192 testTranspose = false; 00193 fwdSolvePL.set("Max Iterations",mtp.maxPrecIters); 00194 adjSolvePL.set("Max Iterations",mtp.maxPrecIters); 00195 maxResid = mtp.maxPrecResid; 00196 maxSolutionError = mtp.maxPrecSolutionError; 00197 maxSlackErrorFrac = mtp.maxPrecSlackErrorFrac; 00198 } 00199 std::ostringstream oss; 00200 Teuchos::FancyOStream fancy_oss(Teuchos::rcp(&oss,false)); 00201 result = 00202 Thyra::test_single_aztecoo_thyra_solver( 00203 matrixDir+"/"+mtp.matrixFile,testTranspose,numRandomVectors 00204 ,mtp.maxFwdError,maxResid,maxSolutionError 00205 ,showAllTestsDetails,dumpAll,¶mList,&fancy_oss 00206 ); 00207 if(!result) success = false; 00208 if(verbose) { 00209 if(result) { 00210 if(showAllTests) 00211 out << std::endl << oss.str(); 00212 else 00213 out << " : passed!\n"; 00214 } 00215 else { 00216 if(showAllTests) 00217 out << std::endl << oss.str(); 00218 else 00219 out << " : failed!\n"; 00220 } 00221 } 00222 } 00223 } 00224 00225 } 00226 TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); 00227 00228 if (verbose) { 00229 if(success) out << "\nCongratulations! All of the tests checked out!\n"; 00230 else out << "\nOh no! At least one of the tests failed!\n"; 00231 } 00232 00233 return ( success ? EXIT_SUCCESS : EXIT_FAILURE ); 00234 }
1.7.6.1