Skip to content

Commit

Permalink
#2074: Add tests for detecting OfflineLB in LB data file
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed May 22, 2023
1 parent 74b491b commit a584f19
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/vt/vrt/collection/balance/read_lb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace vt { namespace vrt { namespace collection { namespace balance {
/*static*/ typename ReadLBConfig::ConfigMapType ReadLBConfig::config_exact_ = {};
/*static*/ std::vector<ConfigIndex> ReadLBConfig::config_prec_ = {};
/*static*/ bool ReadLBConfig::read_complete_ = false;
/*static*/ bool ReadLBConfig::has_offline_lb_ = false;

/*static*/ bool ReadLBConfig::openConfig(std::string const& filename) {
// No-op if no file specified. Can't be used to clear.
Expand Down Expand Up @@ -102,15 +103,6 @@ namespace vt { namespace vrt { namespace collection { namespace balance {
}
}

/*static*/ bool ReadLBConfig::hasOfflineLB() {
for(auto&& ele : config_exact_) {
if(getLB(ele.first) == LBType::OfflineLB) {
return true;
}
}
return false;
}

/*static*/ ConfigEntry* ReadLBConfig::entry(ConfigIndex const& idx) {
// First, search the exact iter config for this iteration: it has the highest
// precedence
Expand Down Expand Up @@ -240,6 +232,10 @@ int eatWhitespace(std::ifstream& file) {
vtAbort(err_msg);
}

if (lb_name == get_lb_names()[LBType::OfflineLB]) {
has_offline_lb_ = true;
}

map->emplace(
std::piecewise_construct,
std::forward_as_tuple(mod),
Expand All @@ -252,6 +248,7 @@ int eatWhitespace(std::ifstream& file) {

/*static*/ void ReadLBConfig::clear() {
read_complete_ = false;
has_offline_lb_ = false;
open_filename_ = "";
config_mod_.clear();
config_exact_.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/vt/vrt/collection/balance/read_lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ struct ReadLBConfig {
static ConfigIndex numEntries() { return config_mod_.size() + config_exact_.size(); }
static ConfigEntry* entry(ConfigIndex const& idx);
static LBType getLB(ConfigIndex const& idx);
static bool hasOfflineLB();
static bool hasOfflineLB() { return has_offline_lb_; };
static ConfigMapType getModEntries() { return config_mod_; };
static ConfigMapType getExactEntries() {return config_exact_; };
static ParamMapType parseParams(std::vector<std::string> params);
Expand All @@ -209,6 +209,7 @@ struct ReadLBConfig {
static void readFile(std::string const& filename);

static bool read_complete_;
static bool has_offline_lb_;
static std::string open_filename_;
static ConfigMapType config_mod_;
static ConfigMapType config_exact_;
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/lb/test_lb_reader.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ TEST_F(TestLBReader, test_lb_read_1) {
Config::clear();
Config::openConfig(file_name);

EXPECT_EQ(Config::hasOfflineLB(), false);
EXPECT_EQ(Config::numEntries(), 3);
EXPECT_EQ(Config::getExactEntries().size(), 2);
EXPECT_EQ(Config::getModEntries().size(), 1);
Expand Down Expand Up @@ -120,6 +121,7 @@ TEST_F(TestLBReader, test_lb_read_2) {
Config::clear();
Config::openConfig(file_name);

EXPECT_EQ(Config::hasOfflineLB(), false);
EXPECT_EQ(Config::numEntries(), 5);
for (ConfigIdx i = 0; i < 121; i++) {
auto entry = Config::entry(i);
Expand Down Expand Up @@ -195,4 +197,20 @@ TEST_F(TestLBReader, test_lb_read_2) {
EXPECT_EQ(Config::toString(), expected_config);
}

TEST_F(TestLBReader, test_lb_read_3_with_offline_lb) {
std::string file_name = "test_lb_read_3.txt";
std::ofstream out(file_name);
out << ""
"0 NoLB\n"
"1 OfflineLB\n"
"%10 OfflineLB\n";
out.close();

using Config = vt::vrt::collection::balance::ReadLBConfig;

Config::clear();
Config::openConfig(file_name);
EXPECT_EQ(Config::hasOfflineLB(), true);
}

}}} // end namespace vt::tests::unit
1 change: 0 additions & 1 deletion tests/unit/lb/test_offlinelb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ struct SimCol : vt::Collection<SimCol, vt::Index1D> {
}

void sparseHandler(Msg* m){
// TODO
}
};

Expand Down

0 comments on commit a584f19

Please sign in to comment.