From d074668199a75d59b42d53756ce8c9a6ba14d2da Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Thu, 12 Jan 2023 16:52:37 +0100 Subject: [PATCH] #1934: Refactor trimLBDataHistory to have better performance --- src/vt/vrt/collection/balance/node_lb_data.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/vt/vrt/collection/balance/node_lb_data.cc b/src/vt/vrt/collection/balance/node_lb_data.cc index 1a2d6e028e..39cc7d8cea 100644 --- a/src/vt/vrt/collection/balance/node_lb_data.cc +++ b/src/vt/vrt/collection/balance/node_lb_data.cc @@ -131,12 +131,17 @@ void NodeLBData::startIterCleanup(PhaseType phase) { void NodeLBData::trimLBDataHistory(PhaseType phase) { if (phase != no_lb_phase && phase > min_hist_lb_data_) { - // Clean phases which are no longer needed - for(auto i = 0ull; i < phase - min_hist_lb_data_; i++) { - lb_data_->node_data_.erase(i); - lb_data_->node_comm_.erase(i); - lb_data_->node_subphase_comm_.erase(i); - } + auto phaseToLookFor = phase - min_hist_lb_data_ - 1; + + // Trim all maps to have 'min_hist_lb_data_ + 1' phases of data + auto fromData = lb_data_->node_data_.find(phaseToLookFor); + lb_data_->node_data_.erase(fromData, lb_data_->node_data_.end()); + + auto fromComm = lb_data_->node_comm_.find(phaseToLookFor); + lb_data_->node_comm_.erase(fromComm, lb_data_->node_comm_.end()); + + auto fromSub = lb_data_->node_subphase_comm_.find(phaseToLookFor); + lb_data_->node_subphase_comm_.erase(fromSub, lb_data_->node_subphase_comm_.end()); NodeLBData::node_migrate_.clear(); node_collection_lookup_.clear();