diff --git a/src/vt/vrt/collection/balance/lb_data_holder.cc b/src/vt/vrt/collection/balance/lb_data_holder.cc index 545baf7bdd..788087b76e 100644 --- a/src/vt/vrt/collection/balance/lb_data_holder.cc +++ b/src/vt/vrt/collection/balance/lb_data_holder.cc @@ -47,6 +47,8 @@ #include +#include + namespace vt { namespace vrt { namespace collection { namespace balance { void LBDataHolder::outputEntity(nlohmann::json& j, ElementIDStruct const& id) const { @@ -277,20 +279,16 @@ std::unique_ptr LBDataHolder::toJson(PhaseType phase) const { } void LBDataHolder::resizeHistory(std::size_t num_to_retain) { - node_data_.resize(num_to_retain); - node_comm_.resize(num_to_retain); - node_subphase_comm_.resize(num_to_retain); - user_defined_json_.resize(num_to_retain); - user_defined_lb_info_.resize(num_to_retain); - node_user_attributes_.resize(num_to_retain); + auto new_size = std::max(std::size_t{1}, num_to_retain); + + node_data_.resize(new_size); + node_comm_.resize(new_size); + node_subphase_comm_.resize(new_size); + user_defined_json_.resize(new_size); + user_defined_lb_info_.resize(new_size); + node_user_attributes_.resize(new_size); } -LBDataHolder::LBDataHolder(std::size_t phases_history_num) - : node_data_(phases_history_num), node_comm_(phases_history_num), - node_subphase_comm_(phases_history_num), user_defined_json_(phases_history_num), - user_defined_lb_info_(phases_history_num), node_user_attributes_(phases_history_num) -{ } - LBDataHolder::LBDataHolder(nlohmann::json const& j) { auto this_node = theContext()->getNode(); diff --git a/src/vt/vrt/collection/balance/lb_data_holder.h b/src/vt/vrt/collection/balance/lb_data_holder.h index 4fdecbd7f0..b3e5c98a8e 100644 --- a/src/vt/vrt/collection/balance/lb_data_holder.h +++ b/src/vt/vrt/collection/balance/lb_data_holder.h @@ -65,12 +65,7 @@ namespace vt { namespace vrt { namespace collection { namespace balance { * output them as JSON. */ struct LBDataHolder { - /** - * \brief Construct a new \c LBDataHolder with specified history length. - * - * \param[in] phases_history_num the number of phases to retain - */ - LBDataHolder(std::size_t phases_history_num); + LBDataHolder() = default; /** * \brief Create \c LBDataHolder from input JSON diff --git a/src/vt/vrt/collection/balance/node_lb_data.cc b/src/vt/vrt/collection/balance/node_lb_data.cc index 0ceefc8485..465572e9ad 100644 --- a/src/vt/vrt/collection/balance/node_lb_data.cc +++ b/src/vt/vrt/collection/balance/node_lb_data.cc @@ -139,12 +139,7 @@ void NodeLBData::resizeLBDataHistory(uint32_t new_hist_len) { hist_lb_data_size_ = new_hist_len; if (lb_data_) { - lb_data_->node_data_.resize(new_hist_len); - lb_data_->node_comm_.resize(new_hist_len); - lb_data_->node_subphase_comm_.resize(new_hist_len); - lb_data_->user_defined_lb_info_.resize(new_hist_len); - lb_data_->user_defined_json_.resize(new_hist_len); - lb_data_->node_user_attributes_.resize(new_hist_len); + lb_data_->resizeHistory(hist_lb_data_size_); } startIterCleanup(); @@ -155,7 +150,8 @@ ElementIDType NodeLBData::getNextElm() { } void NodeLBData::initialize() { - lb_data_ = std::make_unique(hist_lb_data_size_); + lb_data_ = std::make_unique(); + lb_data_->resizeHistory(hist_lb_data_size_); #if vt_check_enabled(lblite) if (theConfig()->vt_lb_data) { diff --git a/tests/unit/collection/test_workload_data_migrator.cc b/tests/unit/collection/test_workload_data_migrator.cc index 2b64a56039..dd8f48e4ef 100644 --- a/tests/unit/collection/test_workload_data_migrator.cc +++ b/tests/unit/collection/test_workload_data_migrator.cc @@ -93,7 +93,8 @@ setupWorkloads(PhaseType phase, size_t numElements) { ); } - auto lbdh = std::make_shared(1); + auto lbdh = std::make_shared(); + lbdh->resizeHistory(1); for (auto&& elmID : myElemList) { double tval = elmID.id * 2; @@ -790,7 +791,8 @@ setupManyWorkloads( ); } - auto lbdh = std::make_shared(num_phases); + auto lbdh = std::make_shared(); + lbdh->resizeHistory(num_phases); PhaseType stop_phase = initial_phase + num_phases; for (PhaseType phase = initial_phase; phase < stop_phase; ++phase) { @@ -804,7 +806,8 @@ setupManyWorkloads( } } - auto scrambled_lbdh = std::make_shared(num_phases); + auto scrambled_lbdh = std::make_shared(); + scrambled_lbdh->resizeHistory(num_phases); for (PhaseType phase = initial_phase; phase < stop_phase; ++phase) { auto base_load_model = setupBaseModel(phase, lbdh);