Skip to content

Commit

Permalink
#2074: Update data selection for offlineLB sparse test
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Nov 30, 2023
1 parent a649bea commit 77911e8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
13 changes: 6 additions & 7 deletions src/vt/vrt/collection/balance/lb_data_restart_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ struct LBDataRestartReader : runtime::component::Component<LBDataRestartReader>
*
* \param[in] phase the phase
*
* \return pointer to elements assigned to this node, guaranteed to be not null
* \return pointer to elements assigned to this node if not skipped
*/
std::shared_ptr<const std::set<ElementIDStruct>> getDistro(PhaseType phase) const {
auto iter = history_.find(phase);
vtAssert(iter != history_.end() && iter->second != nullptr, "Must have a valid phase");
return iter->second;
if (iter != history_.end()) {
return iter->second;
}
return nullptr;
}

/**
Expand All @@ -142,10 +144,7 @@ struct LBDataRestartReader : runtime::component::Component<LBDataRestartReader>
* \param[in] phase the phase to clear
*/
void clearDistro(PhaseType phase) {
auto iter = history_.find(phase);
if (iter != history_.end()) {
history_.erase(iter);
}
history_.erase(phase);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/vt/vrt/collection/balance/offlinelb/offlinelb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ void OfflineLB::init(objgroup::proxy::Proxy<OfflineLB> in_proxy) {

void OfflineLB::runLB(LoadType) {
auto const distro = theLBDataReader()->getDistro(phase_ + 1);
for (auto&& elm : *distro) {
migrateObjectTo(elm, theContext()->getNode());
if (distro) {
for (auto&& elm : *distro) {
migrateObjectTo(elm, theContext()->getNode());
}
theLBDataReader()->clearDistro(phase_ + 1);
}
theLBDataReader()->clearDistro(phase_ + 1);
}

}}}} /* end namespace vt::vrt::collection::lb */
57 changes: 36 additions & 21 deletions tests/unit/lb/test_offlinelb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,15 @@ struct SimCol : vt::Collection<SimCol, vt::Index1D> {

void sparseHandler(Msg* m){
auto const this_node = theContext()->getNode();
auto const num_nodes = theContext()->getNumNodes();
auto const next_node = (this_node + 1) % num_nodes;
auto const prev_node = this_node - 1 >= 0 ? this_node - 1 : num_nodes - 1;
vt_debug_print(terse, lb, "sparseHandler: idx={}: elm={}\n", getIndex(), getElmID());
if (m->iter >= 0 and m->iter <= 6) {
if (m->iter == 7 or m->iter == 8 or m->iter == 9) {
EXPECT_EQ(getIndex().x() / 2, next_node);
} else if (m->iter == 4 or m-> iter == 5) {
EXPECT_EQ(getIndex().x() / 2, prev_node);
} else {
EXPECT_EQ(getIndex().x() / 2, this_node);
}
}
Expand Down Expand Up @@ -171,8 +178,8 @@ TEST_F(TestOfflineLB, test_offlinelb_2) {

std::unordered_map<PhaseType, std::vector<ElementIDStruct>> ids;
int len = 2;
PhaseType num_phases = 7;
for (int i = 0; i < len; i++) {
PhaseType num_phases = 10;
for (int i = 0; i < len * 2; i++) {
auto id = elm::ElmIDBits::createCollectionImpl(true, i+1, this_node, this_node);
id.curr_node = this_node;
ids[0].push_back(id);
Expand All @@ -183,51 +190,59 @@ TEST_F(TestOfflineLB, test_offlinelb_2) {
}

for (int i = 0; i < len; i++) {
auto pid = elm::ElmIDBits::createCollectionImpl(true, i+1, prev_node, this_node);
auto nid = elm::ElmIDBits::createCollectionImpl(true, i+1, next_node, this_node);
ids[1].push_back(pid);
ids[2].push_back(pid);
ids[4].push_back(nid);
ids[5].push_back(nid);
auto pid = elm::ElmIDBits::createCollectionImpl(true, i+1, prev_node, this_node);
ids[4].push_back(pid);
ids[7].push_back(nid);
}

LBDataHolder dh;
for (PhaseType i = 0; i < num_phases; i++) {
for (auto&& elm : ids[i]) {
dh.node_data_[i][elm] = LoadSummary{3};
if (i != 1 and i != 2 and i != 5 and i != 8 and i != 9) {
auto& elms = ids[i];
for(std::size_t j = 0; j < elms.size(); j++) {
dh.node_data_[i][elms[j]] = LoadSummary{ static_cast<double>(i + j) + 3};
}
}
}

using JSONAppender = util::json::Appender<std::stringstream>;
std::stringstream stream{std::ios_base::out | std::ios_base::in};
nlohmann::json metadata, phasesMetadata;
phasesMetadata["count"] = num_phases;
phasesMetadata["skipped"]["list"] = {2};
phasesMetadata["skipped"]["range"] = {{3,3}};
phasesMetadata["identical_to_previous"]["list"] = {1};
phasesMetadata["identical_to_previous"]["range"] = {{5,6}};
phasesMetadata["skipped"]["list"] = {9};
phasesMetadata["skipped"]["range"] = {{1,2}};
phasesMetadata["identical_to_previous"]["list"] = {8};
phasesMetadata["identical_to_previous"]["range"] = {{5,5}};
metadata["type"] = "LBDatafile";
metadata["phases"] = phasesMetadata;

auto appender = std::make_unique<JSONAppender>(
"phases", metadata, std::move(stream), true
);
// Add phases 0 and 4
appender->addElm(*dh.toJson(0));
appender->addElm(*dh.toJson(4));
for (PhaseType i = 0; i < num_phases; i++) {
// ignore skipped and identical phases
if(i != 1 and i != 2 and i != 5 and i != 8 and i != 9) {
auto j = dh.toJson(i);
appender->addElm(*j);
}
}
stream = appender->finish();

// Preapre configuration file
std::string file_name = getUniqueFilenameWithRanks(".txt");
std::ofstream out(file_name);
out << ""
"0 OfflineLB\n"
"1 NoLB\n"
"2 NoLB\n"
"3 NoLB\n"
"1 OfflineLB\n"
"2 OfflineLB\n"
"3 OfflineLB\n"
"4 OfflineLB\n"
"5 OfflineLB\n"
"6 NoLB\n";
"6 OfflineLB\n"
"7 OfflineLB\n"
"8 OfflineLB\n"
"9 OfflineLB\n";
out.close();

theConfig()->vt_lb = true;
Expand Down

0 comments on commit 77911e8

Please sign in to comment.