#include "Teuchos_oblackholestream.hpp"
#include "Teuchos_StandardCatchMacros.hpp"
#include "Teuchos_Version.hpp"
enum ESpeed { SPEED_SLOW=-1, SPEED_MEDIUM=0, SPEED_FAST=+1 };
int main(int argc, char* argv[])
{
std::ostream &out = ( procRank == 0 ? std::cout : blackhole );
bool success = true;
try {
out << Teuchos::Teuchos_Version() << std::endl << std::endl;
"This example program demonstrates how to use this Teuchos::CommandLineProcessor class\n"
"to get options from the command-line and print this help messange automatically.\n"
);
int NumIters = 1550;
My_CLP.
setOption(
"iterations", &NumIters,
"Number of iterations");
My_CLP.
setOption(
"long-matrix-dim", &MatrixDim,
"Matrix dimension (long)");
My_CLP.
setOption(
"long-long-matrix-dim", &MatrixDim2,
"Matrix dimension (long long)");
double Tolerance = 1e-10;
My_CLP.
setOption(
"tolerance", &Tolerance,
"Tolerance");
std::string Solver = "GMRES";
My_CLP.
setOption(
"solver", &Solver,
"Linear solver");
bool Precondition = true;
My_CLP.
setOption(
"precondition",
"no-precondition",
&Precondition,"Preconditioning flag");
const int num_speed_values = 3;
const ESpeed speed_opt_values[] = { SPEED_SLOW, SPEED_MEDIUM, SPEED_FAST };
const char* speed_opt_names[] = { "slow", "medium", "fast" };
ESpeed Speed = SPEED_MEDIUM;
"speed", &Speed,
num_speed_values, speed_opt_values, speed_opt_names,
"Speed of our solver"
);
parseReturn= My_CLP.
parse( argc, argv );
return 0;
}
return 1;
}
if (procRank == 0)
out << "\nPrinting help message with new values of command-line arguments ...\n\n";
if (procRank == 0) {
out << "\nPrinting user options after parsing ...\n\n";
out << "NumIters = " << NumIters << std::endl;
out << "MatrixDim = " << MatrixDim << std::endl;
out << "MatrixDim2 = " << MatrixDim2 << std::endl;
out << "Tolerance = " << Tolerance << std::endl;
out << "Solver = \"" << Solver << "\"\n";
out << "Precondition = " << Precondition << std::endl;
out << "Speed = " << Speed << std::endl;
}
}
if(success)
out << "\nEnd Result: TEST PASSED" << std::endl;
return ( success ? 0 : 1 );
}
Basic command line parser for input from (argc,argv[])
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Defines basic traits for the ordinal field type.
Class that helps parse command line input arguments from (argc,argv[]) and set options.
void throwExceptions(const bool &throwExceptions)
Set if an std::exception is thrown, there is a parse error, or help is printed.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
EParseCommandLineReturn
Return value for CommandLineProcessor::parse(). Note: These enums are all given non-negative values s...
void recogniseAllOptions(const bool &recogniseAllOptions)
Set if all options must be recognized or not.
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Parse a command line.
void printHelpMessage(const char program_name[], std::ostream &out) const
Print the help message.
void setDocString(const char doc_string[])
Set a documentation sting for the entire program printed when –help is specified.
Initialize, finalize, and query the global MPI session.
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
basic_ostream<> subclass that does nothing but discard output.
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
static T max()
Returns a value designating the maximum value accessible by code using OrdinalTraits.