From 249e66b5d20dc77cef37e44f81eb07fc8f8ba293 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 8 Dec 2017 22:54:06 +0100 Subject: [PATCH] implement ExecImpl::remainingRatio and make sure we never call ExecImpl::remaining on seq tasks --- src/kernel/activity/ExecImpl.cpp | 16 +++++++++++++++- src/kernel/activity/ExecImpl.hpp | 1 + src/msg/msg_task.cpp | 7 +------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index afb1832eed..5ecdf6a168 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -43,7 +43,21 @@ void simgrid::kernel::activity::ExecImpl::resume() double simgrid::kernel::activity::ExecImpl::remains() { - return surfAction_->getRemains(); + if (host_ == nullptr) // parallel task: their remain is not in flops (we'd need a vector to express it this way + // instead of a scalar), but between 0 and 1 + throw new std::logic_error( + "The remaining work on parallel tasks cannot be defined as a scalar amount of flops (it's a vector). " + "So parallel_task->remains() is not defined. " + "You are probably looking for parallel_task->remainingRatio()."); + else // sequential task: everything's fine + return surfAction_->getRemains(); +} +double simgrid::kernel::activity::ExecImpl::remainingRatio() +{ + if (host_ == nullptr) // parallel task: their remain is already between 0 and 1 (see comment in ExecImpl::remains()) + return surfAction_->getRemains(); + else // Actually compute the ratio for sequential tasks + return surfAction_->getRemains() / surfAction_->getCost(); } void simgrid::kernel::activity::ExecImpl::post() diff --git a/src/kernel/activity/ExecImpl.hpp b/src/kernel/activity/ExecImpl.hpp index 63e3dcb716..e5fe71bb6e 100644 --- a/src/kernel/activity/ExecImpl.hpp +++ b/src/kernel/activity/ExecImpl.hpp @@ -23,6 +23,7 @@ public: void resume() override; void post() override; double remains(); + double remainingRatio(); /* The host where the execution takes place. If nullptr, then this is a parallel exec (and only surf knows the hosts) */ diff --git a/src/msg/msg_task.cpp b/src/msg/msg_task.cpp index 3b119af69b..e31fb10339 100644 --- a/src/msg/msg_task.cpp +++ b/src/msg/msg_task.cpp @@ -239,12 +239,7 @@ double MSG_task_get_remaining_work_ratio(msg_task_t task) { xbt_assert((task != nullptr), "Cannot get information from a nullptr task"); if (task->simdata->compute) { // Task in progress - return task->simdata->compute->remains(); - - //} else if ((MSG_task_get_flops_amount(task) == 0 and task->simdata->flops_parallel_amount == nullptr) //this is a sequential task - // or (task->simdata->flops_parallel_amount != nullptr and task->simdata->flops_parallel_amount == 0)) { - // // Task finished - // return 1; + return task->simdata->compute->remainingRatio(); } else { // Task not started or finished return 0; -- 2.20.1