Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
test_amesos_thyra_driver.cpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 //         Stratimikos: Thyra-based strategies for linear solvers
00006 //                Copyright (2006) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00039 // 
00040 // ***********************************************************************
00041 // @HEADER
00042 */
00043 
00044 #include "test_single_amesos_thyra_solver.hpp"
00045 #include "Teuchos_CommandLineProcessor.hpp"
00046 #include "Teuchos_GlobalMPISession.hpp"
00047 #include "Teuchos_VerboseObject.hpp"
00048 
00049 struct MatrixTestPacket {
00050   MatrixTestPacket(std::string  _matrixFile, bool _unsymmetric, double _maxFwdError, double _maxError, double _maxResid)
00051     :matrixFile(_matrixFile),unsymmetric(_unsymmetric),maxFwdError(_maxFwdError),maxError(_maxError),maxResid(_maxResid) {}
00052   std::string  matrixFile;
00053   bool         unsymmetric;
00054   double       maxFwdError;
00055   double       maxError;
00056   double       maxResid;
00057 };
00058 
00059 int main(int argc, char* argv[])
00060 {
00061 
00062   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00063   
00064   using Teuchos::CommandLineProcessor;
00065   using Teuchos::OSTab;
00066 
00067   bool result, success = true;
00068   bool verbose = true;
00069 
00070 
00071   Teuchos::RCP<Teuchos::FancyOStream>
00072     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00073 
00074   try {
00075 
00076     //
00077     // Read options from command-line
00078     //
00079     
00080     std::string    matrixDir              = ".";
00081     bool           testTranspose          = true;
00082     int            numRandomVectors       = 1;
00083     bool           showAllTests           = false;
00084     bool           showAllTestsDetails    = false;
00085     bool           dumpAll                = false;
00086 
00087     CommandLineProcessor  clp;
00088     clp.throwExceptions(false);
00089     clp.addOutputSetupOptions(true);
00090     clp.setOption( "matrix-dir", &matrixDir, "Base directory for the test matrices" );
00091     clp.setOption( "test-transpose", "no-test-transpose", &testTranspose, "Test the transpose solve or not." );
00092     clp.setOption( "num-random-vectors", &numRandomVectors, "Number of times a test is performed with different random vectors." );
00093     clp.setOption( "verbose", "quiet", &verbose, "Set if output is printed or not." );
00094     clp.setOption( "show-all-tests", "no-show-all-tests", &showAllTests, "Set if all the tests are shown or not." );
00095     clp.setOption( "show-all-tests-details", "no-show-all-tests-details", &showAllTestsDetails, "Set if all the details of the tests are shown or not." );
00096     clp.setOption( "dump-all", "no-dump-all", &dumpAll, "Determines if vectors are printed or not." );
00097     CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
00098     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
00099 
00100     TEUCHOS_TEST_FOR_EXCEPT( matrixDir == "" );
00101 
00102     //
00103     // Define the test matrices
00104     //
00105 
00106     const int numTestMatrices = 9;
00107 
00108     typedef MatrixTestPacket MTP;
00109 
00110     // Set up the matices and the tolerances.
00111     // Note, we may need to adjust these for bad platforms ...
00112     const MTP testMatrices[numTestMatrices] =
00113       {
00114         MTP("bcsstk01.mtx",false,1e-12,1e-12,1e-12)
00115         ,MTP("bcsstk02.mtx",false,1e-12,1e-12,1e-12)
00116         ,MTP("bcsstk04.mtx",false,1e-12,1e-10,1e-12)
00117         ,MTP("Diagonal.mtx",false,1e-12,1e-12,1e-12)
00118         ,MTP("FourByFour.mtx",true,1e-12,1e-12,1e-12)
00119         ,MTP("KheadK.mtx",false,1e-12,1e-12,1e-12)
00120         ,MTP("KheadSorted.mtx",false,1e-12,1e-12,1e-12)
00121         ,MTP("nos1.mtx",false,1e-11,1e-10,1e-12)
00122         ,MTP("nos5.mtx",false,1e-12,1e-12,1e-12)
00123       };
00124     //
00125     // Loop through all of the test matrices
00126     //
00127     for( int matrix_i = 0; matrix_i < numTestMatrices; ++matrix_i ) {
00128       const MatrixTestPacket
00129         mtp = testMatrices[matrix_i];
00130       //
00131       // Loop through all of the solvers
00132       //
00133       for( int solver_i = 0; solver_i < Thyra::Amesos::numSolverTypes; ++solver_i ) {
00134         const Thyra::Amesos::ESolverType
00135           solverType = Thyra::Amesos::solverTypeValues[solver_i];
00136 
00137         //  bug 1902 - Amesos_Superlu fails on bcsstk01.mtx
00138         //  bug 1903 - Amesos_Superlu fails on four matrices,
00139         //             when called from the thyra test
00140         //
00141         bool BadMatrixForSuperlu = 
00142           mtp.matrixFile == "bcsstk01.mtx" // bug 1902 
00143           || mtp.matrixFile == "bcsstk04.mtx" // bug 1903 
00144           || mtp.matrixFile == "KheadK.mtx" // bug 1903 
00145           || mtp.matrixFile == "KheadSorted.mtx" // bug 1903 
00146           || mtp.matrixFile == "nos1.mtx" ; // bug 1903 
00147         //
00148         // Toggle the refactorization options
00149         //
00150         for( int factorizationPolicy_i = 0; factorizationPolicy_i < Thyra::Amesos::numRefactorizationPolices;  ++factorizationPolicy_i ) {
00151           const Thyra::Amesos::ERefactorizationPolicy
00152             refactorizationPolicy = Thyra::Amesos::refactorizationPolicyValues[factorizationPolicy_i];
00153           if(verbose)
00154             *out
00155               << std::endl<<matrix_i<<"."<<solver_i<<"."<<factorizationPolicy_i<<": "
00156               << "Testing, matrixFile=\'"<<mtp.matrixFile<<"\', solverType=\'"<<toString(solverType)<<"\', refactorizationPolicy=\'"<<toString(refactorizationPolicy)<<"\' ..."; 
00157           if( mtp.unsymmetric && !Thyra::Amesos::supportsUnsymmetric[solver_i] ) {
00158             *out << " : Skipping since unsymmetric and not supported!\n";
00159           }
00160           else {
00161             //  bug 1902 and bug 1903  
00162             std::string StrSolverType = toString(solverType) ; 
00163             std::string StrSuperlu = "Superlu";
00164             if ( StrSolverType==StrSuperlu && BadMatrixForSuperlu ) {
00165               *out << " : Skipping since Superlu fails on this matrix!\n";
00166             }
00167             else {
00168               std::ostringstream ossStore;
00169               Teuchos::RCP<Teuchos::FancyOStream>
00170                 oss = Teuchos::rcp(new Teuchos::FancyOStream(Teuchos::rcp(&ossStore,false)));
00171               Teuchos::ParameterList amesosLOWSFPL;
00172               amesosLOWSFPL.set("Solver Type",toString(solverType));
00173               amesosLOWSFPL.set("Refactorization Policy",toString(refactorizationPolicy));
00174               result =
00175                 Thyra::test_single_amesos_thyra_solver(
00176                   matrixDir+"/"+mtp.matrixFile,&amesosLOWSFPL,testTranspose,numRandomVectors
00177                   ,mtp.maxFwdError,mtp.maxError,mtp.maxResid,showAllTestsDetails,dumpAll,OSTab(oss).get()
00178                   );
00179               if(!result) success = false;
00180               if(verbose) {
00181                 if(result) {
00182                   if(showAllTests)
00183                     *out << std::endl << ossStore.str();
00184                   else
00185                     *out << " : passed!\n";
00186                 }
00187                 else {
00188                   if(showAllTests)
00189                     *out << std::endl << ossStore.str();
00190                   else
00191                     *out << " : failed!\n";
00192                 }
00193               }
00194             }
00195           }
00196         }
00197       }
00198     }
00199     
00200   }
00201   catch( const std::exception &excpt ) {
00202     std::cerr << "*** Caught standard exception : " << excpt.what() << std::endl;
00203     success = false;
00204   }
00205   catch( ... ) {
00206     std::cerr << "*** Caught an unknown exception\n";
00207     success = false;
00208   }
00209   
00210   if (verbose) {
00211     if(success)  *out << "\nCongratulations! All of the tests checked out!\n";
00212     else         *out << "\nOh no! At least one of the tests failed!\n";
00213   }
00214 
00215   return ( success ? 0 : 1 );
00216 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines