#include "Teuchos_CommandLineProcessor.hpp"
#include "Teuchos_Version.hpp"
#ifdef HAVE_MPI
#include "mpi.h"
#endif
enum ESpeed { SPEED_SLOW=-1, SPEED_MEDIUM=0, SPEED_FAST=+1 };
int main(int argc, char* argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
int procRank = -1;
MPI_Comm_rank( MPI_COMM_WORLD, &procRank );
if ( procRank == 0 )
cout << Teuchos::Teuchos_Version() << endl << endl;
#else
cout << Teuchos::Teuchos_Version() << endl << endl;
#endif
Teuchos::CommandLineProcessor My_CLP;
int NumIters = 1550;
My_CLP.setOption("iterations", &NumIters, "Number of iterations");
double Tolerance = 1e-10;
My_CLP.setOption("tolerance", &Tolerance, "Tolerance");
string Solver = "GMRES";
My_CLP.setOption("solver", &Solver, "Linear solver");
bool Precondition;
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;
My_CLP.setOption(
"speed", &Speed,
num_speed_values, speed_opt_values, speed_opt_names,
"Speed of our solver"
);
My_CLP.recogniseAllOptions(true);
My_CLP.throwExceptions(false);
Teuchos::CommandLineProcessor::EParseCommandLineReturn
parseReturn= My_CLP.parse( argc, argv );
if( parseReturn == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED ) {
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return 0;
}
if( parseReturn != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return 1;
}
#ifdef HAVE_MPI
if (procRank == 0)
#endif
std::cout << "\nPrinting help message with new values of command-line arguments ...\n\n";
My_CLP.printHelpMessage(argv[0],std::cout);
#ifdef HAVE_MPI
if (procRank == 0) {
#endif
std::cout << "\nPrinting user options after parsing ...\n\n";
std::cout << "NumIters = " << NumIters << std::endl;
std::cout << "Tolerance = " << Tolerance << std::endl;
std::cout << "Solver = \"" << Solver << "\"\n";
std::cout << "Precondition = " << Precondition << std::endl;
std::cout << "Speed = " << Speed << std::endl;
#ifdef HAVE_MPI
}
MPI_Finalize();
#endif
return 0;
}