60inline int my_max(
int a,
int b ) {
return a > b ? a : b; }
63std::string remove_quotes(
const std::string& str )
67 return str.substr(1,str.size()-2);
71std::string add_quotes(
const std::string& str )
75 return "\"" + str +
"\"";
102 ,output_all_front_matter_(output_all_front_matter_default_)
103 ,output_show_line_prefix_(output_show_line_prefix_default_)
104 ,output_show_tab_count_(output_show_tab_count_default_)
105 ,output_show_proc_rank_(output_show_proc_rank_default_)
106 ,output_to_root_rank_only_(output_to_root_rank_only_default_)
107 ,print_rcpnode_statistics_on_exit_(print_rcpnode_statistics_on_exit_default_)
108 ,show_timer_summary_on_exit_(show_timer_summary_on_exit_default_)
109 ,printed_timer_summary_(
false)
110 ,added_extra_output_setup_options_(
false)
111 ,in_add_extra_output_setup_options_(
false)
134 ,
const char documentation[]
145 std::string(documentation?documentation:
""),
any(
option_val))
153 ,
const char documentation[]
171 ,
const char documentation[]
189 ,
const char documentation[]
206 ,
const char documentation[]
223 ,
const char documentation[]
240 ,
const char documentation[]
257 ,
const char documentation[]
283 std::string opt_name;
285 const std::string
echo_cl_opt =
"echo-command-line";
286 const std::string
help_opt =
"help";
287 const std::string
pause_opt =
"pause-for-debugging";
292 for(
int i = 1;
i <
argc; ++
i ) {
300 for(
int i = 1;
i <
argc; ++
i ) {
313 *
errout <<
"\nEchoing the command-line:\n\n";
314 for(
int j = 0;
j <
argc; ++
j )
328 std::cerr <<
"Rank " <<
k <<
" has PID " <<
pids[
k] << std::endl;
331 std::cerr <<
"\nType 0 and press enter to continue : ";
402 "Error, the option --"<<opt_val_name<<" was required but was not set!"
433 std::ostream &out )
const
446 options_documentation_list_t::const_iterator
itr;
465#ifdef HAVE_STD_IOS_BASE_FMTFLAGS
472 <<
"Prints this help message"
476#ifdef HAVE_STD_IOS_BASE_FMTFLAGS
480 << std::setiosflags(std::ios::left) <<
setw(
opt_name_w) <<
"pause-for-debugging"
483 <<
"Pauses for user input to allow attaching a debugger"
487#ifdef HAVE_STD_IOS_BASE_FMTFLAGS
491 << std::setiosflags(std::ios::left) <<
setw(
opt_name_w) <<
"echo-command-line"
494 <<
"Echo the command-line but continue as normal"
505#ifdef HAVE_STD_IOS_BASE_FMTFLAGS
512 << (
itr->documentation.length() ?
itr->documentation.c_str() :
"No documentation" )
541 switch(
itr->opt_type ) {
544 itr->opt_name :
itr->opt_name_false );
554 out <<
"--" <<
itr->opt_name;
559 switch(
itr->opt_type ) {
593 out <<
"\nDETAILED DOCUMENTATION:\n\n" <<
doc_string_ << std::endl << std::endl;
643 ,
"Set if all front matter is printed to the default FancyOStream or not"
647 ,
"Set if the line prefix matter is printed to the default FancyOStream or not"
651 ,
"Set if the tab count is printed to the default FancyOStream or not"
655 ,
"Set if the processor rank is printed to the default FancyOStream or not"
659 ,
"Set which processor (the root) gets the output. If < 0, then all processors get output."
662 "print-rcpnode-statistics-on-exit",
"no-print-rcpnode-statistics-on-exit",
664 "Set if the RCPNode usage statistics will be printed on exit or not. Warning,"
665 " this prints to std::cerr or every process so do not turn this on for very large"
671 "If true, then Teuchos::TimeMonitor::summarize() is called in"
672 " CommandLineProcessor's destructor (usually at the end of main)."
683 ,
int *enum_option_val
684 ,
const int num_enum_opt_values
685 ,
const int enum_opt_values[]
686 ,
const char* enum_opt_names[]
687 ,
const char documentation[]
699 enum_opt_data_t(enum_option_val,num_enum_opt_values,enum_opt_values,enum_opt_names)
706 std::string(documentation?documentation:
""),
any(
opt_id))
722 std::vector<std::string>::const_iterator
729 "Error, the value \"" << enum_str_val << "\" for the " \
730 << j<<(j==1?"st":(j==2?"nd":(j==3?"rd":"th"))) << " option --" \
731 << enum_opt_name << " was not recognized (use --help)!"
755 typedef std::vector<std::string>::const_iterator
itr_t;
756 out <<
"Valid options:";
793 std::vector<int>::const_iterator
799 ( recogniseAllOptions() ? "Error" : "Warning" ) \
800 << ", option --" << enum_opt_name << " was given an invalid " \
801 "initial option value of " << opt_value << "!"
814 ,std::string *opt_name
818 const int len =
static_cast<int>(std::strlen(
str));
821 if(
str[0] !=
'-' ||
str[1] !=
'-' )
827 opt_name->assign(
str + 2,
equ_i-2 );
846 ( recogniseAllOptions() ? "Error" : "Warning" ) \
847 << ", the " << j<<(j==1?"st":(j==2?"nd":(j==3?"rd":"th"))) \
848 << " option \'" << argv[argv_i] << "\' was not recognized (use --help)!"
Templated array class derived from the STL std::vector.
Basic command line parser for input from (argc,argv[])
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Definition of Teuchos::as, for conversions between types.
Thrown if –help was specified and throwExceptions==true.
Thrown if a parse std::exception occurs and throwExceptions==true.
Thrown if an unrecognized option was found and throwExceptions==true.
Class that helps parse command line input arguments from (argc,argv[]) and set options.
bool output_show_proc_rank_
bool get_opt_val(const char str[], std::string *opt_name, std::string *opt_val_str) const
static const bool output_all_front_matter_default_
bool output_show_tab_count_
static const bool show_timer_summary_on_exit_default_
void add_extra_output_setup_options() const
bool show_timer_summary_on_exit_
bool throwExceptions() const
Returns true if an std::exception is thrown, there is a parse error, or help is printed.
void setEnumOption(const char enum_option_name[], int *enum_option_val, const int num_enum_opt_values, const int enum_opt_values[], const char *enum_opt_names[], const char documentation[], const bool required)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
bool set_enum_value(int argv_i, char *argv[], const std::string &enum_opt_name, const int enum_id, const std::string &enum_str_val, std::ostream *errout) const
bool output_all_front_matter_
EParseCommandLineReturn
Return value for CommandLineProcessor::parse(). Note: These enums are all given non-negative values s...
@ PARSE_UNRECOGNIZED_OPTION
void print_bad_opt(int argv_i, char *argv[], std::ostream *errout) const
enum_opt_data_list_t enum_opt_data_list_
options_documentation_list_t options_documentation_list_
void print_enum_opt_names(const int enum_id, std::ostream &out) const
int output_to_root_rank_only_
static RCP< TimeMonitorSurrogate > & getRawTimeMonitorSurrogate()
static const bool output_show_line_prefix_default_
static const int output_to_root_rank_only_default_
static const bool output_show_tab_count_default_
std::string enum_opt_default_val_name(const std::string &enum_name, const int enum_id, std::ostream *errout) const
static const bool print_rcpnode_statistics_on_exit_default_
static RCP< TimeMonitorSurrogate > getTimeMonitorSurrogate()
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Parse a command line.
bool added_extra_output_setup_options_
void printHelpMessage(const char program_name[], std::ostream &out) const
Print the help message.
void printFinalTimerSummary(const Ptr< std::ostream > &out=null)
Call to print timers so that they don't get printed in the destructor.
static const bool output_show_proc_rank_default_
static void setTimeMonitorSurrogate(const RCP< TimeMonitorSurrogate > &timeMonitorSurrogate)
void setDocString(const char doc_string[])
Set a documentation sting for the entire program printed when –help is specified.
bool addOutputSetupOptions_
~CommandLineProcessor()
Destructor.
bool output_show_line_prefix_
bool printed_timer_summary_
bool print_rcpnode_statistics_on_exit_
options_list_t options_list_
CommandLineProcessor(bool throwExceptions=true, bool recogniseAllOptions=true, bool addOutputSetupOptions=false)
Default Constructor.
std::string opt_type_str(EOptType) const
bool recogniseAllOptions() const
Returns true if all options must be recognized by the parser.
bool in_add_extra_output_setup_options_
int find_enum_opt_index(const std::string &enum_opt_name, const int opt_value, const enum_opt_data_t &enum_data, std::ostream *errout) const
static void barrier()
Call MPI_Barrier() on MPI_COMM_WORLD.
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
static int getNProc()
The number of processes in MPI_COMM_WORLD.
static void allGather(int localVal, const ArrayView< int > &allVals)
Global all-to-all of a set of integers across processes.
static void setPrintRCPNodeStatisticsOnExit(bool printRCPNodeStatisticsOnExit)
Set if RCPNode usage statistics will be printed when the program ends or not.
Concrete serial communicator subclass.
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
Modified boost::any class, which is a container for a templated value.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.