Skip to content

Commit

Permalink
#128: render: make rank qoi selection check user-defined first
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Dec 9, 2024
1 parent 2705d10 commit 6bf446e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
69 changes: 56 additions & 13 deletions src/vt-tv/api/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ struct Info {
*/
template <typename T = double>
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<T>(rank_qoi);
auto const& rank = this->ranks_.at(rank_id);
return qoi_getter(rank, phase);
Expand All @@ -304,13 +305,34 @@ struct Info {
*/
template <typename T = double>
std::unordered_map<PhaseType, T>
getAllQOIAtRank(ElementIDType rank_id, std::string rank_qoi) const {
std::unordered_map<PhaseType, T> rank_qois;
auto qoi_getter = getRankQOIGetter<T>(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<PhaseType, T> rank_qois;

if (hasRankUserDefined(rank_qoi)) {
auto const& test_value = getFirstRankUserDefined(rank_qoi);
for (auto const& [phase, _] : phase_work) {
if (std::holds_alternative<double>(test_value)) {
rank_qois.emplace(
phase, static_cast<T>(
std::get<double>(getRankUserDefined(rank, phase, rank_qoi))
)
);
} else if (std::holds_alternative<int>(test_value)) {
rank_qois.emplace(
phase, static_cast<T>(
std::get<int>(getRankUserDefined(rank, phase, rank_qoi))
)
);
}
}
} else {
auto qoi_getter = getRankQOIGetter<T>(rank_qoi);
for (auto const& [phase, _] : phase_work) {
rank_qois.emplace(phase, qoi_getter(rank, phase));
}
}

return rank_qois;
Expand All @@ -323,11 +345,32 @@ struct Info {
*/
template <typename T = double>
std::unordered_map<ElementIDType, T>
getAllRankQOIAtPhase(PhaseType phase, std::string rank_qoi) const {
getAllRankQOIAtPhase(PhaseType phase, std::string const& rank_qoi) const {
std::unordered_map<ElementIDType, T> rank_qois;
auto qoi_getter = getRankQOIGetter<T>(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<double>(test_value)) {
rank_qois.emplace(
phase, static_cast<T>(
std::get<double>(getRankUserDefined(rank, phase, rank_qoi))
)
);
} else if (std::holds_alternative<int>(test_value)) {
rank_qois.emplace(
phase, static_cast<T>(
std::get<int>(getRankUserDefined(rank, phase, rank_qoi))
)
);
}
}
} else {
auto qoi_getter = getRankQOIGetter<T>(rank_qoi);
for (auto const& [rank_id, rank] : this->ranks_) {
rank_qois.emplace(rank_id, qoi_getter(rank, phase));
}
}

return rank_qois;
Expand Down Expand Up @@ -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++) {
Expand All @@ -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++) {
Expand Down
17 changes: 5 additions & 12 deletions src/vt-tv/render/render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,29 +249,22 @@ std::pair<double, double> Render::computeRankQOIRange_() {

// Iterate over all ranks
for (uint64_t rank_id = 0; rank_id < this->n_ranks_; rank_id++) {
std::unordered_map<PhaseType, double> rank_qoi_map;
rank_qoi_map = this->info_.getAllQOIAtRank<double>(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<PhaseType, double>& p1,
const std::pair<PhaseType, double>& 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<PhaseType, double>& p1,
const std::pair<PhaseType, double>& 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)
Expand Down

0 comments on commit 6bf446e

Please sign in to comment.