00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 */
00029
00030 #include "test_single_aztecoo_thyra_solver.hpp"
00031 #include "Teuchos_GlobalMPISession.hpp"
00032 #include "Teuchos_CommandLineProcessor.hpp"
00033 #include "Teuchos_ParameterList.hpp"
00034 #include "az_aztec_defs.h"
00035
00036 struct MatrixTestPacket {
00037 MatrixTestPacket(
00038 std::string _matrixFile
00039 ,double _maxFwdError
00040 ,int _maxIters
00041 ,double _maxResid
00042 ,double _maxSolutionError
00043 ,double _maxSlackErrorFrac
00044 ,int _maxPrecIters
00045 ,double _maxPrecResid
00046 ,double _maxPrecSolutionError
00047 ,double _maxPrecSlackErrorFrac
00048 )
00049 :matrixFile(_matrixFile)
00050 ,maxFwdError(_maxFwdError)
00051 ,maxIters(_maxIters)
00052 ,maxResid(_maxResid)
00053 ,maxSolutionError(_maxSolutionError)
00054 ,maxSlackErrorFrac(_maxSlackErrorFrac)
00055 ,maxPrecIters(_maxPrecIters)
00056 ,maxPrecResid(_maxPrecResid)
00057 ,maxPrecSolutionError(_maxPrecSolutionError)
00058 ,maxPrecSlackErrorFrac(_maxPrecSlackErrorFrac)
00059 {}
00060 std::string matrixFile;
00061 double maxFwdError;
00062 int maxIters;
00063 double maxResid;
00064 double maxSolutionError;
00065 double maxSlackErrorFrac;
00066 int maxPrecIters;
00067 double maxPrecResid;
00068 double maxPrecSolutionError;
00069 double maxPrecSlackErrorFrac;
00070 };
00071
00072 int main(int argc, char* argv[])
00073 {
00074
00075 Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00076
00077 using Teuchos::CommandLineProcessor;
00078
00079 bool result, success = true;
00080 bool verbose = true;
00081
00082 Teuchos::FancyOStream out(Teuchos::rcp(&std::cout,false));
00083
00084 try {
00085
00086
00087
00088
00089
00090 std::string matrixDir = "";
00091 int numRandomVectors = 1;
00092 bool showAllTests = false;
00093 bool showAllTestsDetails = false;
00094 bool dumpAll = false;
00095 std::string aztecOutputLevel = "freq";
00096 int aztecOutputFreq = 0;
00097
00098 CommandLineProcessor clp(false);
00099 clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" );
00100 clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
00101 clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
00102 clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
00103 clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." );
00104 clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
00105 clp.setOption( "aztec-output-level", &aztecOutputLevel, "Aztec output level (freq,last,summary,warnings,all)" );
00106 clp.setOption( "aztec-output-freq", &aztecOutputFreq, "Aztec output freqency (> 0)" );
00107 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
00108 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
00109
00110 TEST_FOR_EXCEPT( matrixDir == "" );
00111
00112
00113
00114
00115
00116 const int numTestMatrices = 9;
00117
00118 typedef MatrixTestPacket MTP;
00119
00120
00121
00122 const MTP testMatrices[numTestMatrices] =
00123 {
00124 MTP("bcsstk01.mtx" ,1e-12, 40 , 1e-4, 0.6, 1.0, 20 , 1e-10, 0.5, 1.0)
00125 ,MTP("bcsstk02.mtx" ,1e-12, 40 , 1e-3, 0.5, 1.0, 2 , 1e-10, 0.5, 1.0)
00126 ,MTP("bcsstk04.mtx" ,1e-12, 80 , 1e-4, 0.999990, 1.0, 40 , 1e-10, 0.999990, 1.0)
00127 ,MTP("Diagonal.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
00128 ,MTP("FourByFour.mtx" ,1e-12, 4 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
00129 ,MTP("KheadK.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
00130 ,MTP("KheadSorted.mtx" ,1e-12, 8 , 1e-6, 1e-14, 1.0, 2 , 1e-10, 1e-14, 1.0)
00131 ,MTP("nos1.mtx" ,1e-11, 200, 1e-4, 0.6, 1.0, 237, 1e-2, 5.0, 1.0)
00132 ,MTP("nos5.mtx" ,1e-12, 468, 1e-5, 0.5, 1.0, 468, 1e-10, 0.5, 1.0)
00133 };
00134
00135
00136
00137 for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) {
00138 const MatrixTestPacket
00139 mtp = testMatrices[matrix_i];
00140
00141
00142
00143 for( int prec_i = 0; prec_i < 2; ++prec_i ) {
00144 if(verbose)
00145 out << std::endl<<matrix_i<<":"<<prec_i<<": Testing, matrixFile=\'"<<mtp.matrixFile<<"\', ";
00146 bool testTranspose;
00147 double maxResid;
00148 double maxSolutionError;
00149 double maxSlackErrorFrac;
00150 Teuchos::ParameterList
00151 paramList("AztecOOLinearOpWithSolveFactory");
00152 Teuchos::ParameterList
00153 &fwdSolvePL = paramList.sublist("Forward Solve"),
00154 &adjSolvePL = paramList.sublist("Adjoint Solve");
00155 Teuchos::ParameterList
00156 &fwdAztecOOPL = fwdSolvePL.sublist("AztecOO"),
00157 &adjAztecOOPL = adjSolvePL.sublist("AztecOO");
00158 if( aztecOutputLevel != "freq" ) {
00159 fwdAztecOOPL.set("Output Frequency",aztecOutputLevel);
00160 adjAztecOOPL.set("Output Frequency",aztecOutputLevel);
00161 }
00162 else {
00163 fwdAztecOOPL.set("Output Frequency",aztecOutputFreq);
00164 adjAztecOOPL.set("Output Frequency",aztecOutputFreq);
00165 }
00166 if(prec_i==0) {
00167 out << "no aztec preconditioning ... ";
00168 fwdAztecOOPL.set("Aztec Preconditioner","none");
00169 testTranspose = true;
00170 fwdSolvePL.set("Max Iterations",mtp.maxIters);
00171 adjSolvePL.set("Max Iterations",mtp.maxIters);
00172 maxResid = mtp.maxResid;
00173 maxSolutionError = mtp.maxSolutionError;
00174 maxSlackErrorFrac = mtp.maxSlackErrorFrac;
00175 }
00176 else {
00177 out << "using aztec preconditioning ... ";
00178 fwdAztecOOPL.set("Aztec Preconditioner","ilu");
00179 testTranspose = false;
00180 fwdSolvePL.set("Max Iterations",mtp.maxPrecIters);
00181 adjSolvePL.set("Max Iterations",mtp.maxPrecIters);
00182 maxResid = mtp.maxPrecResid;
00183 maxSolutionError = mtp.maxPrecSolutionError;
00184 maxSlackErrorFrac = mtp.maxPrecSlackErrorFrac;
00185 }
00186 std::ostringstream oss;
00187 Teuchos::FancyOStream fancy_oss(Teuchos::rcp(&oss,false));
00188 result =
00189 Thyra::test_single_aztecoo_thyra_solver(
00190 matrixDir+"/"+mtp.matrixFile,testTranspose,numRandomVectors
00191 ,mtp.maxFwdError,maxResid,maxSolutionError
00192 ,showAllTestsDetails,dumpAll,¶mList,&fancy_oss
00193 );
00194 if(!result) success = false;
00195 if(verbose) {
00196 if(result) {
00197 if(showAllTests)
00198 out << std::endl << oss.str();
00199 else
00200 out << " : passed!\n";
00201 }
00202 else {
00203 if(showAllTests)
00204 out << std::endl << oss.str();
00205 else
00206 out << " : failed!\n";
00207 }
00208 }
00209 }
00210 }
00211
00212 }
00213 catch( const std::exception &excpt ) {
00214 std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
00215 success = false;
00216 }
00217 catch( ... ) {
00218 std::cerr << "*** Caught an unknown exception\n";
00219 success = false;
00220 }
00221
00222 if (verbose) {
00223 if(success) out << "\nCongratulations! All of the tests checked out!\n";
00224 else out << "\nOh no! At least one of the tests failed!\n";
00225 }
00226
00227 return ( success ? 0 : 1 );
00228 }