本文整理汇总了C++中boost::program_options::variables_map类的典型用法代码示例。如果您正苦于以下问题:C++ variables_map类的具体用法?C++ variables_map怎么用?C++ variables_map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了variables_map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hpx_main
int hpx_main(boost::program_options::variables_map& vm)
{
using hpx::lcos::local::dataflow;
boost::uint64_t nt = vm["nt"].as<boost::uint64_t>(); // Number of steps.
boost::uint64_t nx = vm["nx"].as<boost::uint64_t>(); // Number of grid points.
boost::uint64_t np = vm["np"].as<boost::uint64_t>(); // Number of partitions.
if (vm.count("no-header"))
header = false;
std::vector<hpx::id_type> localities = hpx::find_all_localities();
std::size_t nl = localities.size(); // Number of localities
if (np < nl)
{
std::cout << "The number of partitions should not be smaller than "
"the number of localities" << std::endl;
return hpx::finalize();
}
// Create the local stepper instance, register it
stepper step;
// Measure execution time.
boost::uint64_t t = hpx::util::high_resolution_clock::now();
// Perform all work and wait for it to finish
hpx::future<stepper_server::space> result = step.do_work(np/nl, nx, nt);
// Gather results from all localities
if (0 == hpx::get_locality_id())
{
boost::uint64_t elapsed = 0;
hpx::future<std::vector<stepper_server::space> > overall_result =
hpx::lcos::gather_here(gather_basename, std::move(result), nl);
// Print the solution at time-step 'nt'.
if (vm.count("results"))
{
std::vector<stepper_server::space> solution = overall_result.get();
elapsed = hpx::util::high_resolution_clock::now() - t;
for (std::size_t i = 0; i != nl; ++i)
{
stepper_server::space const& s = solution[i];
for (std::size_t j = 0; j != np; ++j)
{
std::cout << "U[" << i*np + j << "] = "
<< s[j].get_data(partition_server::middle_partition).get()
<< std::endl;
}
}
}
else
{
overall_result.wait();
elapsed = hpx::util::high_resolution_clock::now() - t;
}
boost::uint64_t const os_thread_count = hpx::get_os_thread_count();
print_time_results(os_thread_count, elapsed, nx, np, nt, header);
}
else
{
hpx::lcos::gather_there(gather_basename, std::move(result)).wait();
}
return hpx::finalize();
}
示例2: parseArguments
INT parseArguments(INT ac, WCHAR **av, po::variables_map& vm, printInfoStruct& printInfo)
{
WCHAR namePath[MAX_PATH];
GetModuleFileName(NULL, namePath, MAX_PATH);
WCHAR *progName = PathFindFileName(namePath);
po::options_description desc;
desc.add_options()
("help,h", "Print help message and exit")
("version,V", "Print version and exit")
("debug,d", "Verbose/Debug output")
("warning,w", po::wvalue<std::wstring>(), "Warning threshold")
("critical,c", po::wvalue<std::wstring>(), "Critical threshold")
("unit,u", po::wvalue<std::wstring>(), "The unit to use for display (default MB)")
;
po::basic_command_line_parser<WCHAR> parser(ac, av);
try {
po::store(
parser
.options(desc)
.style(
po::command_line_style::unix_style |
po::command_line_style::allow_long_disguise)
.run(),
vm);
vm.notify();
} catch (std::exception& e) {
std::cout << e.what() << '\n' << desc << '\n';
return 3;
}
if (vm.count("help")) {
std::wcout << progName << " Help\n\tVersion: " << VERSION << '\n';
wprintf(
L"%s is a simple program to check a machines swap in percent.\n"
L"You can use the following options to define its behaviour:\n\n", progName);
std::cout << desc;
wprintf(
L"\nIt will then output a string looking something like this:\n\n"
L"\tSWAP WARNING - 20%% free | swap=2000B;3000;500;0;10000\n\n"
L"\"SWAP\" being the type of the check, \"WARNING\" the returned status\n"
L"and \"20%%\" is the returned value.\n"
L"The performance data is found behind the \"|\", in order:\n"
L"returned value, warning threshold, critical threshold, minimal value and,\n"
L"if applicable, the maximal value. Performance data will only be displayed when\n"
L"you set at least one threshold\n\n"
L"%s' exit codes denote the following:\n"
L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n"
L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n"
L" 2\tCRITICAL,\n\tThe critical threshold was broken\n"
L" 3\tUNKNOWN, \n\tThe program experienced an internal or input error\n\n"
L"Threshold syntax:\n\n"
L"-w THRESHOLD\n"
L"warn if threshold is broken, which means VALUE > THRESHOLD\n"
L"(unless stated differently)\n\n"
L"-w !THRESHOLD\n"
L"inverts threshold check, VALUE < THRESHOLD (analogous to above)\n\n"
L"-w [THR1-THR2]\n"
L"warn is VALUE is inside the range spanned by THR1 and THR2\n\n"
L"-w ![THR1-THR2]\n"
L"warn if VALUE is outside the range spanned by THR1 and THR2\n\n"
L"-w THRESHOLD%%\n"
L"if the plugin accepts percentage based thresholds those will be used.\n"
L"Does nothing if the plugin does not accept percentages, or only uses\n"
L"percentage thresholds. Ranges can be used with \"%%\", but both range values need\n"
L"to end with a percentage sign.\n\n"
L"All of these options work with the critical threshold \"-c\" too.\n"
, progName);
std::cout << '\n';
return 0;
}
if (vm.count("version"))
std::wcout << L"Version: " << VERSION << '\n';
if (vm.count("warning")) {
try {
printInfo.warn = threshold(vm["warning"].as<std::wstring>());
} catch (std::invalid_argument& e) {
std::cout << e.what() << '\n';
return 3;
}
printInfo.warn.legal = !printInfo.warn.legal;
}
if (vm.count("critical")) {
try {
printInfo.crit = threshold(vm["critical"].as<std::wstring>());
} catch (std::invalid_argument& e) {
std::cout << e.what() << '\n';
return 3;
}
printInfo.crit.legal = !printInfo.crit.legal;
}
if (vm.count("debug"))
debug = TRUE;
//.........这里部分代码省略.........
示例3: hpx_main
int hpx_main(boost::program_options::variables_map& vm)
{
/* Number of partitions dynamically determined
// Number of partitions.
// boost::uint64_t np = vm["np"].as<boost::uint64_t>();
*/
// Number of grid points.
boost::uint64_t nx = vm["nx"].as<boost::uint64_t>();
// Number of steps.
boost::uint64_t nt = vm["nt"].as<boost::uint64_t>();
// Number of runs (repartition between runs).
boost::uint64_t nr = vm["nr"].as<boost::uint64_t>();
if (vm.count("no-header"))
header = false;
// Find divisors of nx
std::vector<boost::uint64_t> divisors;
for(boost::uint64_t i = 1; i < std::sqrt(nx); ++i) {
if(nx % i == 0) {
divisors.push_back(i);
divisors.push_back(nx/i);
}
}
divisors.push_back(static_cast<boost::uint64_t>(std::sqrt(nx)));
std::sort(divisors.begin(), divisors.end());
// Set up APEX tuning
// The tunable parameter -- how many partitions to divide data into
long np_index = 1;
long * tune_params[1] = { 0L };
long num_params = 1;
long mins[1] = { 0 };
long maxs[1] = { (long)divisors.size() };
long steps[1] = { 1 };
tune_params[0] = &np_index;
apex::setup_custom_tuning(get_idle_rate, end_iteration_event, num_params,
tune_params, mins, maxs, steps);
// Create the stepper object
stepper step;
boost::uint64_t const os_thread_count = hpx::get_os_thread_count();
std::vector<double> data;
for(boost::uint64_t i = 0; i < nr; ++i)
{
boost::uint64_t parts = divisors[np_index];
boost::uint64_t size_per_part = nx / parts;
boost::uint64_t total_size = parts * size_per_part;
//std::cerr << "parts: " << parts << " Per part: " << size_per_part
//std::cerr << " Overall: " << total_size << std::endl;
// Measure execution time.
boost::uint64_t t = hpx::util::high_resolution_clock::now();
// Execute nt time steps on nx grid points and print the final solution.
hpx::future<stepper::space> result =
step.do_work(parts, size_per_part, nt, data);
stepper::space solution = result.get();
hpx::wait_all(solution);
boost::uint64_t elapsed = hpx::util::high_resolution_clock::now() - t;
// Get new partition size
apex::custom_event(end_iteration_event, 0);
// Gather data together
data.resize(total_size);
for(boost::uint64_t partition = 0; partition != parts; ++partition) {
solution[partition].get().copy_into_array(
data, partition*size_per_part);
}
// Print the final solution
if (vm.count("results"))
{
for (boost::uint64_t i = 0; i != parts; ++i)
std::cout << "U[" << i << "] = " << solution[i].get() << std::endl;
}
print_time_results(os_thread_count, elapsed, size_per_part, parts, nt, header);
header = false; // only print header once
}
return hpx::finalize();
}
示例4: onSigOptionsParsed
static void onSigOptionsParsed(boost::program_options::variables_map& v)
{
if(v.count("start-simulation")){
callLater(std::bind(static_cast<void(SimulationBar::*)(bool)>(&SimulationBar::startSimulation), instance_, true));
}
}
示例5: store
bool CmdLine::store( int argc , char ** argv ,
boost::program_options::options_description& visible,
boost::program_options::options_description& hidden,
boost::program_options::positional_options_description& positional,
boost::program_options::variables_map ¶ms ) {
{
// setup binary name
cmdLine.binaryName = argv[0];
size_t i = cmdLine.binaryName.rfind( '/' );
if ( i != string::npos )
cmdLine.binaryName = cmdLine.binaryName.substr( i + 1 );
// setup cwd
char buffer[1024];
#ifdef _WIN32
verify( _getcwd( buffer , 1000 ) );
#else
verify( getcwd( buffer , 1000 ) );
#endif
cmdLine.cwd = buffer;
}
/* don't allow guessing - creates ambiguities when some options are
* prefixes of others. allow long disguises and don't allow guessing
* to get away with our vvvvvvv trick. */
int style = (((po::command_line_style::unix_style ^
po::command_line_style::allow_guessing) |
po::command_line_style::allow_long_disguise) ^
po::command_line_style::allow_sticky);
try {
po::options_description all;
all.add( visible );
all.add( hidden );
po::store( po::command_line_parser(argc, argv)
.options( all )
.positional( positional )
.style( style )
.run(),
params );
if ( params.count("config") ) {
ifstream f( params["config"].as<string>().c_str() );
if ( ! f.is_open() ) {
cout << "ERROR: could not read from config file" << endl << endl;
cout << visible << endl;
return false;
}
stringstream ss;
CmdLine::parseConfigFile( f, ss );
po::store( po::parse_config_file( ss , all ) , params );
f.close();
}
po::notify(params);
}
catch (po::error &e) {
cout << "error command line: " << e.what() << endl;
cout << "use --help for help" << endl;
//cout << visible << endl;
return false;
}
if (params.count("verbose")) {
logLevel = 1;
}
for (string s = "vv"; s.length() <= 12; s.append("v")) {
if (params.count(s)) {
logLevel = s.length();
}
}
if (params.count("quiet")) {
cmdLine.quiet = true;
}
if (params.count("traceExceptions")) {
DBException::traceExceptions = true;
}
if ( params.count( "maxConns" ) ) {
int newSize = params["maxConns"].as<int>();
if ( newSize < 5 ) {
out() << "maxConns has to be at least 5" << endl;
::_exit( EXIT_BADOPTIONS );
}
else if ( newSize >= 10000000 ) {
out() << "maxConns can't be greater than 10000000" << endl;
::_exit( EXIT_BADOPTIONS );
}
connTicketHolder.resize( newSize );
}
//.........这里部分代码省略.........
示例6: instream
///////////////////////////////////////////////////////////////////////////////
// do the actual preprocessing
int
do_actual_work (std::string file_name, po::variables_map const &vm)
{
// current file position is saved for exception handling
boost::wave::util::file_position_type current_position;
try {
// process the given file
ifstream instream(file_name.c_str());
string instring;
if (!instream.is_open()) {
cerr << "waveidl: could not open input file: " << file_name << endl;
return -1;
}
instream.unsetf(std::ios::skipws);
#if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
// this is known to be very slow for large files on some systems
copy (istream_iterator<char>(instream),
istream_iterator<char>(),
inserter(instring, instring.end()));
#else
instring = string(istreambuf_iterator<char>(instream.rdbuf()),
istreambuf_iterator<char>());
#endif
// This sample uses the lex_token type predefined in the Wave library, but
// but uses a custom lexer type.
typedef boost::wave::idllexer::lex_iterator<
boost::wave::cpplexer::lex_token<> >
lex_iterator_type;
typedef boost::wave::context<std::string::iterator, lex_iterator_type>
context_type;
// The C++ preprocessor iterators shouldn't be constructed directly. They
// are to be generated through a boost::wave::context<> object. This
// boost::wave::context object is additionally to be used to initialize and
// define different parameters of the actual preprocessing.
// The preprocessing of the input stream is done on the fly behind the
// scenes during iteration over the context_type::iterator_type stream.
context_type ctx (instring.begin(), instring.end(), file_name.c_str());
// add include directories to the system include search paths
if (vm.count("sysinclude")) {
vector<string> const &syspaths =
vm["sysinclude"].as<vector<string> >();
vector<string>::const_iterator end = syspaths.end();
for (vector<string>::const_iterator cit = syspaths.begin();
cit != end; ++cit)
{
ctx.add_sysinclude_path((*cit).c_str());
}
}
// add include directories to the include search paths
if (vm.count("include")) {
cmd_line_util::include_paths const &ip =
vm["include"].as<cmd_line_util::include_paths>();
vector<string>::const_iterator end = ip.paths.end();
for (vector<string>::const_iterator cit = ip.paths.begin();
cit != end; ++cit)
{
ctx.add_include_path((*cit).c_str());
}
// if on the command line was given -I- , this has to be propagated
if (ip.seen_separator)
ctx.set_sysinclude_delimiter();
// add system include directories to the include path
vector<string>::const_iterator sysend = ip.syspaths.end();
for (vector<string>::const_iterator syscit = ip.syspaths.begin();
syscit != sysend; ++syscit)
{
ctx.add_sysinclude_path((*syscit).c_str());
}
}
// add additional defined macros
if (vm.count("define")) {
vector<string> const ¯os = vm["define"].as<vector<string> >();
vector<string>::const_iterator end = macros.end();
for (vector<string>::const_iterator cit = macros.begin();
cit != end; ++cit)
{
ctx.add_macro_definition(*cit);
}
}
// add additional predefined macros
if (vm.count("predefine")) {
vector<string> const &predefmacros =
vm["predefine"].as<vector<string> >();
vector<string>::const_iterator end = predefmacros.end();
for (vector<string>::const_iterator cit = predefmacros.begin();
cit != end; ++cit)
//.........这里部分代码省略.........
示例7: hpx_main
// ----------------------------------------------------------------------------
int hpx_main(boost::program_options::variables_map &vm)
{
namespace process = hpx::components::process;
namespace fs = boost::filesystem;
// find where the HPX core libraries are located
fs::path base_dir = hpx::util::find_prefix();
base_dir /= "bin";
fs::path exe = base_dir / "launched_process_test" HPX_EXECUTABLE_EXTENSION;
std::string launch_target;
if (vm.count("launch"))
{
launch_target = vm["launch"].as<std::string>();
std::cout << "using launch: " << launch_target << std::endl;
exe = launch_target;
}
else
{
std::cout << "using launch (default): " << exe << std::endl;
}
// set up command line for launched executable
std::vector<std::string> args;
args.push_back(exe.string());
args.push_back("--exit_code=42");
args.push_back("--component=test_server");
args.push_back("--set_message=accessed");
args.push_back("--hpx:ignore-batch-env");
// set up environment for launched executable
std::vector<std::string> env = get_environment(); // current environment
// Pass along the console parcelport address
env.push_back("HPX_AGAS_SERVER_ADDRESS=" +
hpx::get_config_entry("hpx.agas.address", HPX_INITIAL_IP_ADDRESS));
env.push_back("HPX_AGAS_SERVER_PORT=" +
hpx::get_config_entry("hpx.agas.port",
std::to_string(HPX_INITIAL_IP_PORT)));
// Pass along the parcelport address which should be used by the launched
// executable
// The launched executable will run on the same host as this test
int port = 42; // each launched HPX locality needs to be assigned a
// unique port
env.push_back("HPX_PARCEL_SERVER_ADDRESS=" +
hpx::get_config_entry("hpx.agas.address", HPX_INITIAL_IP_ADDRESS));
env.push_back("HPX_PARCEL_SERVER_PORT=" +
std::to_string(HPX_CONNECTING_IP_PORT - port));
// Instruct new locality to connect back on startup using the given name.
env.push_back("HPX_ON_STARTUP_WAIT_ON_LATCH=launch_process");
// launch test executable
process::child c = process::execute(
hpx::find_here(),
process::run_exe(exe.string()),
process::set_args(args),
process::set_env(env),
process::start_in_dir(base_dir.string()),
process::throw_on_error(),
process::wait_on_latch("launch_process") // same as above!
);
{
// now create an instance of the test_server component
hpx::components::client<launch_process::test_server> t =
hpx::new_<launch_process::test_server>(hpx::find_here());
hpx::future<std::string> f =
hpx::async(launch_process_get_message_action(), t);
HPX_TEST_EQ(f.get(), std::string("initialized"));
// register the component instance with AGAS
t.register_as("test_server"); // same as --component=<> above
// wait for the HPX locality to be up and running
c.wait();
HPX_TEST(c);
// the launched executable should have connected back as a new locality
HPX_TEST_EQ(hpx::find_all_localities().size(), std::size_t(2));
// wait for it to exit, we know it returns 42 (see --exit_code=<> above)
int exit_code = c.wait_for_exit(hpx::launch::sync);
HPX_TEST_EQ(exit_code, 42);
// make sure the launched process has set the message in the component
// this should be the same as --set_message=<> above
f = hpx::async(launch_process_get_message_action(), t);
HPX_TEST_EQ(f.get(), std::string("accessed"));
} // release the component
// the new locality should have disconnected now
HPX_TEST_EQ(hpx::find_all_localities().size(), std::size_t(1));
//.........这里部分代码省略.........
示例8: hpx_main
int hpx_main(boost::program_options::variables_map& vm)
{
boost::uint64_t order = vm["matrix_size"].as<boost::uint64_t>();
boost::uint64_t iterations = vm["iterations"].as<boost::uint64_t>();
boost::uint64_t tile_size = order;
if(vm.count("tile_size"))
tile_size = vm["tile_size"].as<boost::uint64_t>();
verbose = vm.count("verbose");
boost::uint64_t bytes = 2.0 * sizeof(double) * order * order;
std::vector<double> A(order * order);
std::vector<double> B(order * order);
std::cout
<< "Serial Matrix transpose: B = A^T\n"
<< "Matrix order = " << order << "\n";
if(tile_size < order)
std::cout << "Tile size = " << tile_size << "\n";
else
std::cout << "Untiled\n";
std::cout
<< "Number of iterations = " << iterations << "\n";
using hpx::parallel::for_each;
using hpx::parallel::par;
const boost::uint64_t start = 0;
// Fill the original matrix, set transpose to known garbage value.
auto range = boost::irange(start, order);
// parallel for
for_each(par, boost::begin(range), boost::end(range),
[&](boost::uint64_t i)
{
for(boost::uint64_t j = 0; j < order; ++j)
{
A[i * order + j] = COL_SHIFT * j + ROW_SHIFT * i;
B[i * order + j] = -1.0;
}
}
);
double errsq = 0.0;
double avgtime = 0.0;
double maxtime = 0.0;
double mintime = 366.0 * 24.0*3600.0; // set the minimum time to a large value;
// one leap year should be enough
for(boost::uint64_t iter = 0; iter < iterations; ++iter)
{
hpx::util::high_resolution_timer t;
if(tile_size < order)
{
auto range = boost::irange(start, order+tile_size, tile_size);
// parallel for
for_each(par, boost::begin(range), boost::end(range),
[&](boost::uint64_t i)
{
for(boost::uint64_t j = 0; j < order; j += tile_size)
{
for(boost::uint64_t it = i; it < (std::min)(order, i + tile_size); ++it)
{
for(boost::uint64_t jt = j; jt < (std::min)(order, j + tile_size); ++jt)
{
B[it + order * jt] = A[jt + order * it];
}
}
}
}
);
}
else
{
auto range = boost::irange(start, order);
// parallel for
for_each(par, boost::begin(range), boost::end(range),
[&](boost::uint64_t i)
{
for(boost::uint64_t j = 0; j < order; ++j)
{
B[i + order * j] = A[j + order * i];
}
}
);
}
double elapsed = t.elapsed();
if(iter > 0 || iterations == 1) // Skip the first iteration
{
avgtime = avgtime + elapsed;
maxtime = (std::max)(maxtime, elapsed);
mintime = (std::min)(mintime, elapsed);
}
errsq += test_results(order, B);
} // end of iter loop
//.........这里部分代码省略.........
示例9: parseParameters
int
parseParameters( boost::program_options::variables_map _vm, int ruleGen, execMyRuleInp_t *execMyRuleInp, char *inBuf ) {
strArray_t strArray;
int status, i, j;
char *value;
char line[MAX_NAME_LEN];
int promptF = 0;
int labelF = 0;
if ( inBuf == NULL || strcmp( inBuf, "null" ) == 0 ) {
execMyRuleInp->inpParamArray = NULL;
return 0;
}
memset( &strArray, 0, sizeof( strArray ) );
status = splitMultiStr( inBuf, &strArray );
if ( status < 0 ) {
rodsLog( LOG_ERROR,
"parseMsInputParam: parseMultiStr error, status = %d", status );
execMyRuleInp->inpParamArray = NULL;
return status;
}
status = 0;
resizeStrArray( &strArray, MAX_NAME_LEN );
value = strArray.value;
if ( _vm.count( "file" ) ) {
if ( _vm.count( "parameters" ) ) {
std::vector< std::string > parameters;
try {
parameters = _vm["parameters"].as< std::vector< std::string > >();
} catch ( boost::bad_any_cast& e ) {
std::cerr << "Bad parameter list provided to parseParameters\n";
std::cerr << "Use -h or --help for help\n";
return -1;
}
for ( size_t inx = 0; inx < parameters.size(); ++inx ) {
std::string param = parameters.at(inx);
/* using the values from the input line following -F <filename> */
/* each string is supposed to have to format label=value */
if ( param == "prompt" ) {
promptF = 1;
break;
}
if ( param == "default" || param.length() == 0 ) {
continue;
}
else if ( param.at(0) == '*' ) {
size_t eqInx;
std::string tmpStr;
if ( inx > 0 && labelF == 0 ) {
return CAT_INVALID_ARGUMENT;
}
labelF = 1;
if ( ( eqInx = param.find( "=" ) ) == std::string::npos ) {
return CAT_INVALID_ARGUMENT;
}
tmpStr = param.substr( 0, eqInx );
for ( j = 0; j < strArray.len; j++ ) {
if ( strstr( &value[j * strArray.size], tmpStr.c_str() ) == &value[j * strArray.size] ) {
char *val = quoteString( param.c_str(), _vm.count( "string" ), 1 );
rstrcpy( &value[j * strArray.size], val, strArray.size );
free( val );
break;
}
}
if ( j == strArray.len ) {
printf( "Ignoring Argument \"%s\"\n", param.c_str() );
}
} else {
char *valPtr = &value[inx * strArray.size];
char *tmpPtr;
if ( labelF == 1 ) {
return CAT_INVALID_ARGUMENT;
}
if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) {
tmpPtr++;
char *val = quoteString( param.c_str(), _vm.count( "string" ), 0 );
rstrcpy( tmpPtr, val,
strArray.size - ( tmpPtr - valPtr + 1 ) );
free( val );
}
}
}
}
}
for ( i = 0; i < strArray.len; i++ ) {
char *valPtr = &value[i * strArray.size];
char *tmpPtr;
//.........这里部分代码省略.........
示例10: basic_configuration
configuration::configuration(const boost::program_options::variables_map& vars, logger::logger& log) : basic_configuration(vars, log), pimpl(std::make_unique<impl>())
{
if (vars.count("input"))
set_input_filename(vars.at("input").as<std::string>());
}
示例11: compile
void compile(boost::program_options::variables_map vm,
string out_file_name,
string routine_name,
map<string,type*>& inputs,
map<string,type*>& inouts,
map<string,type*>& outputs,
vector<stmt*> const& prog)
{
// set up signal to end search after certain amount of time
int sMinutes = vm["limit"].as<int>();
if (sMinutes > 0) {
int sSeconds = sMinutes * 60;
signal(SIGALRM, sig_alarm_handler);
alarm(sSeconds);
}
// search strategy
enum search_strategy {exhaustive, orthogonal, random,
hybrid_orthogonal, ga, debug, thread};
search_strategy strat = ga;
if (vm["search"].as<std::string>().compare("ex") == 0) {
strat = exhaustive;
}
else if (vm["search"].as<std::string>().compare("debug") == 0) {
strat = debug;
}
else if (vm["search"].as<std::string>().compare("orthogonal") == 0) {
strat = orthogonal;
}
else if (vm["search"].as<std::string>().compare("random") == 0) {
strat = random;
}
else if (vm["search"].as<std::string>().compare("hybrid_orthogonal") == 0) {
strat = hybrid_orthogonal;
}
else if (vm["search"].as<std::string>().compare("ga") == 0) {
strat = ga;
}
else if (vm["search"].as<std::string>().compare("thread") == 0) {
strat = thread;
}
else {
std::cout << "Error: unknown search strategy (--search):" << vm["search"].as<std::string>() << "\n\n";
exit(0);
}
// which backend
bool noptr;
if (vm["backend"].as<std::string>().compare("noptr") == 0) {
noptr = true;
} else {
noptr = false;
}
std::cout << noptr << std::endl;
// partitiong FIXME can't turn off anymore?
/*
bool partitionSet = true;
if (vm.count("partition_off")) {
partitionSet = false;
}
*/
bool mpi = false;
if (vm.count("distributed")) {
mpi = true;
}
string pathToTop = getcwd(NULL,0);
pathToTop += "/";
// std::cout << pathToTop << std::endl;
// set up temporary workspace
string tmpPath, fileName, path;
if (setUpWorkSpace(out_file_name, fileName, path, tmpPath, pathToTop,
vm.count("delete_tmp"))) {
std::cout << "Failed to set up temporary directory for unique implementations\n";
return;
}
// set all work to be performed in temporary work directory
out_file_name = tmpPath + fileName;
// {{{ COST MODELS
std::list<versionData*> orderedVersions;
string testParam = vm["test_param"].as<std::string>();
string start, stop, step;
string::size_type pos = testParam.find_first_of(":");
if (pos != string::npos)
start = testParam.substr(0, pos);
string::size_type last = pos+1;
pos = testParam.find_first_of(":",last);
if (pos != string::npos)
stop = testParam.substr(last, pos-last);
step = testParam.substr(pos+1,string::npos);
if (boost::lexical_cast<int>(start) > boost::lexical_cast<int>(stop)) {
//.........这里部分代码省略.........
示例12: setCpp
bool
Config::applyOptions(
const po::variables_map& vm,
bool stopOnError)
{
bool rc;
ArgMultiplier v;
rc = true;
if (vm.count("function")) {
if (!setFunction(vm["function"].as<std::string>())) {
std::cerr << "Invalid function name: " <<
vm["function"].as<std::string>() << std::endl;
return false;
}
}
if (vm.count("cpp")) {
setCpp(vm["cpp"].as<std::string>());
}
if (vm.count("cl")) {
setCl(vm["cl"].as<std::string>());
}
if (vm.count("data")) {
if (!setDataPattern(vm["data"].as<std::string>())) {
std::cerr << "Invalid data pattern name" << std::endl;
rc = false;
if (stopOnError) {
return false;
}
}
}
if (vm.count("skip-accuracy")) {
setSkipAccuracy();
}
if (vm.count("platform")) {
if (!setPlatform(vm["platform"].as<std::string>())) {
std::cerr << "Invalid platform name" << std::endl;
rc = false;
if (stopOnError) {
return false;
}
}
}
if (vm.count("device")) {
if (!setDevice(vm["device"].as<std::string>())) {
std::cerr << "Invalid device name" << std::endl;
rc = false;
if (stopOnError) {
return false;
}
}
}
if (vm.count("build-options")) {
setBuildOptions(vm["build-options"].as<std::string>());
}
if (vm.count("order")) {
setOrder(vm["order"].as<clblasOrder>());
}
if (vm.count("side")) {
setSide(vm["side"].as<clblasSide>());
}
if (vm.count("uplo")) {
setUplo(vm["uplo"].as<clblasUplo>());
}
if (vm.count("transA")) {
setTransA(vm["transA"].as<clblasTranspose>());
}
if (vm.count("transB")) {
setTransB(vm["transB"].as<clblasTranspose>());
}
if (vm.count("diag")) {
setDiag(vm["diag"].as<clblasDiag>());
}
if (vm.count("M")) {
setM(vm["M"].as<size_t>());
}
if (vm.count("N")) {
setN(vm["N"].as<size_t>());
}
if (vm.count("K")) {
setK(vm["K"].as<size_t>());
}
if (vm.count("alpha")) {
if (!parseArgMultiplier(vm["alpha"].as<std::string>(), v)) {
std::cerr << "in option 'alpha': invalid option value" << std::endl;
rc = false;
if (stopOnError) {
return false;
}
}
setAlpha(v);
}
if (vm.count("beta")) {
if (!parseArgMultiplier(vm["beta"].as<std::string>(), v)) {
std::cerr << "in option 'beta': invalid option value" << std::endl;
rc = false;
//.........这里部分代码省略.........
示例13: parseArguments
INT parseArguments(INT ac, WCHAR **av, po::variables_map& vm, printInfoStruct& printInfo)
{
WCHAR namePath[MAX_PATH];
GetModuleFileName(NULL, namePath, MAX_PATH);
WCHAR *progName = PathFindFileName(namePath);
po::options_description desc;
desc.add_options()
("help,h", "Print help message and exit")
("version,V", "Print version and exit")
("debug,d", "Verbose/Debug output")
("service,s", po::wvalue<std::wstring>(), "Service to check (required)")
("warn,w", "Return warning (1) instead of critical (2),\n when service is not running")
;
po::basic_command_line_parser<WCHAR> parser(ac, av);
try {
po::store(
parser
.options(desc)
.style(
po::command_line_style::unix_style |
po::command_line_style::allow_long_disguise)
.run(),
vm);
vm.notify();
} catch (std::exception& e) {
std::cout << e.what() << '\n' << desc << '\n';
return 3;
}
if (vm.count("help")) {
std::wcout << progName << " Help\n\tVersion: " << VERSION << '\n';
wprintf(
L"%s is a simple program to check the status of a service.\n"
L"You can use the following options to define its behaviour:\n\n", progName);
std::cout << desc;
wprintf(
L"\nIt will then output a string looking something like this:\n\n"
L"\tSERVICE CRITICAL NOT_RUNNING | service=4;!4;!4;1;7\n\n"
L"\"SERVICE\" being the type of the check, \"CRITICAL\" the returned status\n"
L"and \"1\" is the returned value.\n"
L"A service is either running (Code 0x04) or not running (any other).\n"
L"For more information consult the msdn on service state transitions.\n\n"
L"%s' exit codes denote the following:\n"
L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n"
L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n"
L" 2\tCRITICAL,\n\tThe critical threshold was broken\n"
L" 3\tUNKNOWN, \n\tThe program experienced an internal or input error\n\n"
L"%s' thresholds work differently, since a service is either running or not\n"
L"all \"-w\" and \"-c\" do is say whether a not running service is a warning\n"
L"or critical state respectively.\n\n"
, progName, progName);
std::cout << '\n';
return 0;
}
if (vm.count("version")) {
std::cout << "Version: " << VERSION << '\n';
return 0;
}
if (!vm.count("service")) {
std::cout << "Missing argument: service" << '\n' << desc << '\n';
return 3;
}
if (vm.count("warn"))
printInfo.warn = true;
printInfo.service = vm["service"].as<std::wstring>();
if (vm.count("debug"))
debug = TRUE;
return -1;
}
示例14: Edit
void Edit(const po::variables_map& variables, int& retcode)
{
retcode = 1;
if (!variables.count("input"))
{
std::wcerr << L"Error parsing options: must have some input files.\n";
return;
}
auto inputs = variables["input"].as<std::vector<std::wstring>>();
bool noResourceRebuild = variables["no-resource-rebuild"].as<bool>();
retcode = 0;
for (auto& input : inputs)
{
StripSignature(input, retcode);
if (!noResourceRebuild)
{
HANDLE binaryHandle = NULL;
{
PEParser pe(input);
pe.Open();
if (!pe.IsValidPE())
{
std::wcerr << L"Can't open file for reading or invalid format." << std::endl;
continue;
}
std::vector<std::shared_ptr<BYTE>> data;
binaryHandle = BeginUpdateResource(input.c_str(), FALSE);
if (!binaryHandle)
{
std::wcerr << L"Can't lock file for updating resources." << std::endl;
continue;
}
ResourceEntryPtr node;
if (pe.ResourceDirectory())
node = pe.ResourceDirectory()->AtPath(L"16/1");
if (!node)
continue;
bool success = true;
if (node->IsData())
data.push_back(ProcessNode(binaryHandle, node, variables));
else
for (auto& entry : node->Entries())
data.push_back(ProcessNode(binaryHandle, entry.second, variables));
}
if (!EndUpdateResource(binaryHandle, false))
{
std::wcerr << L"Failed to update resources" << std::endl;
retcode = 1;
}
}
else
{
PEParser pe(input);
pe.Open(true);
if (!pe.IsValidPE())
{
std::wcerr << L"Can't open file for reading or invalid format." << std::endl;
continue;
}
VersionString version;
PEParser::VersionField versionField = PEParser::Both;
if (variables.count("set-version"))
{
version = variables["set-version"].as<std::wstring>();
versionField = PEParser::Both;
}
else if (variables.count("set-file-version"))
{
version = variables["set-file-version"].as<std::wstring>();
versionField = PEParser::FileOnly;
}
else if (variables.count("set-product-version"))
{
version = variables["set-product-version"].as<std::wstring>();
versionField = PEParser::ProductOnly;
}
if (!pe.SetVersion(version, versionField))
retcode = 1;
pe.Close();
}
}
}
示例15: ParseArguments
BOOL ParseArguments(CONST INT ac, WCHAR **av, po::variables_map& vm, printInfoStruct& printInfo)
{
WCHAR szNamePath[MAX_PATH + 1];
GetModuleFileName(NULL, szNamePath, MAX_PATH);
WCHAR *szProgName = PathFindFileName(szNamePath);
po::options_description desc("Options");
desc.add_options()
("help,h", "Print help page and exit")
("version,V", "Print version and exit")
("warning,w", po::wvalue<std::wstring>(), "Warning thershold")
("critical,c", po::wvalue<std::wstring>(), "Critical threshold")
("performance-counter,P", po::wvalue<std::wstring>(), "The performance counter string to use")
("performance-wait", po::value<DWORD>(), "Sleep in milliseconds between the two perfomance querries (Default: 1000ms)")
("fmt-countertype", po::wvalue<std::wstring>(), "Value type of counter: 'double'(default), 'long', 'int64'")
("print-objects", "Prints all available objects to console")
("print-object-info", "Prints all available instances and counters of --performance-counter, do not use a full perfomance counter string here")
;
po::basic_command_line_parser<wchar_t> parser(ac, av);
try {
po::store(
parser
.options(desc)
.style(
po::command_line_style::unix_style |
po::command_line_style::allow_long_disguise)
.run(),
vm);
vm.notify();
} catch (std::exception& e) {
std::cout << e.what() << '\n' << desc << '\n';
return FALSE;
}
if (vm.count("version")) {
std::wcout << "Version: " << VERSION << '\n';
return FALSE;
}
if (vm.count("help")) {
std::wcout << szProgName << " Help\n\tVersion: " << VERSION << '\n';
wprintf(
L"%s runs a check against a performance counter.\n"
L"You can use the following options to define its behaviour:\n\n", szProgName);
std::cout << desc;
wprintf(
L"\nIt will then output a string looking something like this:\n\n"
L"\tPERFMON CRITICAL \"\\Processor(_Total)\\%% Idle Time\" = 40.34 | "
L"perfmon=40.34;20;40;; \"\\Processor(_Total)\\%% Idle Time\"=40.34\n\n"
L"\"tPERFMON\" being the type of the check, \"CRITICAL\" the returned status\n"
L"and \"40.34\" is the performance counters value.\n"
L"%s' exit codes denote the following:\n"
L" 0\tOK,\n\tNo Thresholds were exceeded\n"
L" 1\tWARNING,\n\tThe warning was broken, but not the critical threshold\n"
L" 2\tCRITICAL,\n\tThe critical threshold was broken\n"
L" 3\tUNKNOWN, \n\tNo check could be performed\n\n"
, szProgName);
return 0;
}
if (vm.count("warning")) {
try {
printInfo.tWarn = threshold(vm["warning"].as<std::wstring>());
} catch (std::invalid_argument& e) {
std::wcout << e.what() << '\n';
return FALSE;
}
}
if (vm.count("critical")) {
try {
printInfo.tCrit = threshold(vm["critical"].as<std::wstring>());
} catch (std::invalid_argument& e) {
std::wcout << e.what() << '\n';
return FALSE;
}
}
if (vm.count("fmt-countertype")) {
if (!vm["fmt-countertype"].as<std::wstring>().compare(L"int64"))
printInfo.dwRequestedType = PDH_FMT_LARGE;
else if (!vm["fmt-countertype"].as<std::wstring>().compare(L"long"))
printInfo.dwRequestedType = PDH_FMT_LONG;
else if (vm["fmt-countertype"].as<std::wstring>().compare(L"double")) {
std::wcout << "Unknown value type " << vm["fmt-countertype"].as<std::wstring>() << '\n';
return FALSE;
}
}
if (vm.count("performance-counter"))
printInfo.wsFullPath = vm["performance-counter"].as<std::wstring>();
if (vm.count("performance-wait"))
printInfo.dwPerformanceWait = vm["performance-wait"].as<DWORD>();
return TRUE;
}