Skip to content

Commit 9b09544

Browse files
committed
#2074: Calculate number of phases after removal of the count_ property
1 parent 07c4a96 commit 9b09544

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/vt/vrt/collection/balance/lb_data_restart_reader.cc

+24-4
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,26 @@ void LBDataRestartReader::startup() {
7979
}
8080

8181
void LBDataRestartReader::readHistory(LBDataHolder const& lbdh) {
82+
auto find_max_data_phase = [&]() -> PhaseType {
83+
if (lbdh.node_data_.empty()) {
84+
return 0;
85+
}
86+
return std::max_element(
87+
lbdh.node_data_.begin(), lbdh.node_data_.end(),
88+
[](const auto& p1, const auto& p2) { return p1.first < p2.first; })
89+
->first;
90+
};
91+
92+
// Find last phase number
93+
auto largest_data = find_max_data_phase();
94+
auto largest_identical =
95+
lbdh.identical_phases_.size() > 0 ? *lbdh.identical_phases_.rbegin() : 0;
96+
auto largest_skipped =
97+
lbdh.skipped_phases_.size() > 0 ? *lbdh.skipped_phases_.rbegin() : 0;
98+
num_phases_ =
99+
std::max(std::max(largest_data, largest_identical), largest_skipped) + 1;
100+
82101
PhaseType last_found_phase = 0;
83-
num_phases_ = lbdh.count_;
84102
for (PhaseType phase = 0; phase < num_phases_; phase++) {
85103
auto iter = lbdh.node_data_.find(phase);
86104
if (iter != lbdh.node_data_.end()) {
@@ -93,11 +111,13 @@ void LBDataRestartReader::readHistory(LBDataHolder const& lbdh) {
93111
history_[phase]->insert(obj.first);
94112
}
95113
}
96-
} else if(lbdh.identical_phases_.find(phase) != lbdh.identical_phases_.end()) {
114+
} else if (
115+
lbdh.identical_phases_.find(phase) != lbdh.identical_phases_.end()) {
97116
// Phase is identical to previous one, use the shared pointer to data from previous phase
98117
addIdenticalPhase(phase, last_found_phase);
99-
} else if(lbdh.skipped_phases_.find(phase) == lbdh.skipped_phases_.end()) {
100-
vtAbort("Could not find data: Skipped phases needs to be listed in file metadata.");
118+
} else if (lbdh.skipped_phases_.find(phase) == lbdh.skipped_phases_.end()) {
119+
vtAbort("Could not find data: Skipped phases needs to be listed in file "
120+
"metadata.");
101121
}
102122
}
103123
}

0 commit comments

Comments
 (0)