From 8ddfd84e26da4e3b7b9ff28726eaf7096532422e Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Mon, 26 Sep 2022 11:32:30 +0200 Subject: [PATCH] #1903: Add const to methods in LoadModel --- .../collection/balance/model/comm_overhead.cc | 2 +- .../collection/balance/model/comm_overhead.h | 2 +- .../collection/balance/model/composed_model.cc | 14 +++++++------- .../collection/balance/model/composed_model.h | 14 +++++++------- .../collection/balance/model/linear_model.cc | 4 ++-- .../collection/balance/model/linear_model.h | 4 ++-- .../vrt/collection/balance/model/load_model.h | 18 +++++++++--------- .../balance/model/multiple_phases.cc | 2 +- .../collection/balance/model/multiple_phases.h | 2 +- .../balance/model/naive_persistence.cc | 6 +++--- .../balance/model/naive_persistence.h | 6 +++--- src/vt/vrt/collection/balance/model/norm.cc | 2 +- src/vt/vrt/collection/balance/model/norm.h | 2 +- .../collection/balance/model/per_collection.cc | 6 +++--- .../collection/balance/model/per_collection.h | 6 +++--- .../balance/model/persistence_median_last_n.cc | 4 ++-- .../balance/model/persistence_median_last_n.h | 4 ++-- .../balance/model/proposed_reassignment.cc | 8 ++++---- .../balance/model/proposed_reassignment.h | 8 ++++---- .../vrt/collection/balance/model/raw_data.cc | 14 +++++++------- src/vt/vrt/collection/balance/model/raw_data.h | 14 +++++++------- .../balance/model/select_subphases.cc | 4 ++-- .../balance/model/select_subphases.h | 4 ++-- .../balance/model/weighted_messages.cc | 2 +- .../balance/model/weighted_messages.h | 2 +- .../test_model_comm_overhead.nompi.cc | 10 +++++----- .../test_model_linear_model.nompi.cc | 10 +++++----- .../test_model_multiple_phases.nompi.cc | 10 +++++----- .../test_model_naive_persistence.nompi.cc | 10 +++++----- tests/unit/collection/test_model_norm.nompi.cc | 10 +++++----- .../test_model_per_collection.extended.cc | 2 +- ...st_model_persistence_median_last_n.nompi.cc | 10 +++++----- .../test_model_select_subphases.nompi.cc | 10 +++++----- .../test_model_weighted_messages.nompi.cc | 10 +++++----- 34 files changed, 118 insertions(+), 118 deletions(-) diff --git a/src/vt/vrt/collection/balance/model/comm_overhead.cc b/src/vt/vrt/collection/balance/model/comm_overhead.cc index 879c38ccad..e4c113346d 100644 --- a/src/vt/vrt/collection/balance/model/comm_overhead.cc +++ b/src/vt/vrt/collection/balance/model/comm_overhead.cc @@ -61,7 +61,7 @@ void CommOverhead::setLoads(std::unordered_map 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; diff --git a/src/vt/vrt/collection/balance/model/comm_overhead.h b/src/vt/vrt/collection/balance/model/comm_overhead.h index 857907e56c..ff68140f47 100644 --- a/src/vt/vrt/collection/balance/model/comm_overhead.h +++ b/src/vt/vrt/collection/balance/model/comm_overhead.h @@ -68,7 +68,7 @@ struct CommOverhead : public ComposedModel { void setLoads(std::unordered_map const* proc_load, std::unordered_map const* proc_comm) override; - TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override; + TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override; private: std::unordered_map const* proc_comm_; /**< Underlying comm data */ diff --git a/src/vt/vrt/collection/balance/model/composed_model.cc b/src/vt/vrt/collection/balance/model/composed_model.cc index 6f3f5b9211..a2b8a836a2 100644 --- a/src/vt/vrt/collection/balance/model/composed_model.cc +++ b/src/vt/vrt/collection/balance/model/composed_model.cc @@ -55,7 +55,7 @@ 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); } @@ -63,28 +63,28 @@ 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(); } diff --git a/src/vt/vrt/collection/balance/model/composed_model.h b/src/vt/vrt/collection/balance/model/composed_model.h index 459fd5f174..265af6d3d8 100644 --- a/src/vt/vrt/collection/balance/model/composed_model.h +++ b/src/vt/vrt/collection/balance/model/composed_model.h @@ -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 base_; diff --git a/src/vt/vrt/collection/balance/model/linear_model.cc b/src/vt/vrt/collection/balance/model/linear_model.cc index 771fd0a497..2d7f8a4377 100644 --- a/src/vt/vrt/collection/balance/model/linear_model.cc +++ b/src/vt/vrt/collection/balance/model/linear_model.cc @@ -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 @@ -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)); } diff --git a/src/vt/vrt/collection/balance/model/linear_model.h b/src/vt/vrt/collection/balance/model/linear_model.h index d0dd569bd6..964f993a15 100644 --- a/src/vt/vrt/collection/balance/model/linear_model.h +++ b/src/vt/vrt/collection/balance/model/linear_model.h @@ -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; diff --git a/src/vt/vrt/collection/balance/model/load_model.h b/src/vt/vrt/collection/balance/model/load_model.h index d290beb15a..0f6dbfdb3d 100644 --- a/src/vt/vrt/collection/balance/model/load_model.h +++ b/src/vt/vrt/collection/balance/model/load_model.h @@ -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 @@ -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" ); @@ -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 {}; } @@ -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 @@ -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 @@ -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 @@ -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; @@ -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 @@ -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 void serialize(Serializer& s) {} diff --git a/src/vt/vrt/collection/balance/model/multiple_phases.cc b/src/vt/vrt/collection/balance/model/multiple_phases.cc index c52c8bd528..b33d3c863c 100644 --- a/src/vt/vrt/collection/balance/model/multiple_phases.cc +++ b/src/vt/vrt/collection/balance/model/multiple_phases.cc @@ -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); diff --git a/src/vt/vrt/collection/balance/model/multiple_phases.h b/src/vt/vrt/collection/balance/model/multiple_phases.h index 899155c549..ee9f228857 100644 --- a/src/vt/vrt/collection/balance/model/multiple_phases.h +++ b/src/vt/vrt/collection/balance/model/multiple_phases.h @@ -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; diff --git a/src/vt/vrt/collection/balance/model/naive_persistence.cc b/src/vt/vrt/collection/balance/model/naive_persistence.cc index 44815bf3a3..dc4d116aef 100644 --- a/src/vt/vrt/collection/balance/model/naive_persistence.cc +++ b/src/vt/vrt/collection/balance/model/naive_persistence.cc @@ -51,14 +51,14 @@ NaivePersistence::NaivePersistence(std::shared_ptr 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; @@ -66,7 +66,7 @@ TimeType NaivePersistence::getRawLoad(ElementIDStruct object, PhaseOffset offset 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)); } diff --git a/src/vt/vrt/collection/balance/model/naive_persistence.h b/src/vt/vrt/collection/balance/model/naive_persistence.h index 168761cb1d..9c9262469d 100644 --- a/src/vt/vrt/collection/balance/model/naive_persistence.h +++ b/src/vt/vrt/collection/balance/model/naive_persistence.h @@ -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 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 diff --git a/src/vt/vrt/collection/balance/model/norm.cc b/src/vt/vrt/collection/balance/model/norm.cc index 06d5272877..5f8bbe7754 100644 --- a/src/vt/vrt/collection/balance/model/norm.cc +++ b/src/vt/vrt/collection/balance/model/norm.cc @@ -55,7 +55,7 @@ Norm::Norm(std::shared_ptr 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); diff --git a/src/vt/vrt/collection/balance/model/norm.h b/src/vt/vrt/collection/balance/model/norm.h index cb096f4e7c..97e03b6e89 100644 --- a/src/vt/vrt/collection/balance/model/norm.h +++ b/src/vt/vrt/collection/balance/model/norm.h @@ -64,7 +64,7 @@ class Norm : public ComposedModel { */ Norm(std::shared_ptr base, double power); - TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override; + TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override; private: const double power_; diff --git a/src/vt/vrt/collection/balance/model/per_collection.cc b/src/vt/vrt/collection/balance/model/per_collection.cc index f495689c18..6b5b812805 100644 --- a/src/vt/vrt/collection/balance/model/per_collection.cc +++ b/src/vt/vrt/collection/balance/model/per_collection.cc @@ -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()) @@ -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()) @@ -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_) diff --git a/src/vt/vrt/collection/balance/model/per_collection.h b/src/vt/vrt/collection/balance/model/per_collection.h index e3971554d3..97e5364818 100644 --- a/src/vt/vrt/collection/balance/model/per_collection.h +++ b/src/vt/vrt/collection/balance/model/per_collection.h @@ -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> models_; diff --git a/src/vt/vrt/collection/balance/model/persistence_median_last_n.cc b/src/vt/vrt/collection/balance/model/persistence_median_last_n.cc index afafcb61d7..004d018afc 100644 --- a/src/vt/vrt/collection/balance/model/persistence_median_last_n.cc +++ b/src/vt/vrt/collection/balance/model/persistence_median_last_n.cc @@ -56,7 +56,7 @@ PersistenceMedianLastN::PersistenceMedianLastN(std::shared_ptr 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); @@ -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)); } diff --git a/src/vt/vrt/collection/balance/model/persistence_median_last_n.h b/src/vt/vrt/collection/balance/model/persistence_median_last_n.h index 55259d59d1..0ed08298c6 100644 --- a/src/vt/vrt/collection/balance/model/persistence_median_last_n.h +++ b/src/vt/vrt/collection/balance/model/persistence_median_last_n.h @@ -65,8 +65,8 @@ struct PersistenceMedianLastN : public ComposedModel */ PersistenceMedianLastN(std::shared_ptr 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_; diff --git a/src/vt/vrt/collection/balance/model/proposed_reassignment.cc b/src/vt/vrt/collection/balance/model/proposed_reassignment.cc index 06e5820ca1..8d818e60c4 100644 --- a/src/vt/vrt/collection/balance/model/proposed_reassignment.cc +++ b/src/vt/vrt/collection/balance/model/proposed_reassignment.cc @@ -63,7 +63,7 @@ ProposedReassignment::ProposedReassignment( // arrive ^ (present \ depart) == 0 } -ObjectIterator ProposedReassignment::begin() +ObjectIterator ProposedReassignment::begin() const { return { std::make_unique( @@ -83,7 +83,7 @@ ObjectIterator ProposedReassignment::begin() )}; } -int ProposedReassignment::getNumObjects() +int ProposedReassignment::getNumObjects() const { int base = ComposedModel::getNumObjects(); int departing = reassignment_->depart_.size(); @@ -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); @@ -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()) { diff --git a/src/vt/vrt/collection/balance/model/proposed_reassignment.h b/src/vt/vrt/collection/balance/model/proposed_reassignment.h index bdb7e01ce0..dc7c087966 100644 --- a/src/vt/vrt/collection/balance/model/proposed_reassignment.h +++ b/src/vt/vrt/collection/balance/model/proposed_reassignment.h @@ -55,10 +55,10 @@ struct ProposedReassignment : public ComposedModel { std::shared_ptr 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 reassignment_; diff --git a/src/vt/vrt/collection/balance/model/raw_data.cc b/src/vt/vrt/collection/balance/model/raw_data.cc index 9f77edc095..47b30d0459 100644 --- a/src/vt/vrt/collection/balance/model/raw_data.cc +++ b/src/vt/vrt/collection/balance/model/raw_data.cc @@ -57,7 +57,7 @@ void RawData::setLoads(std::unordered_map const* proc_lo proc_comm_ = proc_comm; } -ObjectIterator RawData::begin() { +ObjectIterator RawData::begin() const { auto iter = proc_load_->find(last_completed_phase_); if (iter != proc_load_->end()) { return {std::make_unique(iter->second.cbegin(), @@ -67,7 +67,7 @@ ObjectIterator RawData::begin() { } } -int RawData::getNumObjects() { +int RawData::getNumObjects() const { auto iter = proc_load_->find(last_completed_phase_); if (iter != proc_load_->end()) { return iter->second.size(); @@ -76,11 +76,11 @@ int RawData::getNumObjects() { } } -unsigned int RawData::getNumCompletedPhases() { +unsigned int RawData::getNumCompletedPhases() const { return last_completed_phase_ + 1; } -int RawData::getNumSubphases() { +int RawData::getNumSubphases() const { const auto& last_phase = proc_load_->at(last_completed_phase_); // @todo: this workaround is O(#objects) and should be removed when we finish @@ -94,11 +94,11 @@ int RawData::getNumSubphases() { return subphases; } -TimeType RawData::getModeledLoad(ElementIDStruct object, PhaseOffset offset) { +TimeType RawData::getModeledLoad(ElementIDStruct object, PhaseOffset offset) const { return getRawLoad(object, offset); } -TimeType RawData::getRawLoad(ElementIDStruct object, PhaseOffset offset) { +TimeType RawData::getRawLoad(ElementIDStruct object, PhaseOffset offset) const { vtAssert(offset.phases < 0, "RawData makes no predictions. Compose with NaivePersistence or some longer-range forecasting model as needed"); @@ -106,7 +106,7 @@ TimeType RawData::getRawLoad(ElementIDStruct object, PhaseOffset offset) { return proc_load_->at(phase).at(object).get(offset); } -unsigned int RawData::getNumPastPhasesNeeded(unsigned int look_back) +unsigned int RawData::getNumPastPhasesNeeded(unsigned int look_back) const { return look_back; } diff --git a/src/vt/vrt/collection/balance/model/raw_data.h b/src/vt/vrt/collection/balance/model/raw_data.h index bbaa3ca163..b3c5328c8c 100644 --- a/src/vt/vrt/collection/balance/model/raw_data.h +++ b/src/vt/vrt/collection/balance/model/raw_data.h @@ -59,19 +59,19 @@ namespace vt { namespace vrt { namespace collection { namespace balance { struct RawData : public LoadModel { RawData() = default; 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 { return true; } - TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) override; + TimeType getRawLoad(ElementIDStruct object, PhaseOffset when) const override; void setLoads(std::unordered_map const* proc_load, std::unordered_map const* proc_comm) override; - ObjectIterator begin() override; + ObjectIterator begin() const override; - int getNumObjects() override; - unsigned int getNumCompletedPhases() override; - int getNumSubphases() override; - unsigned int getNumPastPhasesNeeded(unsigned int look_back) override; + int getNumObjects() const override; + unsigned int getNumCompletedPhases() const override; + int getNumSubphases() const override; + unsigned int getNumPastPhasesNeeded(unsigned int look_back) const override; // Observer pointers to the underlying data. In operation, these would be owned by NodeLBData std::unordered_map const* proc_load_; diff --git a/src/vt/vrt/collection/balance/model/select_subphases.cc b/src/vt/vrt/collection/balance/model/select_subphases.cc index 1777db5b14..7a821e0353 100644 --- a/src/vt/vrt/collection/balance/model/select_subphases.cc +++ b/src/vt/vrt/collection/balance/model/select_subphases.cc @@ -59,7 +59,7 @@ SelectSubphases::SelectSubphases(std::shared_ptr base, std::vector base, std::vector subphases); - TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) override; - int getNumSubphases() override; + TimeType getModeledLoad(ElementIDStruct object, PhaseOffset when) const override; + int getNumSubphases() const override; std::vector subphases_; }; // class SelectSubphases diff --git a/src/vt/vrt/collection/balance/model/weighted_messages.cc b/src/vt/vrt/collection/balance/model/weighted_messages.cc index 153dcd4325..c71827afd7 100644 --- a/src/vt/vrt/collection/balance/model/weighted_messages.cc +++ b/src/vt/vrt/collection/balance/model/weighted_messages.cc @@ -46,7 +46,7 @@ namespace vt { namespace vrt { namespace collection { namespace balance { TimeType -WeightedMessages::getModeledComm(ElementIDStruct object, PhaseOffset when) { +WeightedMessages::getModeledComm(ElementIDStruct object, PhaseOffset when) const { auto phase = getNumCompletedPhases() + when.phases; auto& comm = proc_comm_->at(phase); diff --git a/src/vt/vrt/collection/balance/model/weighted_messages.h b/src/vt/vrt/collection/balance/model/weighted_messages.h index daadcf2533..a8f5ec5065 100644 --- a/src/vt/vrt/collection/balance/model/weighted_messages.h +++ b/src/vt/vrt/collection/balance/model/weighted_messages.h @@ -72,7 +72,7 @@ struct WeightedMessages : public ComposedModel { ComposedModel::setLoads(proc_load, proc_comm); } - TimeType getModeledComm(ElementIDStruct object, PhaseOffset when) override; + TimeType getModeledComm(ElementIDStruct object, PhaseOffset when) const override; private: // observer pointer to the underlying comm data diff --git a/tests/unit/collection/test_model_comm_overhead.nompi.cc b/tests/unit/collection/test_model_comm_overhead.nompi.cc index ba73ed37e8..f193a0db56 100644 --- a/tests/unit/collection/test_model_comm_overhead.nompi.cc +++ b/tests/unit/collection/test_model_comm_overhead.nompi.cc @@ -86,7 +86,7 @@ struct StubModel : LoadModel { void updateLoads(PhaseType) override {} - TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) override { + TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override { const auto work = proc_load_->at(0).at(id).whole_phase_load; if (phase.subphase == PhaseOffset::WHOLE_PHASE) { @@ -96,15 +96,15 @@ struct StubModel : LoadModel { } } - ObjectIterator begin() override { + ObjectIterator begin() const override { return {std::make_unique(proc_load_->at(0).begin(), proc_load_->at(0).end())}; } - unsigned int getNumCompletedPhases() override { return num_phases; } + unsigned int getNumCompletedPhases() const override { return num_phases; } // Not used in this test - int getNumSubphases() override { return 0; } - unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) override { return look_back; } + int getNumSubphases() const override { return 0; } + unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const override { return look_back; } private: ProcLoadMap const* proc_load_ = nullptr; diff --git a/tests/unit/collection/test_model_linear_model.nompi.cc b/tests/unit/collection/test_model_linear_model.nompi.cc index a432b3b958..79ce7752a4 100644 --- a/tests/unit/collection/test_model_linear_model.nompi.cc +++ b/tests/unit/collection/test_model_linear_model.nompi.cc @@ -79,18 +79,18 @@ struct StubModel : LoadModel { void updateLoads(PhaseType) override {} - TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) override { + TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override { // Most recent phase will be at the end of vector return proc_load_->at(num_phases + phase.phases).at(id).whole_phase_load; } - virtual ObjectIterator begin() override { + virtual ObjectIterator begin() const override { return {std::make_unique(proc_load_->at(0).begin(), proc_load_->at(0).end())}; } - virtual unsigned int getNumCompletedPhases() override { return num_phases; } - virtual int getNumSubphases() override { return 1; } - unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) override { return look_back; } + virtual unsigned int getNumCompletedPhases() const override { return num_phases; } + virtual int getNumSubphases() const override { return 1; } + unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const override { return look_back; } private: std::unordered_map const* proc_load_ = nullptr; diff --git a/tests/unit/collection/test_model_multiple_phases.nompi.cc b/tests/unit/collection/test_model_multiple_phases.nompi.cc index ce43affa52..b61c94851c 100644 --- a/tests/unit/collection/test_model_multiple_phases.nompi.cc +++ b/tests/unit/collection/test_model_multiple_phases.nompi.cc @@ -77,20 +77,20 @@ struct StubModel : LoadModel { void updateLoads(PhaseType) override {} - TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) override { + TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override { // Here we return predicted loads for future phases // For the sake of the test we use values from the past phases return proc_load_->at(phase.phases).at(id).whole_phase_load; } - virtual ObjectIterator begin() override { + virtual ObjectIterator begin() const override { return {std::make_unique(proc_load_->at(3).begin(), proc_load_->at(3).end())}; } // Not used by this test - virtual unsigned int getNumCompletedPhases() override { return 0; } - virtual int getNumSubphases() override { return 0; } - unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) override { return look_back; } + virtual unsigned int getNumCompletedPhases() const override { return 0; } + virtual int getNumSubphases() const override { return 0; } + unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const override { return look_back; } private: std::unordered_map const* proc_load_ = nullptr; diff --git a/tests/unit/collection/test_model_naive_persistence.nompi.cc b/tests/unit/collection/test_model_naive_persistence.nompi.cc index f9b7636940..6f8e678510 100644 --- a/tests/unit/collection/test_model_naive_persistence.nompi.cc +++ b/tests/unit/collection/test_model_naive_persistence.nompi.cc @@ -81,19 +81,19 @@ struct StubModel : LoadModel { void updateLoads(PhaseType) override {} - TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) override { + TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override { EXPECT_LE(phase.phases, -1); return proc_load_->at(getIndexFromPhase(phase.phases)).at(id).whole_phase_load; } - virtual ObjectIterator begin() override { + virtual ObjectIterator begin() const override { return {std::make_unique(proc_load_->at(3).begin(), proc_load_->at(3).end())}; } // Not used in this test - virtual unsigned int getNumCompletedPhases() override { return 1; } - virtual int getNumSubphases() override { return 1; } - unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) override { return look_back; } + virtual unsigned int getNumCompletedPhases() const override { return 1; } + virtual int getNumSubphases() const override { return 1; } + unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const override { return look_back; } private: std::unordered_map const* proc_load_ = nullptr; diff --git a/tests/unit/collection/test_model_norm.nompi.cc b/tests/unit/collection/test_model_norm.nompi.cc index 9cd6d3a5f6..2765837a7b 100644 --- a/tests/unit/collection/test_model_norm.nompi.cc +++ b/tests/unit/collection/test_model_norm.nompi.cc @@ -84,19 +84,19 @@ struct StubModel : LoadModel { void updateLoads(PhaseType) override {} - TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) override { + TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override { return proc_load_->at(0).at(id).subphase_loads.at(phase.subphase); } - ObjectIterator begin() override { + ObjectIterator begin() const override { return {std::make_unique(proc_load_->at(0).begin(), proc_load_->at(0).end())}; } - int getNumSubphases() override { return num_subphases; } + int getNumSubphases() const override { return num_subphases; } // Not used in this test - unsigned int getNumCompletedPhases() override { return 0; } - unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) override { return look_back; } + unsigned int getNumCompletedPhases() const override { return 0; } + unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const override { return look_back; } private: ProcLoadMap const* proc_load_ = nullptr; diff --git a/tests/unit/collection/test_model_per_collection.extended.cc b/tests/unit/collection/test_model_per_collection.extended.cc index feb5552273..7f7d8841b7 100644 --- a/tests/unit/collection/test_model_per_collection.extended.cc +++ b/tests/unit/collection/test_model_per_collection.extended.cc @@ -74,7 +74,7 @@ struct ConstantTestModel : ComposedModel { proxy_(in_proxy) { } - TimeType getModeledLoad(ElementIDStruct, PhaseOffset) override { + TimeType getModeledLoad(ElementIDStruct, PhaseOffset) const override { return static_cast(proxy_); } diff --git a/tests/unit/collection/test_model_persistence_median_last_n.nompi.cc b/tests/unit/collection/test_model_persistence_median_last_n.nompi.cc index 108153070b..f7a91ea145 100644 --- a/tests/unit/collection/test_model_persistence_median_last_n.nompi.cc +++ b/tests/unit/collection/test_model_persistence_median_last_n.nompi.cc @@ -79,18 +79,18 @@ struct StubModel : LoadModel { void updateLoads(PhaseType) override {} - TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) override { + TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override { // Most recent phase will be at the end of vector return proc_load_->at(num_phases + phase.phases).at(id).whole_phase_load; } - virtual ObjectIterator begin() override { + virtual ObjectIterator begin() const override { return {std::make_unique(proc_load_->at(num_phases-1).begin(), proc_load_->at(num_phases-1).end())}; } - virtual unsigned int getNumCompletedPhases() override { return num_phases; } - virtual int getNumSubphases() override { return 1; } - unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) override { return look_back; } + virtual unsigned int getNumCompletedPhases() const override { return num_phases; } + virtual int getNumSubphases() const override { return 1; } + unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const override { return look_back; } private: std::unordered_map const* proc_load_ = nullptr; diff --git a/tests/unit/collection/test_model_select_subphases.nompi.cc b/tests/unit/collection/test_model_select_subphases.nompi.cc index 6880f0e95c..dc97d55528 100644 --- a/tests/unit/collection/test_model_select_subphases.nompi.cc +++ b/tests/unit/collection/test_model_select_subphases.nompi.cc @@ -83,11 +83,11 @@ struct StubModel : LoadModel { void updateLoads(PhaseType) override {} - TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) override { + TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override { return proc_load_->at(0).at(id).subphase_loads.at(phase.subphase); } - ObjectIterator begin() override { + ObjectIterator begin() const override { return { std::make_unique( proc_load_->at(0).begin(), proc_load_->at(0).end() @@ -95,11 +95,11 @@ struct StubModel : LoadModel { }; } - int getNumSubphases() override { return num_subphases; } + int getNumSubphases() const override { return num_subphases; } // Not used in this test - unsigned int getNumCompletedPhases() override { return 0; } - unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) override { + unsigned int getNumCompletedPhases() const override { return 0; } + unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const override { return look_back; } diff --git a/tests/unit/collection/test_model_weighted_messages.nompi.cc b/tests/unit/collection/test_model_weighted_messages.nompi.cc index b231f8a76c..91cce389c4 100644 --- a/tests/unit/collection/test_model_weighted_messages.nompi.cc +++ b/tests/unit/collection/test_model_weighted_messages.nompi.cc @@ -81,7 +81,7 @@ struct StubModel : LoadModel { void updateLoads(PhaseType) override { } - TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) override { + TimeType getModeledLoad(ElementIDStruct id, PhaseOffset phase) const override { const auto work = proc_load_->at(0).at(id).whole_phase_load; if (phase.subphase == PhaseOffset::WHOLE_PHASE) { @@ -91,17 +91,17 @@ struct StubModel : LoadModel { } } - ObjectIterator begin() override { + ObjectIterator begin() const override { return {std::make_unique( proc_load_->at(0).begin(), proc_load_->at(0).end() )}; } - unsigned int getNumCompletedPhases() override { return num_phases; } + unsigned int getNumCompletedPhases() const override { return num_phases; } // Not used in this test - int getNumSubphases() override { return 0; } - unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) override { + int getNumSubphases() const override { return 0; } + unsigned int getNumPastPhasesNeeded(unsigned int look_back = 0) const override { return look_back; }