Skip to content

Commit 03cb853

Browse files
committed
#142: info: cache min-phase when data is originally added
1 parent d8ada6d commit 03cb853

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
@@ -68,9 +68,11 @@ namespace vt::tv {
6868
struct Info {
6969
Info(
7070
std::unordered_map<ElementIDType, ObjectInfo> in_object_info,
71-
std::unordered_map<NodeType, Rank> in_ranks)
72-
: object_info_(std::move(in_object_info)),
73-
ranks_(std::move(in_ranks)) { }
71+
std::unordered_map<NodeType, Rank> in_ranks
72+
) : object_info_(std::move(in_object_info)),
73+
ranks_(std::move(in_ranks)),
74+
min_phase_(getMinPhase())
75+
{ }
7476

7577
Info() = default;
7678

@@ -88,6 +90,10 @@ struct Info {
8890

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

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

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

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

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

481-
return min_phase;
486+
return keys.size() > 0 ? *keys.begin() : 0;
482487
}
483488

484489
/**
@@ -1245,6 +1250,9 @@ struct Info {
12451250

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

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

0 commit comments

Comments
 (0)