From cdd1e20256ae2cf430d3b6309397d65be9843901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Mon, 3 Jun 2024 18:22:16 +0200 Subject: [PATCH 1/4] #2279: collection: synthesize home: 0 id: 0 task in LBData JSON ouput --- src/vt/vrt/collection/balance/lb_data_holder.cc | 14 +++++++++++++- src/vt/vrt/collection/balance/lb_data_holder.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/vt/vrt/collection/balance/lb_data_holder.cc b/src/vt/vrt/collection/balance/lb_data_holder.cc index 15ffd34827..64d20a67c2 100644 --- a/src/vt/vrt/collection/balance/lb_data_holder.cc +++ b/src/vt/vrt/collection/balance/lb_data_holder.cc @@ -144,13 +144,25 @@ std::unique_ptr LBDataHolder::rankAttributesToJson() const { return std::make_unique(std::move(j)); } +void LBDataHolder::addInitialTask(nlohmann::json& j, PhaseType phase) const { + if (phase == 0) { + j["tasks"][0]["resource"] = "cpu"; + j["tasks"][0]["node"] = vt::theContext()->getNode(); + j["tasks"][0]["time"] = 0; + outputEntity( + j["tasks"][0]["entity"], ElementIDStruct() + ); + } +} + std::unique_ptr LBDataHolder::toJson(PhaseType phase) const { using json = nlohmann::json; json j; j["id"] = phase; + addInitialTask(j, phase); - std::size_t i = 0; + std::size_t i = 1; if (node_data_.find(phase) != node_data_.end()) { for (auto&& elm : node_data_.at(phase)) { ElementIDStruct id = elm.first; diff --git a/src/vt/vrt/collection/balance/lb_data_holder.h b/src/vt/vrt/collection/balance/lb_data_holder.h index 39af9eded7..7d6ce1382d 100644 --- a/src/vt/vrt/collection/balance/lb_data_holder.h +++ b/src/vt/vrt/collection/balance/lb_data_holder.h @@ -125,6 +125,8 @@ struct LBDataHolder { */ void outputEntity(nlohmann::json& j, ElementIDStruct const& elm_id) const; + void addInitialTask(nlohmann::json& j, PhaseType phase) const; + /** * \brief Read the LB phase's metadata * From a9e1c15a43de68437d9aa73cc8ad223f0330a5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Sat, 8 Jun 2024 00:46:57 +0200 Subject: [PATCH 2/4] #2279: only add initial task when data is found --- .../vrt/collection/balance/lb_data_holder.cc | 23 ++++++++++--------- .../vrt/collection/balance/lb_data_holder.h | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/vt/vrt/collection/balance/lb_data_holder.cc b/src/vt/vrt/collection/balance/lb_data_holder.cc index 64d20a67c2..fdc1487606 100644 --- a/src/vt/vrt/collection/balance/lb_data_holder.cc +++ b/src/vt/vrt/collection/balance/lb_data_holder.cc @@ -144,15 +144,13 @@ std::unique_ptr LBDataHolder::rankAttributesToJson() const { return std::make_unique(std::move(j)); } -void LBDataHolder::addInitialTask(nlohmann::json& j, PhaseType phase) const { - if (phase == 0) { - j["tasks"][0]["resource"] = "cpu"; - j["tasks"][0]["node"] = vt::theContext()->getNode(); - j["tasks"][0]["time"] = 0; - outputEntity( - j["tasks"][0]["entity"], ElementIDStruct() - ); - } +void LBDataHolder::addInitialTask(nlohmann::json& j, std::size_t n) const { + j["tasks"][n]["resource"] = "cpu"; + j["tasks"][n]["node"] = vt::theContext()->getNode(); + j["tasks"][n]["time"] = 0; + outputEntity( + j["tasks"][n]["entity"], ElementIDStruct() + ); } std::unique_ptr LBDataHolder::toJson(PhaseType phase) const { @@ -160,9 +158,8 @@ std::unique_ptr LBDataHolder::toJson(PhaseType phase) const { json j; j["id"] = phase; - addInitialTask(j, phase); - std::size_t i = 1; + std::size_t i = 0; if (node_data_.find(phase) != node_data_.end()) { for (auto&& elm : node_data_.at(phase)) { ElementIDStruct id = elm.first; @@ -206,6 +203,10 @@ std::unique_ptr LBDataHolder::toJson(PhaseType phase) const { i++; } + + if ((phase == 0) and (i > 0)) { + addInitialTask(j, i); + } } i = 0; diff --git a/src/vt/vrt/collection/balance/lb_data_holder.h b/src/vt/vrt/collection/balance/lb_data_holder.h index 7d6ce1382d..a3badad166 100644 --- a/src/vt/vrt/collection/balance/lb_data_holder.h +++ b/src/vt/vrt/collection/balance/lb_data_holder.h @@ -125,7 +125,7 @@ struct LBDataHolder { */ void outputEntity(nlohmann::json& j, ElementIDStruct const& elm_id) const; - void addInitialTask(nlohmann::json& j, PhaseType phase) const; + void addInitialTask(nlohmann::json& j, std::size_t n) const; /** * \brief Read the LB phase's metadata From 5c569147ed01d7a7338921e39990493420619170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Mon, 10 Jun 2024 23:43:48 +0200 Subject: [PATCH 3/4] #2279: fix LBData restore test --- tests/unit/collection/test_lb.extended.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/collection/test_lb.extended.cc b/tests/unit/collection/test_lb.extended.cc index a865ef5113..a0395e3830 100644 --- a/tests/unit/collection/test_lb.extended.cc +++ b/tests/unit/collection/test_lb.extended.cc @@ -615,6 +615,10 @@ TEST_F(TestRestoreLBData, test_restore_lb_data_data_1) { auto &orig_load_map = phase_data.second; for (auto &entry : read_load_map) { auto read_elm_id = entry.first; + if ((read_elm_id.id == vt::elm::no_element_id) + and (read_elm_id.getHomeNode() == 0)) { + continue; + } EXPECT_FALSE(orig_load_map.find(read_elm_id) == orig_load_map.end()); if (orig_load_map.find(read_elm_id) == orig_load_map.end()) { fmt::print( From 615efe175cb04fb7fbfa3910ad5345cff22e1edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 11 Jun 2024 16:31:45 +0200 Subject: [PATCH 4/4] #2279: add a check in LBData dumping test --- tests/unit/collection/test_lb.extended.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/collection/test_lb.extended.cc b/tests/unit/collection/test_lb.extended.cc index a0395e3830..2c6379cc38 100644 --- a/tests/unit/collection/test_lb.extended.cc +++ b/tests/unit/collection/test_lb.extended.cc @@ -438,6 +438,10 @@ TEST_P(TestNodeLBDataDumper, test_node_lb_data_dumping_with_interval) { EXPECT_EQ(phase["user_defined"]["new_time"], static_cast(phase["id"])); } + auto num_tasks = json["phases"][0]["tasks"].size(); + auto entity = json["phases"][0]["tasks"][num_tasks - 1]["entity"]; + EXPECT_EQ(entity["home"], 0); + EXPECT_EQ(entity["id"], 0); }); if (vt::theContext()->getNode() == 0) {