Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

856 Args: CLI I/O config files #857

Merged
merged 5 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/vt/configs/arguments/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ namespace vt { namespace arguments {
/*static*/ std::string ArgConfig::vt_user_str_2 = "";
/*static*/ std::string ArgConfig::vt_user_str_3 = "";

/*static*/ bool ArgConfig::vt_output_config = false;
/*static*/ std::string ArgConfig::vt_output_config_file = "vt_config.ini";
/*static*/ std::string ArgConfig::vt_output_config_str = "";

/*static*/ std::string ArgConfig::prog_name {"vt_unknown"};
/*static*/ char* ArgConfig::argv_prog_name{const_cast<char*>("vt_unknown")};

Expand All @@ -191,7 +195,10 @@ void addColorArgs(CLI::App& app) {
a->group(outputGroup);
b->group(outputGroup);
a1->group(outputGroup);
b->excludes(a);
// Do not exclude 'a' from 'b' here because when inputting/outputting a
// config, both will be written out causing an error when reading a written
// input file with defaults
// b->excludes(a);
}

void addSignalArgs(CLI::App& app) {
Expand Down Expand Up @@ -558,6 +565,18 @@ void addSchedulerArgs(CLI::App& app) {
kca->group(schedulerGroup);
}

void addConfigFileArgs(CLI::App& app) {
auto doconfig = "Output all VT args to configuration file";
auto configname = "Name of configuration file to output";

auto a1 = app.add_flag("--vt_output_config", ArgConfig::vt_output_config, doconfig);
auto a2 = app.add_option("--vt_output_config_file", ArgConfig::vt_output_config_file, configname, true);

auto configGroup = "Configuration File";
a1->group(configGroup);
a2->group(configGroup);
}

class VtFormatter : public CLI::Formatter {
public:
std::string make_usage(const CLI::App *, std::string name) const override {
Expand Down Expand Up @@ -611,6 +630,7 @@ std::tuple<int, std::string> parseArguments(CLI::App& app, int& argc, char**& ar
addDebuggerArgs(app);
addUserArgs(app);
addSchedulerArgs(app);
addConfigFileArgs(app);

std::tuple<int, std::string> result = parseArguments(app, /*out*/ argc, /*out*/ argv);
if (std::get<0>(result) not_eq -1) {
Expand Down Expand Up @@ -669,6 +689,14 @@ std::tuple<int, std::string> parseArguments(CLI::App& app, int& argc, char**& ar
args_to_parse.push_back(*it);
}

// Allow a input config file
app.set_config(
lifflander marked this conversation as resolved.
Show resolved Hide resolved
"--vt_input_config",
"", // no default file name
"Read in an ini config file for VT",
false // not required
);

try {
app.parse(args_to_parse);
} catch (CLI::Error &ex) {
Expand All @@ -680,6 +708,12 @@ std::tuple<int, std::string> parseArguments(CLI::App& app, int& argc, char**& ar
return std::make_tuple(result, message_stream.str());
}

// If the user specified to output the full configuration, save it in a string
// so node 0 can output in the runtime once MPI is init'ed
if (ArgConfig::vt_output_config) {
ArgConfig::vt_output_config_str = app.config_to_str(true, true);
}

// Get the clean prog name; don't allow path bleed in usages.
// std::filesystem is C++17.
std::string prog_name = argv[0];
Expand Down
4 changes: 4 additions & 0 deletions src/vt/configs/arguments/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ struct ArgConfig {
static std::string vt_user_str_2;
static std::string vt_user_str_3;

static bool vt_output_config;
static std::string vt_output_config_file;
static std::string vt_output_config_str;

/// Name of the program launched (excluding any path!)
static std::string prog_name;

Expand Down
9 changes: 9 additions & 0 deletions src/vt/runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#include <string>
#include <vector>
#include <tuple>
#include <fstream>

#include <cstdio>
#include <cstdint>
Expand Down Expand Up @@ -350,6 +351,14 @@ bool Runtime::initialize(bool const force_now) {
theSched->enqueue([this]{
this->checkForArgumentErrors();
});

// If the user specified to output a configuration file, write it to the
// specified file on rank 0
if (ArgType::vt_output_config) {
std::ofstream out(ArgType::vt_output_config_file);
out << ArgType::vt_output_config_str;
out.close();
}
}
setup();
sync();
Expand Down
14 changes: 14 additions & 0 deletions src/vt/runtime/runtime_banner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,20 @@ void Runtime::printStartupBanner() {
fmt::print("{}\t{}{}", vt_pre, f12, reset);
}

if (ArgType::vt_output_config) {
auto f11 = fmt::format("Enabled configuration output");
auto f12 = opt_on("--vt_output_config", f11);
fmt::print("{}\t{}{}", vt_pre, f12, reset);

if (ArgType::vt_output_config_file != "") {
auto f13 = fmt::format(
"Config file name \"{}\"", ArgType::vt_output_config_file
);
auto f14 = opt_on("--vt_output_config_file", f13);
fmt::print("{}\t{}{}", vt_pre, f14, reset);
}
}

if (ArgType::vt_memory_reporters != "") {
auto f11 = fmt::format(
"Memory usage checker precedence: {}",
Expand Down