00001 #include "Teuchos_CommandLineProcessor.hpp"
00002 #include "Teuchos_GlobalMPISession.hpp"
00003 #include "Teuchos_oblackholestream.hpp"
00004 #include "Teuchos_StandardCatchMacros.hpp"
00005 #include "Teuchos_Version.hpp"
00006
00007
00008 enum ESpeed { SPEED_SLOW=-1, SPEED_MEDIUM=0, SPEED_FAST=+1 };
00009
00010 int main(int argc, char* argv[])
00011 {
00012 Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00013 const int procRank = Teuchos::GlobalMPISession::getRank();
00014
00015 Teuchos::oblackholestream blackhole;
00016 std::ostream &out = ( procRank == 0 ? std::cout : blackhole );
00017
00018 bool success = true;
00019
00020 try {
00021
00022 out << Teuchos::Teuchos_Version() << std::endl << std::endl;
00023
00024
00025 Teuchos::CommandLineProcessor My_CLP;
00026
00027 My_CLP.setDocString(
00028 "This example program demonstrates how to use this Teuchos::CommandLineProcessor class\n"
00029 "to get options from the command-line and print this help messange automatically.\n"
00030 );
00031
00032
00033
00034
00035
00036
00037
00038 int NumIters = 1550;
00039 My_CLP.setOption("iterations", &NumIters, "Number of iterations");
00040
00041 double Tolerance = 1e-10;
00042 My_CLP.setOption("tolerance", &Tolerance, "Tolerance");
00043
00044 std::string Solver = "GMRES";
00045 My_CLP.setOption("solver", &Solver, "Linear solver");
00046
00047 bool Precondition = true;
00048 My_CLP.setOption("precondition","no-precondition",
00049 &Precondition,"Preconditioning flag");
00050
00051 const int num_speed_values = 3;
00052 const ESpeed speed_opt_values[] = { SPEED_SLOW, SPEED_MEDIUM, SPEED_FAST };
00053 const char* speed_opt_names[] = { "slow", "medium", "fast" };
00054 ESpeed Speed = SPEED_MEDIUM;
00055 My_CLP.setOption(
00056 "speed", &Speed,
00057 num_speed_values, speed_opt_values, speed_opt_names,
00058 "Speed of our solver"
00059 );
00060
00061
00062
00063
00064
00065
00066 My_CLP.recogniseAllOptions(true);
00067
00068
00069
00070
00071
00072
00073
00074
00075 My_CLP.throwExceptions(false);
00076
00077
00078
00079
00080
00081
00082 Teuchos::CommandLineProcessor::EParseCommandLineReturn
00083 parseReturn= My_CLP.parse( argc, argv );
00084 if( parseReturn == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED ) {
00085 return 0;
00086 }
00087 if( parseReturn != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
00088 return 1;
00089 }
00090
00091
00092 if (procRank == 0)
00093 out << "\nPrinting help message with new values of command-line arguments ...\n\n";
00094 My_CLP.printHelpMessage(argv[0],out);
00095
00096
00097 if (procRank == 0) {
00098 out << "\nPrinting user options after parsing ...\n\n";
00099 out << "NumIters = " << NumIters << std::endl;
00100 out << "Tolerance = " << Tolerance << std::endl;
00101 out << "Solver = \"" << Solver << "\"\n";
00102 out << "Precondition = " << Precondition << std::endl;
00103 out << "Speed = " << Speed << std::endl;
00104 }
00105
00106 }
00107 TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cerr,success);
00108
00109 if(success)
00110 out << "\nEnd Result: TEST PASSED" << std::endl;
00111
00112 return ( success ? 0 : 1 );
00113 }