From 99fb6f4402d84893c59e00d84b96a6dcc518298c Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 10 May 2018 01:22:08 +0200 Subject: [PATCH 1/1] snake_case (and document) s4u::Exec --- .../s4u/cloud-capping/s4u-cloud-capping.cpp | 2 +- examples/s4u/exec-async/s4u-exec-async.cpp | 2 +- examples/s4u/exec-remote/s4u-exec-remote.cpp | 6 ++-- include/simgrid/s4u/Exec.hpp | 17 ++++++++--- src/s4u/s4u_Exec.cpp | 28 ++++++++++++++++--- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/examples/s4u/cloud-capping/s4u-cloud-capping.cpp b/examples/s4u/cloud-capping/s4u-cloud-capping.cpp index 7d35e58505..8d3872d0d2 100644 --- a/examples/s4u/cloud-capping/s4u-cloud-capping.cpp +++ b/examples/s4u/cloud-capping/s4u-cloud-capping.cpp @@ -18,7 +18,7 @@ static void worker(double computation_amount, bool use_bound, double bound) if (use_bound) { if (bound < 1e-12) /* close enough to 0 without any floating precision surprise */ XBT_INFO("bound == 0 means no capping (i.e., unlimited)."); - exec->setBound(bound); + exec->set_bound(bound); } exec->start(); exec->wait(); diff --git a/examples/s4u/exec-async/s4u-exec-async.cpp b/examples/s4u/exec-async/s4u-exec-async.cpp index a47accebbb..6794d5b25e 100644 --- a/examples/s4u/exec-async/s4u-exec-async.cpp +++ b/examples/s4u/exec-async/s4u-exec-async.cpp @@ -11,7 +11,7 @@ static void test(double computation_amount, double priority) { XBT_INFO("Hello! Execute %g flops with priority %g", computation_amount, priority); simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_init(computation_amount); - activity->setPriority(priority); + activity->set_priority(priority); activity->start(); activity->wait(); diff --git a/examples/s4u/exec-remote/s4u-exec-remote.cpp b/examples/s4u/exec-remote/s4u-exec-remote.cpp index d9c43afd55..8044e17ac7 100644 --- a/examples/s4u/exec-remote/s4u-exec-remote.cpp +++ b/examples/s4u/exec-remote/s4u-exec-remote.cpp @@ -15,7 +15,7 @@ static void wizard() XBT_INFO("I'm a wizard! I can run a task on the Fafard host from the Ginette one! Look!"); simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(48.492e6); - exec->setHost(ginette); + exec->set_host(ginette); exec->start(); XBT_INFO("It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard)."); @@ -27,14 +27,14 @@ static void wizard() XBT_INFO("Done!"); XBT_INFO("And now, harder. Start a remote task on Ginette and move it to Boivin after 0.5 sec"); - exec = simgrid::s4u::this_actor::exec_init(73293500)->setHost(ginette); + exec = simgrid::s4u::this_actor::exec_init(73293500)->set_host(ginette); exec->start(); simgrid::s4u::this_actor::sleep_for(0.5); XBT_INFO("Loads before the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", boivin->getLoad(), fafard->getLoad(), ginette->getLoad()); - exec->setHost(boivin); + exec->set_host(boivin); simgrid::s4u::this_actor::sleep_for(0.1); XBT_INFO("Loads after the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index a023a74dcc..bcf774a784 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -28,14 +28,23 @@ public: Activity* wait(double timeout) override; bool test(); - ExecPtr setPriority(double priority); - ExecPtr setBound(double bound); - ExecPtr setHost(Host * host); - Host* getHost() { return host_; } + ExecPtr set_priority(double priority); + ExecPtr set_bound(double bound); + ExecPtr set_host(Host* host); + Host* get_host(); double get_remaining() override; double getRemainingRatio(); + //////////////// Deprecated functions + XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_priority()") ExecPtr setPriority(double priority) + { + return set_priority(priority); + } + XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_bound()") ExecPtr setBound(double bound) { return set_bound(bound); } + XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_host()") ExecPtr setHost(Host* host) { return set_host(host); } + XBT_ATTRIB_DEPRECATED_v323("Please use Exec::get_host()") Host* getHost() { return get_host(); } + private: Host* host_ = nullptr; double flops_amount_ = 0.0; diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index 03afd33a5c..4c31f6f344 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -15,7 +15,7 @@ namespace s4u { Activity* Exec::start() { - pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0., host_); + pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1. / priority_, 0., host_); boost::static_pointer_cast(pimpl_)->setBound(bound_); state_ = State::started; return this; @@ -34,6 +34,7 @@ Activity* Exec::wait(double timeout) return this; } +/** @brief Returns whether the state of the exec is finished */ bool Exec::test() { xbt_assert(state_ == State::inited || state_ == State::started || state_ == State::finished); @@ -52,21 +53,34 @@ bool Exec::test() return false; } -ExecPtr Exec::setPriority(double priority) +/** @brief Change the execution priority, don't you think? + * + * An execution with twice the priority will get twice the amount of flops when the resource is shared. + * The default priority is 1. + * + * Currently, this cannot be changed once the exec started. */ +ExecPtr Exec::set_priority(double priority) { xbt_assert(state_ == State::inited, "Cannot change the priority of an exec after its start"); priority_ = priority; return this; } -ExecPtr Exec::setBound(double bound) +/** @brief change the execution bound, ie the maximal amount of flops per second that it may consume, regardless of what + * the host may deliver + * + * Currently, this cannot be changed once the exec started. */ +ExecPtr Exec::set_bound(double bound) { xbt_assert(state_ == State::inited, "Cannot change the bound of an exec after its start"); bound_ = bound; return this; } -ExecPtr Exec::setHost(Host* host) +/** @brief Change the host on which this activity takes place. + * + * The activity cannot be terminated already (but it may be started). */ +ExecPtr Exec::set_host(Host* host) { xbt_assert(state_ == State::inited || state_ == State::started, "Cannot change the host of an exec once it's done (state: %d)", (int)state_); @@ -76,6 +90,12 @@ ExecPtr Exec::setHost(Host* host) return this; } +/** @brief Retrieve the host on which this activity takes place. */ +Host* Exec::get_host() +{ + return host_; +} + double Exec::get_remaining() { return simgrid::simix::kernelImmediate( -- 2.20.1