Skip to content

Commit

Permalink
#1934: Update LBDataHolder to use default constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Sep 17, 2024
1 parent 15e4c9f commit 15724b5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
22 changes: 10 additions & 12 deletions src/vt/vrt/collection/balance/lb_data_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

#include <nlohmann/json.hpp>

#include <algorithm>

namespace vt { namespace vrt { namespace collection { namespace balance {

void LBDataHolder::outputEntity(nlohmann::json& j, ElementIDStruct const& id) const {
Expand Down Expand Up @@ -277,20 +279,16 @@ std::unique_ptr<nlohmann::json> 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();
Expand Down
7 changes: 1 addition & 6 deletions src/vt/vrt/collection/balance/lb_data_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions src/vt/vrt/collection/balance/node_lb_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -155,7 +150,8 @@ ElementIDType NodeLBData::getNextElm() {
}

void NodeLBData::initialize() {
lb_data_ = std::make_unique<LBDataHolder>(hist_lb_data_size_);
lb_data_ = std::make_unique<LBDataHolder>();
lb_data_->resizeHistory(hist_lb_data_size_);

#if vt_check_enabled(lblite)
if (theConfig()->vt_lb_data) {
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/collection/test_workload_data_migrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ setupWorkloads(PhaseType phase, size_t numElements) {
);
}

auto lbdh = std::make_shared<LBDataHolder>(1);
auto lbdh = std::make_shared<LBDataHolder>();
lbdh->resizeHistory(1);

for (auto&& elmID : myElemList) {
double tval = elmID.id * 2;
Expand Down Expand Up @@ -790,7 +791,8 @@ setupManyWorkloads(
);
}

auto lbdh = std::make_shared<LBDataHolder>(num_phases);
auto lbdh = std::make_shared<LBDataHolder>();
lbdh->resizeHistory(num_phases);

PhaseType stop_phase = initial_phase + num_phases;
for (PhaseType phase = initial_phase; phase < stop_phase; ++phase) {
Expand All @@ -804,7 +806,8 @@ setupManyWorkloads(
}
}

auto scrambled_lbdh = std::make_shared<LBDataHolder>(num_phases);
auto scrambled_lbdh = std::make_shared<LBDataHolder>();
scrambled_lbdh->resizeHistory(num_phases);

for (PhaseType phase = initial_phase; phase < stop_phase; ++phase) {
auto base_load_model = setupBaseModel(phase, lbdh);
Expand Down

0 comments on commit 15724b5

Please sign in to comment.