From: Ehsan Azimi Date: Thu, 29 Oct 2020 09:38:55 +0000 (+0100) Subject: Merge branch 'master' of github.com:simgrid/simgrid X-Git-Tag: v3.26~72^2^2~59 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4b556ae9138a84688e4c3be1ad3464688fcf8abc?hp=534039d7635bc420c005444981b32e4bcd42ed77 Merge branch 'master' of github.com:simgrid/simgrid --- diff --git a/src/kernel/resource/profile/DatedValue.cpp b/src/kernel/resource/profile/DatedValue.cpp index 68955de29b..61c386ef1d 100644 --- a/src/kernel/resource/profile/DatedValue.cpp +++ b/src/kernel/resource/profile/DatedValue.cpp @@ -14,11 +14,6 @@ bool DatedValue::operator==(DatedValue const& e2) const { return (fabs(date_ - e2.date_) < 0.0001) && (fabs(value_ - e2.value_) < 0.0001); } -std::ostream& operator<<(std::ostream& out, const DatedValue& e) -{ - out << e.date_ << " " << e.value_; - return out; -} } // namespace profile } // namespace kernel diff --git a/src/kernel/resource/profile/DatedValue.hpp b/src/kernel/resource/profile/DatedValue.hpp index 6e5d32cfd9..24b7540957 100644 --- a/src/kernel/resource/profile/DatedValue.hpp +++ b/src/kernel/resource/profile/DatedValue.hpp @@ -32,7 +32,6 @@ public: bool operator==(DatedValue const& e2) const; bool operator!=(DatedValue const& e2) const { return not(*this == e2); } }; -std::ostream& operator<<(std::ostream& out, const DatedValue& e); } // namespace profile } // namespace kernel diff --git a/src/kernel/resource/profile/Profile.cpp b/src/kernel/resource/profile/Profile.cpp index 587a063a67..9a85416023 100644 --- a/src/kernel/resource/profile/Profile.cpp +++ b/src/kernel/resource/profile/Profile.cpp @@ -133,53 +133,51 @@ Profile* Profile::from_string(const std::string& name, const std::string& input, xbt_assert(splittedval.size() > 0, "Invalid profile line"); if (splittedval[0] == "DET") { - stochevent.date_law = Dist_Det; + stochevent.date_law = Distribution::DET; i = 2; } else if (splittedval[0] == "NORM" || splittedval[0] == "NORMAL" || splittedval[0] == "GAUSS" || splittedval[0] == "GAUSSIAN") { - stochevent.date_law = Dist_Norm; + stochevent.date_law = Distribution::NORM; i = 3; } else if (splittedval[0] == "EXP" || splittedval[0] == "EXPONENTIAL") { - stochevent.date_law = Dist_Exp; + stochevent.date_law = Distribution::EXP; i = 2; } else if (splittedval[0] == "UNIF" || splittedval[0] == "UNIFORM") { - stochevent.date_law = Dist_Unif; + stochevent.date_law = Distribution::UNIF; i = 3; } else { - xbt_assert(false, "Unknown law %s", splittedval[0].c_str()); - i = 0; + xbt_die("Unknown law %s", splittedval[0].c_str()); } xbt_assert(splittedval.size() > i, "Invalid profile line"); if (i == 2) { - stochevent.date_params = {std::atof(splittedval[1].c_str())}; + stochevent.date_params = {std::stod(splittedval[1])}; } else if (i == 3) { - stochevent.date_params = {std::atof(splittedval[1].c_str()), std::atof(splittedval[2].c_str())}; + stochevent.date_params = {std::stod(splittedval[1]), std::stod(splittedval[2])}; } if (splittedval[i] == "DET") { - stochevent.value_law = Dist_Det; + stochevent.value_law = Distribution::DET; j = 1; } else if (splittedval[i] == "NORM" || splittedval[i] == "NORMAL" || splittedval[i] == "GAUSS" || splittedval[i] == "GAUSSIAN") { - stochevent.value_law = Dist_Norm; + stochevent.value_law = Distribution::NORM; j = 2; } else if (splittedval[i] == "EXP" || splittedval[i] == "EXPONENTIAL") { - stochevent.value_law = Dist_Exp; + stochevent.value_law = Distribution::EXP; j = 1; } else if (splittedval[i] == "UNIF" || splittedval[i] == "UNIFORM") { - stochevent.value_law = Dist_Unif; + stochevent.value_law = Distribution::UNIF; j = 2; } else { - xbt_assert(false, "Unknown law %s", splittedval[i].c_str()); - j = 0; + xbt_die("Unknown law %s", splittedval[i].c_str()); } xbt_assert(splittedval.size() > i + j, "Invalid profile line"); if (j == 1) { - stochevent.value_params = {std::atof(splittedval[i + 1].c_str())}; + stochevent.value_params = {std::stod(splittedval[i + 1])}; } else if (j == 2) { - stochevent.value_params = {std::atof(splittedval[i + 1].c_str()), std::atof(splittedval[i + 2].c_str())}; + stochevent.value_params = {std::stod(splittedval[i + 1]), std::stod(splittedval[i + 2])}; } profile->stochastic_event_list.emplace_back(stochevent); diff --git a/src/kernel/resource/profile/Profile_test.cpp b/src/kernel/resource/profile/Profile_test.cpp index 55f4c610d8..f7e2abdb7f 100644 --- a/src/kernel/resource/profile/Profile_test.cpp +++ b/src/kernel/resource/profile/Profile_test.cpp @@ -20,18 +20,21 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(unit, "Unit tests of the Trace Manager"); -double thedate; class MockedResource : public simgrid::kernel::resource::Resource { public: + static double the_date; + explicit MockedResource() : simgrid::kernel::resource::Resource(nullptr, "fake", nullptr) {} void apply_event(simgrid::kernel::profile::Event* event, double value) override { - XBT_VERB("t=%.1f: Change value to %lg (idx: %u)", thedate, value, event->idx); + XBT_VERB("t=%.1f: Change value to %lg (idx: %u)", the_date, value, event->idx); tmgr_trace_event_unref(&event); } bool is_used() const override { return true; } }; +double MockedResource::the_date; + static std::vector trace2vector(const char* str) { std::vector res; @@ -46,18 +49,18 @@ static std::vector trace2vector(const char simgrid::kernel::profile::Event* insertedIt = trace->schedule(&fes, &daResource); while (fes.next_date() <= 20.0 && fes.next_date() >= 0) { - thedate = fes.next_date(); + MockedResource::the_date = fes.next_date(); double value; simgrid::kernel::resource::Resource* resource; - simgrid::kernel::profile::Event* it = fes.pop_leq(thedate, &value, &resource); + simgrid::kernel::profile::Event* it = fes.pop_leq(MockedResource::the_date, &value, &resource); if (it == nullptr) continue; REQUIRE(it == insertedIt); // Check that we find what we've put if (value >= 0) { - res.emplace_back(thedate, value); + res.emplace_back(MockedResource::the_date, value); } else { - XBT_DEBUG("%.1f: ignore an event (idx: %u)\n", thedate, it->idx); + XBT_DEBUG("%.1f: ignore an event (idx: %u)\n", MockedResource::the_date, it->idx); } resource->apply_event(it, value); } @@ -154,19 +157,21 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker SECTION("One stochastic event (parsing)") { + using simgrid::kernel::profile::Distribution; std::vector got = trace2selist("STOCHASTIC\n" "DET 0 UNIF 10 20"); std::vector want; want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); // The initial fake event - want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0}, - simgrid::kernel::profile::Dist_Unif, {10, 20})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {0}, + Distribution::UNIF, {10, 20})); REQUIRE(want == got); } SECTION("Several stochastic events (all possible parsing forms)") { + using simgrid::kernel::profile::Distribution; std::vector got = trace2selist("STOCHASTIC\n" "DET 0 DET 4\n" "NORMAL 25 10 DET 3\n" @@ -175,14 +180,14 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker std::vector want; want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); - want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0}, - simgrid::kernel::profile::Dist_Det, {4})); - want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Norm, {25, 10}, - simgrid::kernel::profile::Dist_Det, {3})); - want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Unif, {10, 20}, - simgrid::kernel::profile::Dist_Norm, {25, 10})); - want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {5}, - simgrid::kernel::profile::Dist_Unif, {5, 25})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {0}, + Distribution::DET, {4})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::NORM, {25, 10}, + Distribution::DET, {3})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::UNIF, {10, 20}, + Distribution::NORM, {25, 10})); + want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(Distribution::DET, {5}, + Distribution::UNIF, {5, 25})); REQUIRE(want == got); } diff --git a/src/kernel/resource/profile/StochasticDatedValue.cpp b/src/kernel/resource/profile/StochasticDatedValue.cpp index a9e0d00dea..6830b75bc8 100644 --- a/src/kernel/resource/profile/StochasticDatedValue.cpp +++ b/src/kernel/resource/profile/StochasticDatedValue.cpp @@ -15,17 +15,16 @@ namespace profile { double StochasticDatedValue::draw(Distribution law, std::vector params) { switch (law) { - case Dist_Det: + case Distribution::DET: return params[0]; - case Dist_Exp: + case Distribution::EXP: return simgrid::xbt::random::exponential(params[0]); - case Dist_Unif: + case Distribution::UNIF: return simgrid::xbt::random::uniform_real(params[0], params[1]); - case Dist_Norm: + case Distribution::NORM: return simgrid::xbt::random::normal(params[0], params[1]); default: - xbt_assert(false, "Unimplemented distribution"); - return 0; + xbt_die("Unimplemented distribution"); } } double StochasticDatedValue::get_value() @@ -50,26 +49,6 @@ bool StochasticDatedValue::operator==(StochasticDatedValue const& e2) const (e2.date_params == date_params); } -std::ostream& operator<<(std::ostream& out, const StochasticDatedValue& e) -{ - out << e.date_law << " ("; - for (unsigned int i = 0; i < e.date_params.size(); i++) { - out << e.date_params[i]; - if (i != e.date_params.size() - 1) { - out << ","; - } - } - out << ") " << e.value_law << " ("; - for (unsigned int i = 0; i < e.value_params.size(); i++) { - out << e.value_params[i]; - if (i != e.value_params.size() - 1) { - out << ","; - } - } - out << ")"; - return out; -} - } // namespace profile } // namespace kernel } // namespace simgrid diff --git a/src/kernel/resource/profile/StochasticDatedValue.hpp b/src/kernel/resource/profile/StochasticDatedValue.hpp index 29bc98916f..f4320390cc 100644 --- a/src/kernel/resource/profile/StochasticDatedValue.hpp +++ b/src/kernel/resource/profile/StochasticDatedValue.hpp @@ -14,22 +14,19 @@ namespace simgrid { namespace kernel { namespace profile { -enum Distribution { Dist_Exp, Dist_Norm, Dist_Unif, Dist_Det }; +enum class Distribution { EXP, NORM, UNIF, DET }; class XBT_PUBLIC StochasticDatedValue { public: - Distribution date_law; + Distribution date_law = Distribution::DET; std::vector date_params; - Distribution value_law; + Distribution value_law = Distribution::DET; std::vector value_params; DatedValue get_datedvalue(); double get_date(); double get_value(); explicit StochasticDatedValue() = default; - explicit StochasticDatedValue(double d, double v) - : date_law(Dist_Det), date_params({d}), value_law(Dist_Det), value_params({v}) - { - } + explicit StochasticDatedValue(double d, double v) : date_params({d}), value_params({v}) {} explicit StochasticDatedValue(Distribution dl, const std::vector& dp, Distribution vl, const std::vector& vp) : date_law(dl), date_params(dp), value_law(vl), value_params(vp) @@ -38,11 +35,9 @@ public: bool operator==(StochasticDatedValue const& e2) const; private: - double draw(Distribution law, std::vector params); + static double draw(Distribution law, std::vector params); }; -std::ostream& operator<<(std::ostream& out, const StochasticDatedValue& e); - } // namespace profile } // namespace kernel } // namespace simgrid