Amesos Package Browser (Single Doxygen Collection) Development
Amesos_Performance.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                Amesos: Direct Sparse Solver Package
00005 //                 Copyright (2004) 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 //  Amesos_TestDriver 
00031 //
00032 //  usage: 
00033 //     Amesos_TestDriver.exe Solver InputMatrix Transpose MaxTimeIncr MaxErrorIncr MaxError MaxResid 
00034 //     Where solver is:  SuperLU, SuperLUdist, SuperLUdist2, 
00035 //       UMFPACK, SPOOLES, DSCPACK, DSCPACKOLD, KLU, 
00036 //       SPOOLESERIAL, MUMPS, SUPERLU, SCALAPACK or AZTEC 
00037 //     special is, at present, only used in SuperLU, where 0 means dgssv
00038 //     and 1 means dgssvx 
00039 //  examples:
00040 //      Solver - Amesos class name
00041 //      InputMatrix - matrix_market file name 
00042 //      Transpose - "Trans" or "No Trans"
00043 //      Maximum increase in execution time (typically 0.10 to 0.20) 
00044 //      Maximum increase in error (typically 2 to 10) 
00045 //      MaxSymFactTime - Time for one symbolic factorization 
00046 //      MaxNumFacttime - Time for one numeric factorization
00047 //      MaxSolveTime - Time for a single solve 
00048 //      MaxBlockSolveTime - Per vector time for 16 blocked right hand sides
00049 //      MaxRefactTime - Time for a refactorization
00050 //      MaxMemory - Maximum memory used 
00051 //      MaxError - Maximum scaled error 
00052 //      MaxResid - Maximum scaled residual
00053 //
00054 //  output:  
00055 //    AmesosPerf.log (append) 
00056 //    standard out 
00057 //
00058 //  exits with 0 if test completed (does not imply that the test passed)
00059 //  exits with -1 if command line options or file permissions are wrong 
00060 //
00061 #include "Amesos_ConfigDefs.h"
00062 
00063 #include "Teuchos_CommandLineProcessor.hpp"
00064 #include "Teuchos_Version.hpp"
00065 
00066 #ifdef HAVE_MPI
00067 #include "mpi.h"
00068 #endif
00069 
00070 // Enum for the speed option
00071 enum ESpeed { SPEED_SLOW=-1, SPEED_MEDIUM=0, SPEED_FAST=+1 };
00072 
00073 int main(int argc, char* argv[])
00074 {
00075 #ifdef HAVE_MPI
00076   /* initialize MPI if we are running in parallel */
00077   MPI_Init(&argc, &argv);
00078   int procRank = -1;
00079   MPI_Comm_rank( MPI_COMM_WORLD, &procRank );
00080   if ( procRank == 0 )
00081     std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
00082 #else
00083   std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl;
00084 #endif
00085 
00086   // Creating an empty command line processor looks like:
00087   Teuchos::CommandLineProcessor My_CLP;
00088 
00089   /* To set and option, it must be given a name and default value.  Additionally,
00090      each option can be given a help string.  Although it is not necessary, a help
00091      string aids a users comprehension of the acceptable command line arguments.
00092      Some examples of setting command line options are:
00093   */
00094   // Set an integer command line option.
00095   int NumIters = 1550;
00096   My_CLP.setOption("iterations", &NumIters, "Number of iterations");
00097   // Set a double-precision command line option.
00098   double Tolerance = 1e-10;    
00099   My_CLP.setOption("tolerance", &Tolerance, "Tolerance");
00100   // Set a string command line option.
00101   std::string Solver = "GMRES";
00102   My_CLP.setOption("solver", &Solver, "Linear solver");
00103   // Set a boolean command line option.    
00104   bool Precondition;
00105   My_CLP.setOption("precondition","no-precondition",
00106        &Precondition,"Preconditioning flag");
00107   // Set an enumeration command line option
00108   const int    num_speed_values  = 3;
00109   const ESpeed speed_opt_values[] = { SPEED_SLOW, SPEED_MEDIUM, SPEED_FAST };
00110   const char*  speed_opt_names[]  = { "slow",     "medium",     "fast"     };
00111   ESpeed       Speed = SPEED_MEDIUM;
00112   My_CLP.setOption(
00113     "speed", &Speed,
00114     num_speed_values, speed_opt_values, speed_opt_names,
00115     "Speed of our solver"
00116     );
00117 
00118   /* There are also two methods that control the behavior of the
00119      command line processor.  First, for the command line processor to
00120      allow an unrecognized a command line option to be ignored (and
00121      only have a warning printed), use:
00122   */
00123   My_CLP.recogniseAllOptions(true);
00124   
00125   /* Second, by default, if the parser finds a command line option it
00126      doesn't recognize or finds the --help option, it will throw an
00127      exception.  If you want prevent a command line processor from
00128      throwing an exception (which is important in this program since
00129      we don't have an try/catch around this) when it encounters a
00130      unrecognized option or help is printed, use:
00131   */
00132   My_CLP.throwExceptions(false);
00133 
00134   /* We now parse the command line where argc and argv are passed to
00135      the parse method.  Note that since we have turned off exception
00136      throwing above we had better grab the return argument so that
00137      we can see what happened and act accordingly.
00138   */
00139   Teuchos::CommandLineProcessor::EParseCommandLineReturn
00140     parseReturn= My_CLP.parse( argc, argv );
00141   if( parseReturn == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED ) {
00142 #ifdef HAVE_MPI
00143     MPI_Finalize();
00144 #endif
00145     return 0;
00146   }
00147   if( parseReturn != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL   ) {
00148 #ifdef HAVE_MPI 
00149     MPI_Finalize();
00150 #endif  
00151     return 1; // Error!
00152   }
00153   // Here is where you would use these command line arguments but for this example program
00154   // we will just print the help message with the new values of the command-line arguments.
00155 #ifdef HAVE_MPI
00156   if (procRank == 0)
00157 #endif
00158   std::cout << "\nPrinting help message with new values of command-line arguments ...\n\n";
00159   My_CLP.printHelpMessage(argv[0],std::cout);
00160 
00161   // Now we will print the option values
00162 #ifdef HAVE_MPI
00163   if (procRank == 0) {
00164 #endif
00165   std::cout << "\nPrinting user options after parsing ...\n\n";
00166   std::cout << "NumIters     = " << NumIters << std::endl;
00167   std::cout << "Tolerance    = " << Tolerance << std::endl;
00168   std::cout << "Solver       = \"" << Solver << "\"\n";
00169   std::cout << "Precondition = " << Precondition << std::endl;
00170   std::cout << "Speed        = " << Speed << std::endl;
00171 #ifdef HAVE_MPI
00172   }
00173   /* finalize MPI if we are running in parallel */
00174   MPI_Finalize();
00175 #endif
00176 
00177   return 0;
00178 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines