From 63cae4f228ba73bfc9d56b078145369382a785ae Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Mon, 20 Jul 2020 13:33:17 -0400 Subject: [PATCH] #582: Implement a compositional model of object load prediction --- .../balance/lb_invoke/lb_manager.cc | 3 +- .../collection/balance/model/comm_overhead.cc | 80 +++++++++++++++++++ .../collection/balance/model/comm_overhead.h | 65 +++++++++++++++ .../balance/model/composed_model.cc | 75 +++++++++++++++++ .../collection/balance/model/composed_model.h | 78 ++++++++++++++++++ .../vrt/collection/balance/model/load_model.h | 28 +++---- .../balance/model/naive_persistence.cc | 24 +++--- .../balance/model/naive_persistence.h | 7 +- src/vt/vrt/collection/balance/model/norm.cc | 31 +++++-- src/vt/vrt/collection/balance/model/norm.h | 12 +-- .../vrt/collection/balance/model/raw_data.cc | 75 +++++++++++++++++ .../vrt/collection/balance/model/raw_data.h | 76 ++++++++++++++++++ 12 files changed, 504 insertions(+), 50 deletions(-) create mode 100644 src/vt/vrt/collection/balance/model/comm_overhead.cc create mode 100644 src/vt/vrt/collection/balance/model/comm_overhead.h create mode 100644 src/vt/vrt/collection/balance/model/composed_model.cc create mode 100644 src/vt/vrt/collection/balance/model/composed_model.h create mode 100644 src/vt/vrt/collection/balance/model/raw_data.cc create mode 100644 src/vt/vrt/collection/balance/model/raw_data.h diff --git a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc index 276c715d1d..39ee7d642c 100644 --- a/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc +++ b/src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc @@ -61,6 +61,7 @@ #include "vt/utils/memory/memory_usage.h" #include "vt/vrt/collection/balance/model/load_model.h" #include "vt/vrt/collection/balance/model/naive_persistence.h" +#include "vt/vrt/collection/balance/model/raw_data.h" namespace vt { namespace vrt { namespace collection { namespace balance { @@ -148,7 +149,7 @@ LBManager::makeLB(MsgSharedPtr msg) { EpochType migrate_epoch = theTerm()->makeEpochCollective("LBManager::migrate_epoch"); if (model_ == nullptr) - setLoadModel(std::make_unique()); + setLoadModel(std::make_unique(new balance::RawData)); theMsg()->pushEpoch(model_epoch); model_->updateLoads(phase); diff --git a/src/vt/vrt/collection/balance/model/comm_overhead.cc b/src/vt/vrt/collection/balance/model/comm_overhead.cc new file mode 100644 index 0000000000..a6cb4e47ab --- /dev/null +++ b/src/vt/vrt/collection/balance/model/comm_overhead.cc @@ -0,0 +1,80 @@ +/* +//@HEADER +// ***************************************************************************** +// +// comm_overhead.cc +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + + +#include "vt/vrt/collection/balance/model/comm_overhead.h" + +namespace vt { namespace vrt { namespace collection { namespace balance { + +CommOverhead::CommOverhead(balance::LoadModel *base) + : ComposedModel(base) +{ +} + +void CommOverhead::setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) { + proc_comm_ = proc_comm; + ComposedModel::setLoads(proc_load, proc_subphase_load, proc_comm); +} + +TimeType CommOverhead::getWork(ElementIDType object, PhaseOffset offset) +{ + auto work = ComposedModel::getWork(object, offset); + + vtAbort("Not fully implemented yet"); +#if 0 + // Add a bit of overhead for each off-node received message per object + for (auto &&comm : *comms_) { + auto obj = loads_.find(comm.first.toObj()); + if (obj != loads_.end()) + work += 0.001 * comm.second.messages; + } +#endif + + return work; +} + + +}}}} diff --git a/src/vt/vrt/collection/balance/model/comm_overhead.h b/src/vt/vrt/collection/balance/model/comm_overhead.h new file mode 100644 index 0000000000..4fbadec78c --- /dev/null +++ b/src/vt/vrt/collection/balance/model/comm_overhead.h @@ -0,0 +1,65 @@ +/* +//@HEADER +// ***************************************************************************** +// +// comm_overhead.h +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#if !defined INCLUDED_VRT_COLLECTION_BALANCE_COMM_OVERHEAD_H +#define INCLUDED_VRT_COLLECTION_BALANCE_COMM_OVERHEAD_H + +#include "vt/vrt/collection/balance/model/composed_model.h" +#include + +namespace vt { namespace vrt { namespace collection { namespace balance { + +struct CommOverhead : public ComposedModel { + CommOverhead(balance::LoadModel *base); + void setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) override; + TimeType getWork(ElementIDType object, PhaseOffset when) override; + + std::vector const* proc_comm_; +}; // class CommOverhead + +}}}} // end namespace + +#endif diff --git a/src/vt/vrt/collection/balance/model/composed_model.cc b/src/vt/vrt/collection/balance/model/composed_model.cc new file mode 100644 index 0000000000..99e101f255 --- /dev/null +++ b/src/vt/vrt/collection/balance/model/composed_model.cc @@ -0,0 +1,75 @@ +/* +//@HEADER +// ***************************************************************************** +// +// composed_model.cc +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#include "vt/vrt/collection/balance/model/composed_model.h" + +namespace vt { namespace vrt { namespace collection { namespace balance { + +void ComposedModel::setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) { + base_.setLoads(proc_load, proc_subphase_load, proc_comm); +} + +void ComposedModel::updateLoads(PhaseType last_completed_phase) { + base_.updateLoads(last_completed_phase); +} + +TimeType ComposedModel::getWork(ElementIDType object, PhaseOffset when) { + return base_.getWork(object, when); +} + +ObjectIterator ComposedModel::begin() { + return base_.begin(); +} + +ObjectIterator ComposedModel::end() { + return base_.end(); +} + +int ComposedModel::getNumObjects() { + return base_.getNumObjects(); +} + +}}}} diff --git a/src/vt/vrt/collection/balance/model/composed_model.h b/src/vt/vrt/collection/balance/model/composed_model.h new file mode 100644 index 0000000000..06723a6383 --- /dev/null +++ b/src/vt/vrt/collection/balance/model/composed_model.h @@ -0,0 +1,78 @@ +/* +//@HEADER +// ***************************************************************************** +// +// composed_model.h +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#if !defined INCLUDED_VRT_COLLECTION_BALANCE_COMPOSED_MODEL_H +#define INCLUDED_VRT_COLLECTION_BALANCE_COMPOSED_MODEL_H + +#include "vt/config.h" +#include "vt/vrt/collection/balance/model/load_model.h" + +namespace vt { namespace vrt { namespace collection { namespace balance { + +class ComposedModel : public LoadModel +{ +public: + // \param[in] base must not be null + ComposedModel(LoadModel *base) : base_(*base) {} + + void setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) override; + + void updateLoads(PhaseType last_completed_phase) override; + + TimeType getWork(ElementIDType object, PhaseOffset when) override; + + ObjectIterator begin() override; + ObjectIterator end() override; + + int getNumObjects() override; + +private: + LoadModel &base_; +}; // class ComposedModel + +}}}} // namespaces + +#endif diff --git a/src/vt/vrt/collection/balance/model/load_model.h b/src/vt/vrt/collection/balance/model/load_model.h index f3c32cd150..023d0a3089 100644 --- a/src/vt/vrt/collection/balance/model/load_model.h +++ b/src/vt/vrt/collection/balance/model/load_model.h @@ -88,7 +88,8 @@ class ObjectIterator { class LoadModel { public: - LoadModel() {} + LoadModel() = default; + virtual ~LoadModel() = default; /** * \internal \brief Initialize the model instance with pointers to the measured load data @@ -96,14 +97,9 @@ class LoadModel * This would typically be called by LBManager when the user has * passed a new model instance for a collection */ - void setLoads(std::vector const* proc_load, - std::vector const* proc_subphase_load, - std::vector const* proc_comm) - { - proc_load_ = proc_load; - proc_subphase_load_ = proc_subphase_load; - proc_comm_ = proc_comm; - } + virtual void setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) = 0; /** * \brief Signals that load data for a new phase is available @@ -115,7 +111,7 @@ class LoadModel * an epoch that can be used for global communication in advance of * any calls to getWork() */ - virtual void updateLoads(PhaseType last_completed_phase) { } + virtual void updateLoads(PhaseType last_completed_phase) = 0; /** * \brief Provide an estimate of the given object's load during a specified interval @@ -128,16 +124,10 @@ class LoadModel virtual TimeType getWork(ElementIDType object, PhaseOffset when) = 0; // Object enumeration, to abstract away access to the underlying structures from ProcStats - ObjectIterator begin() { return ObjectIterator(proc_load_->back().begin()); } - ObjectIterator end() { return ObjectIterator(proc_load_->back().end()); } + virtual ObjectIterator begin() = 0; + virtual ObjectIterator end() = 0; - int getNumObjects() { return end() - begin(); } - -protected: - // Observer pointers to the underlying data. In operation, these would be owned by ProcStats - std::vector const* proc_load_; - std::vector const* proc_subphase_load_; - std::vector const* proc_comm_; + virtual int getNumObjects() = 0; }; // class LoadModel }}}} // namespaces diff --git a/src/vt/vrt/collection/balance/model/naive_persistence.cc b/src/vt/vrt/collection/balance/model/naive_persistence.cc index e2362c67ea..31853bad59 100644 --- a/src/vt/vrt/collection/balance/model/naive_persistence.cc +++ b/src/vt/vrt/collection/balance/model/naive_persistence.cc @@ -2,7 +2,7 @@ //@HEADER // ***************************************************************************** // -// naive_persistence.cpp +// naive_persistence.cc // DARMA Toolkit v. 1.0.0 // DARMA/vt => Virtual Transport // @@ -47,22 +47,16 @@ namespace vt { namespace vrt { namespace collection { namespace balance { -NaivePersistence::NaivePersistence() -{ - /* -// Add a bit of overhead for each off-node received message per object - for (auto &&comm : *comms_) { - auto obj = loads_.find(comm.first.toObj()); - if (obj != loads_.end()) - obj->second += 0.001 * comm.second.messages; - } - */ -} +NaivePersistence::NaivePersistence(balance::LoadModel *base) + : ComposedModel(base) +{ } -TimeType NaivePersistence::getWork(ElementIDType object, PhaseOffset /*ignored*/) +TimeType NaivePersistence::getWork(ElementIDType object, PhaseOffset offset) { - return proc_load_->back().at(object); -} + if (offset.phases >= 0) + offset.phases = -1; + return ComposedModel::getWork(object, offset); +} }}}} diff --git a/src/vt/vrt/collection/balance/model/naive_persistence.h b/src/vt/vrt/collection/balance/model/naive_persistence.h index 1cba0db43b..42ae3ff9fa 100644 --- a/src/vt/vrt/collection/balance/model/naive_persistence.h +++ b/src/vt/vrt/collection/balance/model/naive_persistence.h @@ -45,14 +45,13 @@ #if !defined INCLUDED_VRT_COLLECTION_BALANCE_NAIVE_PERSISTENCE_H #define INCLUDED_VRT_COLLECTION_BALANCE_NAIVE_PERSISTENCE_H -#include "vt/vrt/collection/balance/model/load_model.h" -#include "vt/vrt/collection/balance/lb_comm.h" +#include "vt/vrt/collection/balance/model/composed_model.h" #include namespace vt { namespace vrt { namespace collection { namespace balance { -struct NaivePersistence : public LoadModel { - NaivePersistence(); +struct NaivePersistence : public ComposedModel { + NaivePersistence(balance::LoadModel *base); TimeType getWork(ElementIDType object, PhaseOffset when) override; }; // class NaivePersistence diff --git a/src/vt/vrt/collection/balance/model/norm.cc b/src/vt/vrt/collection/balance/model/norm.cc index 8d3362aeee..242eed4e0f 100644 --- a/src/vt/vrt/collection/balance/model/norm.cc +++ b/src/vt/vrt/collection/balance/model/norm.cc @@ -48,28 +48,47 @@ namespace vt { namespace vrt { namespace collection { namespace balance { -Norm::Norm(double power) - : power_(power) +Norm::Norm(balance::LoadModel *base, double power) + : ComposedModel(base) + , power_(power) { vtAssert(not std::isnan(power), "Power must have a real value"); vtAssert(power >= 0.0, "Reciprocal loads make no sense"); } -TimeType Norm::getWork(ElementIDType object, PhaseOffset /*ignored*/) +void Norm::setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) { + const auto& last_phase = proc_subphase_load->back(); + const auto& an_object = *last_phase.begin(); + const auto& subphases = an_object.second; + num_subphases_ = subphases.size(); + + ComposedModel::setLoads(proc_load, proc_subphase_load, proc_comm); +} + +TimeType Norm::getWork(ElementIDType object, PhaseOffset offset) { - auto const& subphase_loads = proc_subphase_load_->back().at(object); + if (offset.subphase != PhaseOffset::WHOLE_PHASE) + return ComposedModel::getWork(object, offset); if (std::isfinite(power_)) { double sum = 0.0; - for (auto t : subphase_loads) + + for (int i = 0; i < num_subphases_; ++i) { + auto t = ComposedModel::getWork(object, offset); sum += std::pow(t, power_); + } return std::pow(sum, 1.0/power_); } else { // l-infinity implies a max norm double max = 0.0; - for (auto t : subphase_loads) + + for (int i = 0; i < num_subphases_; ++i) { + auto t = ComposedModel::getWork(object, offset); max = std::max(max, t); + } return max; } diff --git a/src/vt/vrt/collection/balance/model/norm.h b/src/vt/vrt/collection/balance/model/norm.h index b84bfdeb79..a26fe0451d 100644 --- a/src/vt/vrt/collection/balance/model/norm.h +++ b/src/vt/vrt/collection/balance/model/norm.h @@ -45,9 +45,7 @@ #if !defined INCLUDED_VRT_COLLECTION_BALANCE_NAIVE_PERSISTENCE_H #define INCLUDED_VRT_COLLECTION_BALANCE_NAIVE_PERSISTENCE_H -#include "vt/vrt/collection/balance/model/load_model.h" -#include "vt/vrt/collection/balance/lb_comm.h" -#include "vt/vrt/collection/balance/proc_stats.h" +#include "vt/vrt/collection/balance/model/composed_model.h" #include namespace vt { namespace vrt { namespace collection { namespace balance { @@ -56,7 +54,7 @@ namespace vt { namespace vrt { namespace collection { namespace balance { * \brief A load model that computes an l-norm of a given power across * subphases */ -class Norm : public LoadModel { +class Norm : public ComposedModel { public: /** @@ -64,10 +62,14 @@ class Norm : public LoadModel { * * \param[in] power The power to use in computing the norms */ - Norm(double power); + Norm(balance::LoadModel *base, double power); + void setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) override; TimeType getWork(ElementIDType object, PhaseOffset when) override; private: + int num_subphases_; const double power_; }; // class Norm diff --git a/src/vt/vrt/collection/balance/model/raw_data.cc b/src/vt/vrt/collection/balance/model/raw_data.cc new file mode 100644 index 0000000000..5f64e64046 --- /dev/null +++ b/src/vt/vrt/collection/balance/model/raw_data.cc @@ -0,0 +1,75 @@ +/* +//@HEADER +// ***************************************************************************** +// +// raw_data.cc +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + + +#include "vt/vrt/collection/balance/model/raw_data.h" + +namespace vt { namespace vrt { namespace collection { namespace balance { + +RawData::RawData() +{ +} + +void RawData::setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) +{ + proc_load_ = proc_load; + proc_subphase_load_ = proc_subphase_load; + proc_comm_ = proc_comm; +} + +TimeType RawData::getWork(ElementIDType object, PhaseOffset offset) +{ + vtAssert(offset.phases < 0, + "RawData makes no predictions. Compose with NaivePersistence or some longer-range forecasting model as needed"); + + auto phase = proc_load_->size() - offset.phases; + if (offset.subphase == PhaseOffset::WHOLE_PHASE) + return proc_load_->at(phase).at(object); + else + return proc_subphase_load_->at(phase).at(object).at(offset.subphase); +} + +}}}} diff --git a/src/vt/vrt/collection/balance/model/raw_data.h b/src/vt/vrt/collection/balance/model/raw_data.h new file mode 100644 index 0000000000..2c7c8f38f1 --- /dev/null +++ b/src/vt/vrt/collection/balance/model/raw_data.h @@ -0,0 +1,76 @@ +/* +//@HEADER +// ***************************************************************************** +// +// raw_data.h +// DARMA Toolkit v. 1.0.0 +// DARMA/vt => Virtual Transport +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#if !defined INCLUDED_VRT_COLLECTION_BALANCE_RAW_DATA_H +#define INCLUDED_VRT_COLLECTION_BALANCE_RAW_DATA_H + +#include "vt/vrt/collection/balance/model/load_model.h" +#include "vt/vrt/collection/balance/lb_comm.h" +#include + +namespace vt { namespace vrt { namespace collection { namespace balance { + +struct RawData : public LoadModel { + RawData(); + void updateLoads(PhaseType last_completed_phase) override { } + TimeType getWork(ElementIDType object, PhaseOffset when) override; + + void setLoads(std::vector const* proc_load, + std::vector const* proc_subphase_load, + std::vector const* proc_comm) override; + + ObjectIterator begin() override { return ObjectIterator(proc_load_->back().begin()); } + ObjectIterator end() override { return ObjectIterator(proc_load_->back().end()); } + + int getNumObjects() override { return end() - begin(); } + + // Observer pointers to the underlying data. In operation, these would be owned by ProcStats + std::vector const* proc_load_; + std::vector const* proc_subphase_load_; + std::vector const* proc_comm_; +}; // class RawData + +}}}} // end namespace + +#endif