Skip to content

Commit

Permalink
#582: Shift load model composition to shared_ptr, add API to expose b…
Browse files Browse the repository at this point in the history
…ase and current model
  • Loading branch information
PhilMiller committed Jul 20, 2020
1 parent 63cae4f commit 17c9c6b
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 22 deletions.
11 changes: 6 additions & 5 deletions src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ namespace vt { namespace vrt { namespace collection { namespace balance {
auto ptr = std::make_unique<LBManager>();
auto proxy = theObjGroup()->makeCollective<LBManager>(ptr.get());
proxy.get()->setProxy(proxy);

ptr->base_model_ = std::make_shared<balance::NaivePersistence>(std::make_shared<balance::RawData>());
ptr->setLoadModel(ptr->base_model_);

return ptr;
}

Expand Down Expand Up @@ -127,8 +131,8 @@ LBType LBManager::decideLBToRun(PhaseType phase, bool try_file) {
return the_lb;
}

void LBManager::setLoadModel(std::unique_ptr<LoadModel> model) {
model_ = std::move(model);
void LBManager::setLoadModel(std::shared_ptr<LoadModel> model) {
model_ = model;
auto stats = theProcStats();
model_->setLoads(stats->getProcLoad(),
stats->getProcSubphaseLoad(),
Expand All @@ -148,9 +152,6 @@ LBManager::makeLB(MsgSharedPtr<StartLBMsg> msg) {
EpochType balance_epoch = theTerm()->makeEpochCollective("LBManager::balance_epoch");
EpochType migrate_epoch = theTerm()->makeEpochCollective("LBManager::migrate_epoch");

if (model_ == nullptr)
setLoadModel(std::make_unique<balance::NaivePersistence>(new balance::RawData));

theMsg()->pushEpoch(model_epoch);
model_->updateLoads(phase);
theMsg()->popEpoch(model_epoch);
Expand Down
16 changes: 13 additions & 3 deletions src/vt/vrt/collection/balance/lb_invoke/lb_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,23 @@ struct LBManager : runtime::component::Component<LBManager> {

/**
* \brief Set a model of expected object loads to use in place of
* naive persistence
* the current installed model
*
* \param[in] model the model to apply
*
* This should be called with a similarly-constructed model instance
* on every node
*/
void setLoadModel(std::unique_ptr<LoadModel> model);
void setLoadModel(std::shared_ptr<LoadModel> model);

/**
* \brief Get the system-set basic model of object load
*/
std::shared_ptr<LoadModel> getBaseLoadModel() { return base_model_; }
/**
* \brief Get the currently installed model of object load
*/
std::shared_ptr<LoadModel> getLoadModel() { return model_; }

protected:
/**
Expand All @@ -265,7 +274,8 @@ struct LBManager : runtime::component::Component<LBManager> {
bool synced_in_lb_ = true;
std::vector<ListenerFnType> listeners_ = {};
objgroup::proxy::Proxy<LBManager> proxy_;
std::unique_ptr<LoadModel> model_;
std::shared_ptr<LoadModel> base_model_;
std::shared_ptr<LoadModel> model_;
};

}}}} /* end namespace vt::vrt::collection::balance */
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/model/comm_overhead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

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

CommOverhead::CommOverhead(balance::LoadModel *base)
CommOverhead::CommOverhead(std::shared_ptr<balance::LoadModel> base)
: ComposedModel(base)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/model/comm_overhead.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
namespace vt { namespace vrt { namespace collection { namespace balance {

struct CommOverhead : public ComposedModel {
CommOverhead(balance::LoadModel *base);
CommOverhead(std::shared_ptr<balance::LoadModel> base);
void setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm) override;
Expand Down
12 changes: 6 additions & 6 deletions src/vt/vrt/collection/balance/model/composed_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ namespace vt { namespace vrt { namespace collection { namespace balance {
void ComposedModel::setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm) {
base_.setLoads(proc_load, proc_subphase_load, proc_comm);
base_->setLoads(proc_load, proc_subphase_load, proc_comm);
}

void ComposedModel::updateLoads(PhaseType last_completed_phase) {
base_.updateLoads(last_completed_phase);
base_->updateLoads(last_completed_phase);
}

TimeType ComposedModel::getWork(ElementIDType object, PhaseOffset when) {
return base_.getWork(object, when);
return base_->getWork(object, when);
}

ObjectIterator ComposedModel::begin() {
return base_.begin();
return base_->begin();
}

ObjectIterator ComposedModel::end() {
return base_.end();
return base_->end();
}

int ComposedModel::getNumObjects() {
return base_.getNumObjects();
return base_->getNumObjects();
}

}}}}
4 changes: 2 additions & 2 deletions src/vt/vrt/collection/balance/model/composed_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ComposedModel : public LoadModel
{
public:
// \param[in] base must not be null
ComposedModel(LoadModel *base) : base_(*base) {}
ComposedModel(std::shared_ptr<LoadModel> base) : base_(base) {}

void setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
Expand All @@ -70,7 +70,7 @@ class ComposedModel : public LoadModel
int getNumObjects() override;

private:
LoadModel &base_;
std::shared_ptr<LoadModel> base_;
}; // class ComposedModel

}}}} // namespaces
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/model/naive_persistence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

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

NaivePersistence::NaivePersistence(balance::LoadModel *base)
NaivePersistence::NaivePersistence(std::shared_ptr<balance::LoadModel> base)
: ComposedModel(base)
{ }

Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/model/naive_persistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
namespace vt { namespace vrt { namespace collection { namespace balance {

struct NaivePersistence : public ComposedModel {
NaivePersistence(balance::LoadModel *base);
NaivePersistence(std::shared_ptr<balance::LoadModel> base);
TimeType getWork(ElementIDType object, PhaseOffset when) override;
}; // class NaivePersistence

Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/model/norm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

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

Norm::Norm(balance::LoadModel *base, double power)
Norm::Norm(std::shared_ptr<balance::LoadModel> base, double power)
: ComposedModel(base)
, power_(power)
{
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/model/norm.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Norm : public ComposedModel {
*
* \param[in] power The power to use in computing the norms
*/
Norm(balance::LoadModel *base, double power);
Norm(std::shared_ptr<balance::LoadModel> base, double power);
void setLoads(std::vector<LoadMapType> const* proc_load,
std::vector<SubphaseLoadMapType> const* proc_subphase_load,
std::vector<CommMapType> const* proc_comm) override;
Expand Down

0 comments on commit 17c9c6b

Please sign in to comment.