From 6bf446ec745e5e209f72408ec6e40caeb1827aee Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Mon, 9 Dec 2024 13:39:52 -0800 Subject: [PATCH] #128: render: make rank qoi selection check user-defined first --- src/vt-tv/api/info.h | 69 +++++++++++++++++++++++++++++++------- src/vt-tv/render/render.cc | 17 +++------- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/vt-tv/api/info.h b/src/vt-tv/api/info.h index 0d8f5b748..c3231499f 100644 --- a/src/vt-tv/api/info.h +++ b/src/vt-tv/api/info.h @@ -291,7 +291,8 @@ struct Info { */ template T getRankQOIAtPhase( - ElementIDType rank_id, PhaseType phase, std::string rank_qoi) const { + ElementIDType rank_id, PhaseType phase, std::string const& rank_qoi + ) const { auto qoi_getter = getRankQOIGetter(rank_qoi); auto const& rank = this->ranks_.at(rank_id); return qoi_getter(rank, phase); @@ -304,13 +305,34 @@ struct Info { */ template std::unordered_map - getAllQOIAtRank(ElementIDType rank_id, std::string rank_qoi) const { - std::unordered_map rank_qois; - auto qoi_getter = getRankQOIGetter(rank_qoi); - auto const& rank = this->ranks_.at(rank_id); + getAllQOIAtRank(ElementIDType rank_id, std::string const& rank_qoi) const { + auto const& rank = ranks_.at(rank_id); auto const& phase_work = rank.getPhaseWork(); - for (auto const& [phase, _] : phase_work) { - rank_qois.insert(std::make_pair(phase, qoi_getter(rank, phase))); + + std::unordered_map rank_qois; + + if (hasRankUserDefined(rank_qoi)) { + auto const& test_value = getFirstRankUserDefined(rank_qoi); + for (auto const& [phase, _] : phase_work) { + if (std::holds_alternative(test_value)) { + rank_qois.emplace( + phase, static_cast( + std::get(getRankUserDefined(rank, phase, rank_qoi)) + ) + ); + } else if (std::holds_alternative(test_value)) { + rank_qois.emplace( + phase, static_cast( + std::get(getRankUserDefined(rank, phase, rank_qoi)) + ) + ); + } + } + } else { + auto qoi_getter = getRankQOIGetter(rank_qoi); + for (auto const& [phase, _] : phase_work) { + rank_qois.emplace(phase, qoi_getter(rank, phase)); + } } return rank_qois; @@ -323,11 +345,32 @@ struct Info { */ template std::unordered_map - getAllRankQOIAtPhase(PhaseType phase, std::string rank_qoi) const { + getAllRankQOIAtPhase(PhaseType phase, std::string const& rank_qoi) const { std::unordered_map rank_qois; - auto qoi_getter = getRankQOIGetter(rank_qoi); - for (auto const& [rank_id, rank] : this->ranks_) { - rank_qois.insert(std::make_pair(rank_id, qoi_getter(rank, phase))); + + if (hasRankUserDefined(rank_qoi)) { + auto const& test_value = getFirstRankUserDefined(rank_qoi); + for (uint64_t rank_id = 0; rank_id < ranks_.size(); rank_id++) { + auto const& rank = ranks_.at(rank_id); + if (std::holds_alternative(test_value)) { + rank_qois.emplace( + phase, static_cast( + std::get(getRankUserDefined(rank, phase, rank_qoi)) + ) + ); + } else if (std::holds_alternative(test_value)) { + rank_qois.emplace( + phase, static_cast( + std::get(getRankUserDefined(rank, phase, rank_qoi)) + ) + ); + } + } + } else { + auto qoi_getter = getRankQOIGetter(rank_qoi); + for (auto const& [rank_id, rank] : this->ranks_) { + rank_qois.emplace(rank_id, qoi_getter(rank, phase)); + } } return rank_qois; @@ -831,7 +874,7 @@ struct Info { * * \return whether it exists */ - bool hasRankUserDefined(std::string const& key) { + bool hasRankUserDefined(std::string const& key) const { for (auto const& [id, rank] : ranks_) { auto const num_phases = rank.getNumPhases(); for (std::size_t i = 0; i < num_phases; i++) { @@ -851,7 +894,7 @@ struct Info { * * \return the value */ - QOIVariantTypes getFirstRankUserDefined(std::string const& key) { + QOIVariantTypes getFirstRankUserDefined(std::string const& key) const { for (auto const& [id, rank] : ranks_) { auto const num_phases = rank.getNumPhases(); for (std::size_t i = 0; i < num_phases; i++) { diff --git a/src/vt-tv/render/render.cc b/src/vt-tv/render/render.cc index ebadf9149..7f0b864ae 100644 --- a/src/vt-tv/render/render.cc +++ b/src/vt-tv/render/render.cc @@ -249,29 +249,22 @@ std::pair Render::computeRankQOIRange_() { // Iterate over all ranks for (uint64_t rank_id = 0; rank_id < this->n_ranks_; rank_id++) { - std::unordered_map rank_qoi_map; - rank_qoi_map = this->info_.getAllQOIAtRank(rank_id, this->rank_qoi_); + auto rank_qoi_map = info_.getAllQOIAtRank(rank_id, this->rank_qoi_); // Get max qoi for this rank across all phases auto prmax = std::max_element( std::begin(rank_qoi_map), std::end(rank_qoi_map), - []( - const std::pair& p1, - const std::pair& p2) { - return p1.second < p2.second; - }); + [](auto const& p1, auto const& p2) { return p1.second < p2.second; } + ); rqmax_for_phase = prmax->second; // Get min qoi for this rank across all phases auto prmin = std::max_element( std::begin(rank_qoi_map), std::end(rank_qoi_map), - []( - const std::pair& p1, - const std::pair& p2) { - return p1.second > p2.second; - }); + [](auto const& p1, auto const& p2) { return p1.second > p2.second; } + ); rqmin_for_phase = prmin->second; if (rqmax_for_phase > rq_max)