From d8ae133023c55d9ecbd9aa969d8dc79b31237d13 Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Thu, 30 Nov 2023 19:05:14 +0100 Subject: [PATCH] #2074: Update data selection for offlineLB sparse test --- .../balance/lb_data_restart_reader.h | 13 ++--- .../collection/balance/offlinelb/offlinelb.cc | 8 ++- tests/unit/lb/test_offlinelb.cc | 57 ++++++++++++------- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_data_restart_reader.h b/src/vt/vrt/collection/balance/lb_data_restart_reader.h index 6298d7079d..830ff4aa5e 100644 --- a/src/vt/vrt/collection/balance/lb_data_restart_reader.h +++ b/src/vt/vrt/collection/balance/lb_data_restart_reader.h @@ -128,12 +128,14 @@ struct LBDataRestartReader : runtime::component::Component * * \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> 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; } /** @@ -142,10 +144,7 @@ struct LBDataRestartReader : runtime::component::Component * \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); } /** diff --git a/src/vt/vrt/collection/balance/offlinelb/offlinelb.cc b/src/vt/vrt/collection/balance/offlinelb/offlinelb.cc index b9abd6d03f..a7ddb3aad8 100644 --- a/src/vt/vrt/collection/balance/offlinelb/offlinelb.cc +++ b/src/vt/vrt/collection/balance/offlinelb/offlinelb.cc @@ -56,10 +56,12 @@ void OfflineLB::init(objgroup::proxy::Proxy 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 */ diff --git a/tests/unit/lb/test_offlinelb.cc b/tests/unit/lb/test_offlinelb.cc index bcef890abd..db83c49c68 100644 --- a/tests/unit/lb/test_offlinelb.cc +++ b/tests/unit/lb/test_offlinelb.cc @@ -78,8 +78,15 @@ struct SimCol : vt::Collection { 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); } } @@ -171,8 +178,8 @@ TEST_F(TestOfflineLB, test_offlinelb_2) { std::unordered_map> 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); @@ -183,18 +190,19 @@ 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(i + j) + 3}; + } } } @@ -202,19 +210,23 @@ TEST_F(TestOfflineLB, test_offlinelb_2) { 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( "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 @@ -222,12 +234,15 @@ TEST_F(TestOfflineLB, test_offlinelb_2) { 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;