Skip to content

Commit

Permalink
Merge pull request #1851 from DARMA-tasking/1850-add-cmdline-for-lbst…
Browse files Browse the repository at this point in the history
…ats-dir

#1850: allow setting dir where lb statistics are dumped
  • Loading branch information
nlslatt authored Jun 22, 2022
2 parents 7cfc5ec + 5e5a6ca commit 9f48ecd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/vt/collective/collective_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void printOverwrittens(
printIfOverwritten(vt_lb_statistics);
printIfOverwritten(vt_lb_statistics_compress);
printIfOverwritten(vt_lb_statistics_file);
printIfOverwritten(vt_lb_statistics_dir);
printIfOverwritten(vt_lb_self_migration);
printIfOverwritten(vt_help_lb_args);
printIfOverwritten(vt_no_detect_hang);
Expand Down
2 changes: 2 additions & 0 deletions src/vt/configs/arguments/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ struct AppConfig {
bool vt_lb_statistics = true;
bool vt_lb_statistics_compress = true;
std::string vt_lb_statistics_file = "vt_lb_statistics.%t.json";
std::string vt_lb_statistics_dir = "";
bool vt_help_lb_args = false;
bool vt_lb_self_migration = false;

Expand Down Expand Up @@ -322,6 +323,7 @@ struct AppConfig {
| vt_lb_statistics
| vt_lb_statistics_compress
| vt_lb_statistics_file
| vt_lb_statistics_dir
| vt_help_lb_args
| vt_lb_self_migration

Expand Down
8 changes: 8 additions & 0 deletions src/vt/configs/arguments/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ void addLbArgs(CLI::App& app, AppConfig& appConfig) {
auto lb_statistics = "Dump load balancing statistics to file";
auto lb_statistics_comp = "Compress load balancing statistics file with brotli";
auto lb_statistics_file = "Load balancing statistics output file name";
auto lb_statistics_dir = "Load balancing statistics output directory name";
auto lb_self_migration = "Allow load balancer to migrate objects to the same node";
auto lbn = "NoLB";
auto lbi = 1;
Expand All @@ -490,6 +491,7 @@ void addLbArgs(CLI::App& app, AppConfig& appConfig) {
auto lbs = "data";
auto lba = "";
auto lbq = "vt_lb_statistics.%t.json";
auto lbqq = "";
auto s = app.add_flag("--vt_lb", appConfig.vt_lb, lb);
auto t1 = app.add_flag("--vt_lb_quiet", appConfig.vt_lb_quiet, lb_quiet);
auto u = app.add_option("--vt_lb_file_name", appConfig.vt_lb_file_name, lb_file_name, lbf)->check(CLI::ExistingFile);
Expand All @@ -507,6 +509,7 @@ void addLbArgs(CLI::App& app, AppConfig& appConfig) {
auto yx = app.add_flag("--vt_lb_statistics", appConfig.vt_lb_statistics, lb_statistics);
auto yy = app.add_flag("--vt_lb_statistics_compress", appConfig.vt_lb_statistics_compress, lb_statistics_comp);
auto yz = app.add_option("--vt_lb_statistics_file", appConfig.vt_lb_statistics_file, lb_statistics_file,lbq);
auto zz = app.add_option("--vt_lb_statistics_dir", appConfig.vt_lb_statistics_dir, lb_statistics_dir,lbqq);
auto lbasm = app.add_flag("--vt_lb_self_migration", appConfig.vt_lb_self_migration, lb_self_migration);

auto debugLB = "Load Balancing";
Expand All @@ -527,6 +530,7 @@ void addLbArgs(CLI::App& app, AppConfig& appConfig) {
yx->group(debugLB);
yy->group(debugLB);
yz->group(debugLB);
zz->group(debugLB);
lbasm->group(debugLB);

// help options deliberately omitted from the debugLB group above so that
Expand Down Expand Up @@ -836,6 +840,10 @@ std::string AppConfig::getLBDataFileIn() const {

std::string AppConfig::getLBStatisticsFile() const {
std::string name = vt_lb_statistics_file;
std::string dir = vt_lb_statistics_dir;
if (not dir.empty()) {
name = dir + "/" + name;
}
std::size_t timestamp = name.find("%t");
if (timestamp != std::string::npos) {
std::time_t t = std::time(nullptr);
Expand Down
13 changes: 13 additions & 0 deletions src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,19 @@ void LBManager::createStatisticsFile() {
"LBManager::createStatsFile: file={}\n", file_name
);

auto const dir = theConfig()->vt_lb_statistics_dir;
// Node 0 creates the directory
if (
theContext()->getNode() == 0 and
not dir.empty() and not created_lbstats_dir_
) {
int flag = mkdir(dir.c_str(), S_IRWXU);
if (flag < 0 && errno != EEXIST) {
throw std::runtime_error("Failed to create directory: " + dir);
}
created_lbstats_dir_ = true;
}

using JSONAppender = util::json::Appender<std::ofstream>;

if (not statistics_writer_) {
Expand Down
5 changes: 4 additions & 1 deletion src/vt/vrt/collection/balance/lb_invoke/lb_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ struct LBManager : runtime::component::Component<LBManager> {
| base_model_
| model_
| lb_instances_
| stats;
| stats
| created_lbstats_dir_;
}

void stagePreLBStatistics(const StatisticMapType &statistics);
Expand Down Expand Up @@ -291,6 +292,8 @@ struct LBManager : runtime::component::Component<LBManager> {
bool before_lb_stats_ = true;
/// The appender for outputting statistics in JSON format
std::unique_ptr<util::json::BaseAppender> statistics_writer_ = nullptr;
/// Whether the LB statistics directory has been created
bool created_lbstats_dir_ = false;
};

void makeGraphSymmetric(
Expand Down
5 changes: 4 additions & 1 deletion src/vt/vrt/collection/balance/node_lb_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ void NodeLBData::createLBDataFile() {
auto const dir = theConfig()->vt_lb_data_dir;
// Node 0 creates the directory
if (not created_dir_ and theContext()->getNode() == 0) {
mkdir(dir.c_str(), S_IRWXU);
int flag = mkdir(dir.c_str(), S_IRWXU);
if (flag < 0 && errno != EEXIST) {
throw std::runtime_error("Failed to create directory: " + dir);
}
created_dir_ = true;
}

Expand Down

0 comments on commit 9f48ecd

Please sign in to comment.