GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
graphlab::command_line_options Class Reference

The GraphLab command line options class helps parse basic command line options for the GraphLab framework as well as user applications. More...

#include <graphlab/options/command_line_options.hpp>

List of all members.

Public Member Functions

 command_line_options (std::string desc_str, bool suppress_graphlab_options=false)
 Construct a command options object with basic settings.
void print_description () const
bool parse (int argc, const char *const *argv, bool allow_unregistered=false)
 This function should be called AFTER all the options have been seen (including positionals). The parse function reads the standard command line arguments and fills in the attached variables. If there is an error in the syntax or parsing fails the parse routine will print the error and return false.
bool is_set (const std::string &option)
 The is set function is used to test if the user provided the option. The option string should match one of the attached options.
std::vector< std::string > unrecognized () const
template<typename T >
void attach_option (const std::string &option, T &ret_var, const std::string &description)
 attach a user defined option to the command line options parser.
void add_positional (const std::string &str)
 attach a user defined option to the command line options parser.
void set_ncpus (size_t n)
 Set the number of cpus.
size_t get_ncpus () const
 Get the number of cpus.
void set_scheduler_type (const std::string &stype)
const std::string & get_scheduler_type () const
 Get the type of scheduler.
const options_mapget_engine_args () const
 Get the engine arguments.
options_mapget_engine_args ()
 Get the engine arguments.
const options_mapget_graph_args () const
options_mapget_graph_args ()
const options_mapget_scheduler_args () const
options_mapget_scheduler_args ()
virtual void print () const

Public Attributes

size_t ncpus
 The number of cpus.
std::string scheduler_type
 The type of scheduler to use.
options_map engine_args
 additional arguments to the engine
options_map scheduler_args
 additional arguments to the scheduler
options_map graph_args
 Options for the graph.

Detailed Description

The GraphLab command line options class helps parse basic command line options for the GraphLab framework as well as user applications.

Early in the development of GraphLab we realized that a lot of time was spent writing code to parse the many GraphLab options as well as each of the applications options. In many cases we were using the boost::program_options library which while very powerful can also be fairly complicated.

As a consequence, we developed a simple command line options object that parses the standard argv options capturing GraphLab specific options and also processing users options. GraphLab command line tools to enable user applications to benefit from sophisticated and still easy to use command line parsing.

The command_line_options data-structure is built on top of the boost::program_options library. We have tried to retain much of the functionality of the boost::program_options library while hiding some of the less "friendly" template meta-programming "features".

Here is an example of how the library is used:

int main(int argc, char** argv) {
std::string filename;
size_t dimensions = 20;
double bound = 1E-5;
bool use_x = false;
std::vector<size_t> nsamples(1,10000);
// Parse command line options
graphlab::command_line_options clopts("Welcome to a the HelloWorld");
clopts.attach_option("file", filename, "The input filename (required)");
clopts.add_positional("file");
clopts.attach_option("dim", dimensions,
"the dimension of the grid");
clopts.attach_option("bound", bound,
"The termination bound");
clopts.attach_option("usex", use_x,
"Use algorithm x");
clopts.attach_option("nsamples", nsamples,
"A vector of the number of samples");
if(!clopts.parse(argc, argv)) return EXIT_FAILURE;
if(!clopts.is_set("file")) {
std::cout << "Input file not provided" << std::endl;
clopts.print_description();
return EXIT_FAILURE;
}
}

Definition at line 167 of file command_line_options.hpp.


Constructor & Destructor Documentation

graphlab::command_line_options::command_line_options ( std::string  desc_str,
bool  suppress_graphlab_options = false 
)
inline

Construct a command options object with basic settings.

Parameters:
[in]desc_strThe description of the program that is printed when –help is invoked (in addition to all the options and their descriptions).
[in]suppress_graphlab_optionsIf set to true the standard GraphLab options are not parsed and the help screen. only presents the users options. This is useful in cases where command line options are needed outside of GraphLab binary (e.g., simple utilities).

Definition at line 194 of file command_line_options.hpp.


Member Function Documentation

void graphlab::command_line_options::add_positional ( const std::string &  str)

attach a user defined option to the command line options parser.

The attach option command is used to attach a user defined option to the command line options parser.

Parameters:
optionThe name of the command line flag for that option.
ret_contA pointer to an "arbitrary" type which can be any of the basic types (char, int, size_t, float, double, bool, string...) or an std::vector of basic types. It is important that the ret_cont point to a memory block that will exist when parse is invoked.
default_valueThe default value of the parameter if the user does not provide this parameter on the command line.
descriptionUsed to describe the option when –help is called or when print_description is invoked. This function adds the option as a positional argument. A positional argument does not require –option and instead is read based on its location. Each add_positional call adds to the next position.

Definition at line 186 of file command_line_options.cpp.

template<typename T >
void graphlab::command_line_options::attach_option ( const std::string &  option,
T &  ret_var,
const std::string &  description 
)
inline

attach a user defined option to the command line options parser.

The attach option command is used to attach a user defined option to the command line options parser.

Parameters:
[in]optionThe name of the command line flag for that option.
[in,out]ret_varA reference to an "arbitrary" type which can be any of the basic types (char, int, size_t, float, double, bool, string...) or an std::vector of basic types. It is important that the ret_cont point to a memory block that will exist when parse is invoked. The default value is read from the ret_cont
[in]descriptionUsed to describe the option when –help is called or when print_description is invoked.

Definition at line 261 of file command_line_options.hpp.

bool graphlab::command_line_options::parse ( int  argc,
const char *const *  argv,
bool  allow_unregistered = false 
)

This function should be called AFTER all the options have been seen (including positionals). The parse function reads the standard command line arguments and fills in the attached variables. If there is an error in the syntax or parsing fails the parse routine will print the error and return false.

If allow_unregistered is set to true, will permit unrecognized options

Definition at line 72 of file command_line_options.cpp.

virtual void graphlab::graphlab_options::print ( ) const
inlinevirtualinherited

Display the current engine options

Definition at line 151 of file graphlab_options.hpp.

void graphlab::command_line_options::print_description ( ) const
inline

Print the same message that is printed when the –help command line argument is provided.

Definition at line 208 of file command_line_options.hpp.

std::vector<std::string> graphlab::command_line_options::unrecognized ( ) const
inline

If allow_unregistered flag is set on parse this will contain the list of unrecognized options

Definition at line 236 of file command_line_options.hpp.


The documentation for this class was generated from the following files: