Skip to content

Commit

Permalink
#984 print LB specification during startup
Browse files Browse the repository at this point in the history
- allow printing LB specification during startup
- make documentation consistent with usage info
- remove --vt_lb_file option and rely only on --vt_lb_file_name
  • Loading branch information
cz4rs committed Aug 13, 2020
1 parent e5243ed commit 782b24b
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 49 deletions.
2 changes: 1 addition & 1 deletion docs/md/lb-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ instrumentation of work and communication performed by collection elements.

To run a load balancer at runtime:
- Pass `--vt_lb --vt_lb_name=<LB>` as a command line argument
- Write a LB specification file `--vt_lb --vt_lb_file --vt_lb_file_name=<FILE>`
- Write a LB specification file `--vt_lb --vt_lb_file_name=<FILE>`

\section lb-specification-file LB Specification File

Expand Down
1 change: 0 additions & 1 deletion src/vt/configs/arguments/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ struct AppConfig {
bool vt_trace_irecv_polling = false;

bool vt_lb = false;
bool vt_lb_file = false;
bool vt_lb_print_file = false;
bool vt_lb_quiet = false;
std::string vt_lb_file_name = "";
Expand Down
11 changes: 4 additions & 7 deletions src/vt/configs/arguments/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,10 @@ void ArgConfig::addLbArgs(CLI::App& app) {
* Flags for enabling load balancing and configuring it
*/
auto lb = "Enable load balancing";
auto lb_file = "Enable reading LB configuration from file";
auto lb_print_file = "Print LB configuration file";
auto lb_args = "Arguments pass to LB: \"x=0 y=1 test=2\"";
auto lb_quiet = "Silence load balancing output";
auto lb_file_name = "LB configuration file to read";
auto lb_file_name = "LB specification file to read";
auto lb_print_file = "Print LB specification file during startup";
auto lb_name = "Name of the load balancer to use";
auto lb_interval = "Load balancing interval";
auto lb_stats = "Enable load balancing statistics";
Expand All @@ -343,11 +342,10 @@ void ArgConfig::addLbArgs(CLI::App& app) {
auto lbs = "stats";
auto lba = "";
auto s = app.add_flag("--vt_lb", config_.vt_lb, lb);
auto t = app.add_flag("--vt_lb_file", config_.vt_lb_file, lb_file);
auto tp = app.add_flag("--vt_lb_print_file", config_.vt_lb_print_file, lb_print_file);
auto t1 = app.add_flag("--vt_lb_quiet", config_.vt_lb_quiet, lb_quiet);
auto u = app.add_option("--vt_lb_file_name", config_.vt_lb_file_name, lb_file_name, lbf)
->check(CLI::ExistingFile);
auto u1 = app.add_flag("--vt_lb_print_file", config_.vt_lb_print_file, lb_print_file);
auto v = app.add_option("--vt_lb_name", config_.vt_lb_name, lb_name, lbn);
auto v1 = app.add_option("--vt_lb_args", config_.vt_lb_args, lb_args, lba);
auto w = app.add_option("--vt_lb_interval", config_.vt_lb_interval, lb_interval, lbi);
Expand All @@ -359,10 +357,9 @@ void ArgConfig::addLbArgs(CLI::App& app) {

auto debugLB = "Load Balancing";
s->group(debugLB);
t->group(debugLB);
tp->group(debugLB);
t1->group(debugLB);
u->group(debugLB);
u1->group(debugLB);
v->group(debugLB);
v1->group(debugLB);
w->group(debugLB);
Expand Down
51 changes: 35 additions & 16 deletions src/vt/runtime/runtime_banner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "vt/configs/generated/vt_git_revision.h"
#include "vt/utils/mpi_limits/mpi_max_tag.h"
#include "vt/vrt/collection/balance/lb_type.h"
#include "vt/vrt/collection/balance/read_lb.h"
#include "vt/utils/memory/memory_usage.h"
#include "vt/scheduler/scheduler.h"

Expand All @@ -62,6 +63,32 @@

#include <mpi.h>

void printLBConfig(std::string const& filename) {
using Spec = vt::vrt::collection::balance::ReadLBSpec;

Spec::openFile(filename);
Spec::readFile();

for (auto const& exact_entry : Spec::getExactEntries()) {
std::string formatted_params;
for (auto const& param : exact_entry.second.getParams()) {
formatted_params += fmt::format("{}={} ", param.first, param.second);
}

fmt::print("Run `{}` on phase {} with arguments `{}`\n", exact_entry.second.getName(), exact_entry.second.getIdx(), formatted_params);
}
for (auto const& mod_entry : Spec::getModEntries()) {
std::string formatted_params;
for (auto const& param : mod_entry.second.getParams()) {
formatted_params += fmt::format("{}={} ", param.first, param.second);
}

fmt::print("Run `{}` every {} phases with arguments `{}`\n", mod_entry.second.getName(), mod_entry.second.getIdx(), formatted_params);
}

return;
}

namespace vt { namespace runtime {

void Runtime::printStartupBanner() {
Expand Down Expand Up @@ -280,23 +307,15 @@ void Runtime::printStartupBanner() {
if (getAppConfig()->vt_lb) {
auto f9 = opt_on("--vt_lb", "Load balancing enabled");
fmt::print("{}\t{}{}", vt_pre, f9, reset);
if (getAppConfig()->vt_lb_file) {
if (getAppConfig()->vt_lb_file_name == "") {
auto warn_lb_file = fmt::format(
"{}Warning:{} {}{}{} has no effect: compile-time"
" option {}{}{} is empty{}\n", red, reset, magenta, "--vt_lb_file",
reset, magenta, "--vt_lb_file_name", reset, reset
);
fmt::print("{}\t{}{}", vt_pre, warn_lb_file, reset);
} else {
auto f10 = opt_on("--vt_lb_file", "Reading LB config from file");
fmt::print("{}\t{}{}", vt_pre, f10, reset);
auto f12 = fmt::format("Reading file \"{}\"", getAppConfig()->vt_lb_file_name);
auto f11 = opt_on("--vt_lb_file_name", f12);
fmt::print("{}\t{}{}", vt_pre, f11, reset);
}
if (getAppConfig()->vt_lb_file_name != "") {
auto f10 = opt_on("--vt_lb_file", "Reading LB config from file");
fmt::print("{}\t{}{}", vt_pre, f10, reset);
auto f12 = fmt::format("Reading file \"{}\"", getAppConfig()->vt_lb_file_name);
auto f11 = opt_on("--vt_lb_file_name", f12);
fmt::print("{}\t{}{}", vt_pre, f11, reset);

if (getAppConfig()->vt_lb_print_file) {
fmt::print("Print LB configuration file here\n");
printLBConfig(getAppConfig()->vt_lb_file_name);
}
} else {
auto a3 = fmt::format("Load balancer name: \"{}\"", getAppConfig()->vt_lb_name);
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ LBType LBManager::decideLBToRun(PhaseType phase, bool try_file) {
return LBType::NoLB;
}

if (theConfig()->vt_lb_file and try_file) {
if (theConfig()->vt_lb_file_name != "" and try_file) {
bool const has_spec = ReadLBSpec::hasSpec();
if (has_spec) {
the_lb = ReadLBSpec::getLB(phase);
Expand Down
34 changes: 13 additions & 21 deletions src/vt/vrt/collection/balance/read_lb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,28 @@
namespace vt { namespace vrt { namespace collection { namespace balance {

/*static*/ std::string ReadLBSpec::filename = {};
/*static*/ SpecIndex ReadLBSpec::num_entries_ = 0;
/*static*/ typename ReadLBSpec::SpecMapType ReadLBSpec::spec_mod_ = {};
/*static*/ typename ReadLBSpec::SpecMapType ReadLBSpec::spec_exact_ = {};
/*static*/ std::vector<SpecIndex> ReadLBSpec::spec_prec_ = {};
/*static*/ bool ReadLBSpec::read_complete_ = false;

/*static*/ bool ReadLBSpec::hasSpec() {
if (not theConfig()->vt_lb_file) {
return false;
}
if (read_complete_) {
return true;
} else {
auto const file_name = theConfig()->vt_lb_file_name;
if (file_name == "") {
vtAbort(
"--vt_lb_file enabled but no file name is specified: --vt_lb_file_name"
);
return false;
} else {
bool good = openFile(file_name);
if (not good) {
auto str =
fmt::format("--vt_lb_file_name={} is not a valid file", file_name);
vtAbort(str);
}
return good;
}
}

auto const file_name = theConfig()->vt_lb_file_name;
if (file_name == "") {
return false;
}

bool good = openFile(file_name);
if (not good) {
auto str =
fmt::format("--vt_lb_file_name={} is not a valid file", file_name);
vtAbort(str);
}
return good;
}

/*static*/ bool ReadLBSpec::openFile(std::string const name) {
Expand Down Expand Up @@ -252,7 +245,6 @@ int eatWhitespace(std::ifstream& file) {
/*static*/ void ReadLBSpec::clear() {
read_complete_ = false;
filename = "";
num_entries_ = 0;
spec_mod_.clear();
spec_exact_.clear();
spec_prec_.clear();
Expand Down
6 changes: 4 additions & 2 deletions src/vt/vrt/collection/balance/read_lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct SpecEntry {

SpecIndex getIdx() const { return idx_; }
std::string getName() const { return lb_name_; }
std::unordered_map<std::string, std::string> getParams() const { return params_; }
LBType getLB() const {
for (auto&& elm : lb_names_) {
if (lb_name_ == elm.second) {
Expand Down Expand Up @@ -182,17 +183,18 @@ struct ReadLBSpec {
static void readFile();

static bool hasSpec();
static SpecIndex numEntries() { return num_entries_; }
static SpecIndex numEntries() { return spec_mod_.size() + spec_exact_.size(); }
static SpecEntry* entry(SpecIndex const& idx);
static LBType getLB(SpecIndex const& idx);
static SpecMapType getModEntries() { return spec_mod_; };
static SpecMapType getExactEntries() {return spec_exact_; };
static ParamMapType parseParams(std::vector<std::string> params);
static SpecEntry makeSpecFromParams(std::string params);
static void clear();

private:
static bool read_complete_;
static std::string filename;
static SpecIndex num_entries_;
static SpecMapType spec_mod_;
static SpecMapType spec_exact_;
static std::vector<SpecIndex> spec_prec_;
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/lb/test_lb_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ TEST_F(TestLBReader, test_lb_read_1) {
Spec::openFile(file_name);
Spec::readFile();

EXPECT_EQ(Spec::numEntries(), 3);
for (SpecIdx i = 0; i < 21; i++) {
auto entry = Spec::entry(i);
switch (i) {
Expand Down Expand Up @@ -109,6 +110,7 @@ TEST_F(TestLBReader, test_lb_read_2) {
Spec::openFile(file_name);
Spec::readFile();

EXPECT_EQ(Spec::numEntries(), 5);
for (SpecIdx i = 0; i < 121; i++) {
auto entry = Spec::entry(i);
switch (i) {
Expand Down

0 comments on commit 782b24b

Please sign in to comment.