test_belos_thyra_driver.cpp

Go to the documentation of this file.
00001 /*@HEADER
00002 // ***********************************************************************
00003 // 
00004 //        AztecOO: An Object-Oriented Aztec Linear Solver Package 
00005 //                 Copyright (2002) 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 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #include "test_single_aztecoo_thyra_solver.hpp"
00031 #include "Teuchos_CommandLineProcessor.hpp"
00032 #include "Teuchos_ParameterList.hpp"
00033 #include "az_aztec_defs.h"
00034 
00035 struct MatrixTestPacket {
00036   MatrixTestPacket(
00037     std::string  _matrixFile
00038     ,double      _maxFwdError
00039     ,int         _maxIters
00040     ,double      _maxResid
00041     ,double      _maxSolutionError
00042     ,double      _maxSlackErrorFrac
00043     ,int         _maxPrecIters
00044     ,double      _maxPrecResid
00045     ,double      _maxPrecSolutionError
00046     ,double      _maxPrecSlackErrorFrac
00047     )
00048     :matrixFile(_matrixFile)
00049     ,maxFwdError(_maxFwdError)
00050     ,maxIters(_maxIters)
00051     ,maxResid(_maxResid)
00052     ,maxSolutionError(_maxSolutionError)
00053     ,maxSlackErrorFrac(_maxSlackErrorFrac)
00054     ,maxPrecIters(_maxPrecIters)
00055     ,maxPrecResid(_maxPrecResid)
00056     ,maxPrecSolutionError(_maxPrecSolutionError)
00057     ,maxPrecSlackErrorFrac(_maxPrecSlackErrorFrac)
00058     {}
00059   std::string  matrixFile;
00060   double       maxFwdError;
00061   int          maxIters;
00062   double       maxResid;
00063   double       maxSolutionError;
00064   double       maxSlackErrorFrac;
00065   int          maxPrecIters;
00066   double       maxPrecResid;
00067   double       maxPrecSolutionError;
00068   double       maxPrecSlackErrorFrac;
00069 };
00070 
00071 int main(int argc, char* argv[])
00072 {
00073   
00074   using Teuchos::CommandLineProcessor;
00075 
00076   bool result, success = true;
00077   bool verbose = true;
00078 
00079   Teuchos::FancyOStream out(Teuchos::rcp(&std::cout,false));
00080 
00081   try {
00082 
00083     //
00084     // Read options from command-line
00085     //
00086     
00087     std::string    matrixDir              = "";
00088     int            numRandomVectors       = 1;
00089     bool           showAllTests           = false;
00090     bool           showAllTestsDetails    = false;
00091     bool           dumpAll                = false;
00092     std::string    aztecOutputLevel       = "freq";
00093     int            aztecOutputFreq        = 0;
00094 
00095     CommandLineProcessor  clp(false); // Don't throw exceptions
00096     clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" );
00097     clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
00098     clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
00099     clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
00100     clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." );
00101     clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
00102     clp.setOption( "aztec-output-level", &aztecOutputLevel, "Aztec output level (freq,last,summary,warnings,all)" );
00103     clp.setOption( "aztec-output-freq", &aztecOutputFreq, "Aztec output freqency (> 0)" );
00104     CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
00105     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
00106 
00107     TEST_FOR_EXCEPT( matrixDir == "" );
00108 
00109     Teuchos::ParameterList fwdSolveParamList, adjSolveParamList;
00110     if( aztecOutputLevel != "freq" ) {
00111       fwdSolveParamList.set("AZ_output",aztecOutputLevel);
00112       adjSolveParamList.set("AZ_output",aztecOutputLevel);
00113     }
00114     else {
00115       fwdSolveParamList.set("AZ_output",aztecOutputFreq);
00116       adjSolveParamList.set("AZ_output",aztecOutputFreq);
00117     }
00118 
00119     //
00120     // Define the test matrices
00121     //
00122 
00123     const int numTestMatrices = 9;
00124 
00125     typedef MatrixTestPacket MTP;
00126 
00127     // Set up the matices and the tolerances.
00128     // Note, we may need to adjust these for bad platforms ...
00129     const MTP testMatrices[numTestMatrices] =
00130       {
00131         MTP("bcsstk01.mtx"       ,1e-12, 40 , 1e-4, 0.6,      1.0, 20 , 1e-10, 0.5,      1.0)
00132         ,MTP("bcsstk02.mtx"      ,1e-12, 40 , 1e-3, 0.5,      1.0, 2  , 1e-10, 0.5,      1.0)
00133         ,MTP("bcsstk04.mtx"      ,1e-12, 80 , 1e-4, 0.999990, 1.0, 40 , 1e-10, 0.999990, 1.0)
00134         ,MTP("Diagonal.mtx"      ,1e-12, 4  , 1e-6, 1e-14,    1.0, 2  , 1e-10, 1e-14,    1.0)
00135         ,MTP("FourByFour.mtx"    ,1e-12, 4  , 1e-6, 1e-14,    1.0, 2  , 1e-10, 1e-14,    1.0)
00136         ,MTP("KheadK.mtx"        ,1e-12, 8  , 1e-6, 1e-14,    1.0, 2  , 1e-10, 1e-14,    1.0)
00137         ,MTP("KheadSorted.mtx"   ,1e-12, 8  , 1e-6, 1e-14,    1.0, 2  , 1e-10, 1e-14,    1.0)
00138         ,MTP("nos1.mtx"          ,1e-11, 200, 1e-4, 0.6,      1.0, 237, 1e-2,  5.0,      1.0)
00139         ,MTP("nos5.mtx"          ,1e-12, 468, 1e-5, 0.5,      1.0, 468, 1e-10, 0.5,      1.0)
00140       };
00141     //
00142     // Loop through all of the test matrices
00143     //
00144     for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) {
00145       const MatrixTestPacket
00146         mtp = testMatrices[matrix_i];
00147       //
00148       // Do unpreconditioned and preconditioned solves
00149       //
00150       for( int prec_i = 0; prec_i < 2; ++prec_i ) {
00151         if(verbose)
00152           out << std::endl<<matrix_i<<":"<<prec_i<<": Testing, matrixFile=\'"<<mtp.matrixFile<<"\', ";
00153         bool testTranspose;
00154         int    maxIters;
00155         double maxResid;
00156         double maxSolutionError;
00157         double maxSlackErrorFrac;
00158         if(prec_i==0) {
00159           out << "no aztec preconditioning ... ";
00160           fwdSolveParamList.set("AZ_precond","none");
00161           testTranspose = true;
00162           maxIters = mtp.maxIters;
00163           maxResid = mtp.maxResid;
00164           maxSolutionError = mtp.maxSolutionError;
00165           maxSlackErrorFrac = mtp.maxSlackErrorFrac;
00166         }
00167         else {
00168           out << "using aztec preconditioning ... ";
00169           fwdSolveParamList.set("AZ_precond","dom_decomp");
00170           fwdSolveParamList.set("AZ_subdomain_solve","ilu");
00171           testTranspose = false;
00172           maxIters = mtp.maxPrecIters;
00173           maxResid = mtp.maxPrecResid;
00174           maxSolutionError = mtp.maxPrecSolutionError;
00175           maxSlackErrorFrac = mtp.maxPrecSlackErrorFrac;
00176         }
00177         std::ostringstream oss;
00178         Teuchos::FancyOStream fancy_oss(Teuchos::rcp(&oss,false));
00179         result =
00180           Thyra::test_single_aztecoo_thyra_solver(
00181             matrixDir+"/"+mtp.matrixFile,testTranspose,numRandomVectors
00182             ,mtp.maxFwdError,maxIters,maxResid,maxSolutionError
00183             ,showAllTestsDetails,dumpAll,&fwdSolveParamList,&adjSolveParamList,&fancy_oss
00184             );
00185         if(!result) success = false;
00186         if(verbose) {
00187           if(result) {
00188             if(showAllTests)
00189               out << std::endl << oss.str();
00190             else
00191               out << " : passed!\n";
00192           }
00193           else {
00194             if(showAllTests)
00195               out << std::endl << oss.str();
00196             else
00197               out << " : failed!\n";
00198           }
00199         }
00200       }
00201     }
00202 
00203   }
00204   catch( const std::exception &excpt ) {
00205     std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
00206     success = false;
00207   }
00208   catch( ... ) {
00209     std::cerr << "*** Caught an unknown exception\n";
00210     success = false;
00211   }
00212   
00213   if (verbose) {
00214     if(success)  out << "\nCongratulations! All of the tests checked out!\n";
00215     else         out << "\nOh no! At least one of the tests failed!\n";
00216   }
00217 
00218   return ( success ? 0 : 1 );
00219 }

Generated on Thu Sep 18 12:30:21 2008 for Belos Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1