Skip to content

Commit cabb3c4

Browse files
committed
#142: info: cache min-phase when data is originally added
1 parent a09b658 commit cabb3c4

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/vt-tv/api/info.h

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ namespace vt::tv {
6767
struct Info {
6868
Info(
6969
std::unordered_map<ElementIDType, ObjectInfo> in_object_info,
70-
std::unordered_map<NodeType, Rank> in_ranks)
71-
: object_info_(std::move(in_object_info)),
72-
ranks_(std::move(in_ranks)) { }
70+
std::unordered_map<NodeType, Rank> in_ranks
71+
) : object_info_(std::move(in_object_info)),
72+
ranks_(std::move(in_ranks)),
73+
min_phase_(getMinPhase())
74+
{ }
7375

7476
Info() = default;
7577

@@ -87,6 +89,10 @@ struct Info {
8789

8890
assert(ranks_.find(r.getRankID()) == ranks_.end() && "Rank must not exist");
8991
ranks_.try_emplace(r.getRankID(), std::move(r));
92+
93+
if (min_phase_ == std::numeric_limits<PhaseType>::max()) {
94+
min_phase_ = getMinPhase();
95+
}
9096
}
9197

9298
void setSelectedPhase(PhaseType selected_phase) {
@@ -460,24 +466,23 @@ struct Info {
460466
* \return the minimim phase in the data
461467
*/
462468
PhaseType getMinPhase() const {
463-
PhaseType min_phase = std::numeric_limits<PhaseType>::max();
464-
// Go through all ranks and get all objects at given phase
465-
for (uint64_t rank = 0; rank < ranks_.size(); rank++) {
466-
// Get Rank info for specified rank
467-
auto const& rank_info = ranks_.at(rank);
469+
if (min_phase_ != std::numeric_limits<PhaseType>::max()) {
470+
return min_phase_;
471+
}
472+
// Otherwise, we have to calculate it
468473

469-
// Get the phase work map
470-
auto const& pw = rank_info.getPhaseWork();
474+
// Get the rank info for any rank (all ranks should have the same phases)
475+
auto const& rank_info = ranks_.begin()->second;
471476

472-
std::set<PhaseType> keys;
473-
for (auto& [key, _] : pw) {
474-
keys.insert(key);
475-
}
477+
// Get the phase work map
478+
auto const& pw = rank_info.getPhaseWork();
476479

477-
min_phase = std::min(*keys.begin(), min_phase);
480+
std::set<PhaseType> keys;
481+
for (auto& [key, _] : pw) {
482+
keys.insert(key);
478483
}
479484

480-
return min_phase;
485+
return keys.size() > 0 ? *keys.begin() : 0;
481486
}
482487

483488
/**
@@ -1244,6 +1249,9 @@ struct Info {
12441249

12451250
/// The current phase (or indication to use all phases)
12461251
PhaseType selected_phase_ = std::numeric_limits<PhaseType>::max();
1252+
1253+
/// The min phase found in the data (could start at non-zero)
1254+
PhaseType min_phase_ = std::numeric_limits<PhaseType>::max();
12471255
};
12481256

12491257
} /* end namespace vt::tv */

0 commit comments

Comments
 (0)