Skip to content

Commit

Permalink
Merge pull request #1980 from DARMA-tasking/1903-mark-methods-as-const
Browse files Browse the repository at this point in the history
#1903: Add const to methods in LoadModel
  • Loading branch information
lifflander authored Sep 27, 2022
2 parents 13c86c5 + 8ddfd84 commit c69e439
Show file tree
Hide file tree
Showing 34 changed files with 118 additions and 118 deletions.
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 @@ -61,7 +61,7 @@ void CommOverhead::setLoads(std::unordered_map<PhaseType, LoadMapType> const* pr
}

TimeType
CommOverhead::getModeledLoad(ElementIDStruct object, PhaseOffset offset) {
CommOverhead::getModeledLoad(ElementIDStruct object, PhaseOffset offset) const {
auto work = ComposedModel::getModeledLoad(object, offset);

auto phase = getNumCompletedPhases() + offset.phases;
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 @@ -68,7 +68,7 @@ struct CommOverhead : public ComposedModel {
void setLoads(std::unordered_map<PhaseType, LoadMapType> const* proc_load,
std::unordered_map<PhaseType, CommMapType> const* proc_comm) override;

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;

private:
std::unordered_map<PhaseType, CommMapType> const* proc_comm_; /**< Underlying comm data */
Expand Down
14 changes: 7 additions & 7 deletions src/vt/vrt/collection/balance/model/composed_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,36 @@ void ComposedModel::updateLoads(PhaseType last_completed_phase) {
}

TimeType
ComposedModel::getModeledLoad(ElementIDStruct object, PhaseOffset when) {
ComposedModel::getModeledLoad(ElementIDStruct object, PhaseOffset when) const {
return base_->getModeledLoad(object, when);
}

bool ComposedModel::hasRawLoad() const {
return base_->hasRawLoad();
}

TimeType ComposedModel::getRawLoad(ElementIDStruct object, PhaseOffset when) {
TimeType ComposedModel::getRawLoad(ElementIDStruct object, PhaseOffset when) const {
return base_->getRawLoad(object, when);
}

unsigned int ComposedModel::getNumPastPhasesNeeded(unsigned int look_back)
unsigned int ComposedModel::getNumPastPhasesNeeded(unsigned int look_back) const
{
return base_->getNumPastPhasesNeeded(look_back);
}

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

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

unsigned int ComposedModel::getNumCompletedPhases() {
unsigned int ComposedModel::getNumCompletedPhases() const {
return base_->getNumCompletedPhases();
}

int ComposedModel::getNumSubphases() {
int ComposedModel::getNumSubphases() const {
return base_->getNumSubphases();
}

Expand Down
14 changes: 7 additions & 7 deletions src/vt/vrt/collection/balance/model/composed_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ class ComposedModel : public LoadModel

void updateLoads(PhaseType last_completed_phase) override;

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;
bool hasRawLoad() const override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) const override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) const override;

ObjectIterator begin() override;
ObjectIterator begin() const override;

int getNumObjects() override;
unsigned int getNumCompletedPhases() override;
int getNumSubphases() override;
int getNumObjects() const override;
unsigned int getNumCompletedPhases() const override;
int getNumSubphases() const override;

private:
std::shared_ptr<LoadModel> base_;
Expand Down
4 changes: 2 additions & 2 deletions src/vt/vrt/collection/balance/model/linear_model.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 {

TimeType LinearModel::getModeledLoad(ElementIDStruct object, PhaseOffset when) {
TimeType LinearModel::getModeledLoad(ElementIDStruct object, PhaseOffset when) const {
using util::stats::LinearRegression;

// Retrospective queries don't call for a prediction
Expand All @@ -73,7 +73,7 @@ TimeType LinearModel::getModeledLoad(ElementIDStruct object, PhaseOffset when) {
return regression.predict(when.phases);
}

unsigned int LinearModel::getNumPastPhasesNeeded(unsigned int look_back)
unsigned int LinearModel::getNumPastPhasesNeeded(unsigned int look_back) const
{
return ComposedModel::getNumPastPhasesNeeded(std::max(past_len_, look_back));
}
Expand Down
4 changes: 2 additions & 2 deletions src/vt/vrt/collection/balance/model/linear_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ struct LinearModel : ComposedModel {
past_len_(in_past_len)
{ }

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) const override;

private:
const unsigned int past_len_ = 0;
Expand Down
18 changes: 9 additions & 9 deletions src/vt/vrt/collection/balance/model/load_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ struct LoadModel
* The `updateLoads` method must have been called before any call to
* this.
*/
virtual TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) = 0;
virtual TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const = 0;

/**
* \brief Whether or not the model is based on the RawData model
Expand All @@ -240,7 +240,7 @@ struct LoadModel
*
* \return How much computation time the object required
*/
virtual TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) {
virtual TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) const {
vtAbort(
"LoadModel::getRawLoad() called on a model that does not implement it"
);
Expand All @@ -259,7 +259,7 @@ struct LoadModel
* The `updateLoads` method must have been called before any call to
* this.
*/
virtual TimeType getModeledComm(ElementIDStruct object, PhaseOffset when) {
virtual TimeType getModeledComm(ElementIDStruct object, PhaseOffset when) const {
return {};
}

Expand All @@ -273,7 +273,7 @@ struct LoadModel
* \return How many phases of past load statistics will be needed to
* satisfy the requested history
*/
virtual unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) = 0;
virtual unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const = 0;

/**
* Object enumeration, to abstract away access to the underlying structures
Expand All @@ -282,7 +282,7 @@ struct LoadModel
* The `updateLoads` method must have been called before any call to
* this.
*/
virtual ObjectIterator begin() = 0;
virtual ObjectIterator begin() const = 0;

/**
* Object enumeration, to abstract away access to the underlying structures
Expand All @@ -291,7 +291,7 @@ struct LoadModel
* The `updateLoads` method must have been called before any call to
* this.
*/
ObjectIterator end() { return ObjectIterator{nullptr}; }
ObjectIterator end() const { return ObjectIterator{nullptr}; }

/**
* Object enumeration, to abstract away access to the underlying structures
Expand All @@ -300,7 +300,7 @@ struct LoadModel
* The `updateLoads` method must have been called before any call to
* this.
*/
virtual int getNumObjects() {
virtual int getNumObjects() const {
int count = 0;
for (auto it = begin(); it != end(); ++it, ++count) {}
return count;
Expand All @@ -312,7 +312,7 @@ struct LoadModel
* The `updateLoads` method must have been called before any call to
* this.
*/
virtual unsigned int getNumCompletedPhases() = 0;
virtual unsigned int getNumCompletedPhases() const = 0;

/**
* Returns the number of subphases recorded in the most recent
Expand All @@ -321,7 +321,7 @@ struct LoadModel
* The `updateLoads` method must have been called before any call to
* this.
*/
virtual int getNumSubphases() = 0;
virtual int getNumSubphases() const = 0;

template <typename Serializer>
void serialize(Serializer& s) {}
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/model/multiple_phases.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
namespace vt { namespace vrt { namespace collection { namespace balance {

TimeType
MultiplePhases::getModeledLoad(ElementIDStruct object, PhaseOffset when) {
MultiplePhases::getModeledLoad(ElementIDStruct object, PhaseOffset when) const {
// Retrospective queries don't call for a prediction
if (when.phases < 0)
return ComposedModel::getModeledLoad(object, when);
Expand Down
2 changes: 1 addition & 1 deletion src/vt/vrt/collection/balance/model/multiple_phases.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct MultiplePhases : ComposedModel {
, future_phase_block_size_(in_future_phase_block_size)
{ }

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;

private:
int future_phase_block_size_ = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/vt/vrt/collection/balance/model/naive_persistence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ NaivePersistence::NaivePersistence(std::shared_ptr<balance::LoadModel> base)
{ }

TimeType
NaivePersistence::getModeledLoad(ElementIDStruct object, PhaseOffset offset) {
NaivePersistence::getModeledLoad(ElementIDStruct object, PhaseOffset offset) const {
if (offset.phases >= 0)
offset.phases = -1;

return ComposedModel::getModeledLoad(object, offset);
}

TimeType NaivePersistence::getRawLoad(ElementIDStruct object, PhaseOffset offset)
TimeType NaivePersistence::getRawLoad(ElementIDStruct object, PhaseOffset offset) const
{
if (offset.phases >= 0)
offset.phases = -1;

return ComposedModel::getRawLoad(object, offset);
}

unsigned int NaivePersistence::getNumPastPhasesNeeded(unsigned int look_back)
unsigned int NaivePersistence::getNumPastPhasesNeeded(unsigned int look_back) const
{
return ComposedModel::getNumPastPhasesNeeded(std::max(1u, look_back));
}
Expand Down
6 changes: 3 additions & 3 deletions src/vt/vrt/collection/balance/model/naive_persistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ struct NaivePersistence : public ComposedModel {
* \param[in] base: The source of underlying load numbers to return; must not be null
*/
explicit NaivePersistence(std::shared_ptr<balance::LoadModel> base);
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset offset) override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset offset) const override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) const override;
}; // class NaivePersistence

}}}} // end namespace
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 @@ -55,7 +55,7 @@ Norm::Norm(std::shared_ptr<balance::LoadModel> base, double power)
vtAssert(power >= 0.0, "Reciprocal loads make no sense");
}

TimeType Norm::getModeledLoad(ElementIDStruct object, PhaseOffset offset) {
TimeType Norm::getModeledLoad(ElementIDStruct object, PhaseOffset offset) const {
if (offset.subphase != PhaseOffset::WHOLE_PHASE)
return ComposedModel::getModeledLoad(object, offset);

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 @@ -64,7 +64,7 @@ class Norm : public ComposedModel {
*/
Norm(std::shared_ptr<balance::LoadModel> base, double power);

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;

private:
const double power_;
Expand Down
6 changes: 3 additions & 3 deletions src/vt/vrt/collection/balance/model/per_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void PerCollection::updateLoads(PhaseType last_completed_phase) {
}

TimeType
PerCollection::getModeledLoad(ElementIDStruct object, PhaseOffset when) {
PerCollection::getModeledLoad(ElementIDStruct object, PhaseOffset when) const {
// See if some specific model has been given for the object in question
auto mi = models_.find(theNodeLBData()->getCollectionProxyForElement(object));
if (mi != models_.end())
Expand All @@ -90,7 +90,7 @@ bool PerCollection::hasRawLoad() const {
return has_raw_load and ComposedModel::hasRawLoad();
}

TimeType PerCollection::getRawLoad(ElementIDStruct object, PhaseOffset when) {
TimeType PerCollection::getRawLoad(ElementIDStruct object, PhaseOffset when) const {
// See if some specific model has been given for the object in question
auto mi = models_.find(theNodeLBData()->getCollectionProxyForElement(object));
if (mi != models_.end())
Expand All @@ -100,7 +100,7 @@ TimeType PerCollection::getRawLoad(ElementIDStruct object, PhaseOffset when) {
return ComposedModel::getRawLoad(object, when);
}

unsigned int PerCollection::getNumPastPhasesNeeded(unsigned int look_back)
unsigned int PerCollection::getNumPastPhasesNeeded(unsigned int look_back) const
{
unsigned int needed = ComposedModel::getNumPastPhasesNeeded(look_back);
for (auto& m : models_)
Expand Down
6 changes: 3 additions & 3 deletions src/vt/vrt/collection/balance/model/per_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ struct PerCollection : public ComposedModel

void updateLoads(PhaseType last_completed_phase) override;

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;
bool hasRawLoad() const override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) const override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) const override;

private:
std::unordered_map<CollectionID, std::shared_ptr<LoadModel>> models_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PersistenceMedianLastN::PersistenceMedianLastN(std::shared_ptr<LoadModel> base,

TimeType PersistenceMedianLastN::getModeledLoad(
ElementIDStruct object, PhaseOffset when
) {
) const {
// Retrospective queries don't call for a prospective calculation
if (when.phases < 0)
return ComposedModel::getModeledLoad(object, when);
Expand All @@ -77,7 +77,7 @@ TimeType PersistenceMedianLastN::getModeledLoad(
return (times[phases / 2 - 1] + times[phases / 2]) / 2;
}

unsigned int PersistenceMedianLastN::getNumPastPhasesNeeded(unsigned int look_back)
unsigned int PersistenceMedianLastN::getNumPastPhasesNeeded(unsigned int look_back) const
{
return ComposedModel::getNumPastPhasesNeeded(std::max(n_, look_back));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ struct PersistenceMedianLastN : public ComposedModel
*/
PersistenceMedianLastN(std::shared_ptr<LoadModel> base, unsigned int n);

TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;
unsigned int getNumPastPhasesNeeded(unsigned int look_back) const override;

private:
const unsigned int n_;
Expand Down
8 changes: 4 additions & 4 deletions src/vt/vrt/collection/balance/model/proposed_reassignment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ProposedReassignment::ProposedReassignment(
// arrive ^ (present \ depart) == 0
}

ObjectIterator ProposedReassignment::begin()
ObjectIterator ProposedReassignment::begin() const
{
return {
std::make_unique<ConcatenatedIterator>(
Expand All @@ -83,7 +83,7 @@ ObjectIterator ProposedReassignment::begin()
)};
}

int ProposedReassignment::getNumObjects()
int ProposedReassignment::getNumObjects() const
{
int base = ComposedModel::getNumObjects();
int departing = reassignment_->depart_.size();
Expand All @@ -94,7 +94,7 @@ int ProposedReassignment::getNumObjects()
}

TimeType
ProposedReassignment::getModeledLoad(ElementIDStruct object, PhaseOffset when) {
ProposedReassignment::getModeledLoad(ElementIDStruct object, PhaseOffset when) const {
auto a = reassignment_->arrive_.find(object);
if (a != reassignment_->arrive_.end()) {
return std::get<0>(a->second).get(when);
Expand All @@ -107,7 +107,7 @@ ProposedReassignment::getModeledLoad(ElementIDStruct object, PhaseOffset when) {
return ComposedModel::getModeledLoad(object, when);
}

TimeType ProposedReassignment::getRawLoad(ElementIDStruct object, PhaseOffset when)
TimeType ProposedReassignment::getRawLoad(ElementIDStruct object, PhaseOffset when) const
{
auto a = reassignment_->arrive_.find(object);
if (a != reassignment_->arrive_.end()) {
Expand Down
8 changes: 4 additions & 4 deletions src/vt/vrt/collection/balance/model/proposed_reassignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ struct ProposedReassignment : public ComposedModel {
std::shared_ptr<const Reassignment> reassignment
);

ObjectIterator begin() override;
int getNumObjects() override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) override;
ObjectIterator begin() const override;
int getNumObjects() const override;
TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override;
TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) const override;

private:
std::shared_ptr<const Reassignment> reassignment_;
Expand Down
Loading

0 comments on commit c69e439

Please sign in to comment.