Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow an Exec to be unscheduled (reset host list, flops and bytes vector, and start...
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 20 Dec 2021 15:09:33 +0000 (16:09 +0100)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 20 Dec 2021 15:09:33 +0000 (16:09 +0100)
include/simgrid/s4u/Exec.hpp
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/ExecImpl.hpp
src/s4u/s4u_Exec.cpp

index 643d0d4..57fe743 100644 (file)
@@ -41,6 +41,7 @@ protected:
   explicit Exec(kernel::activity::ExecImplPtr pimpl);
 
   void complete(Activity::State state) override;
+  void reset();
 
 public:
 #ifndef DOXYGEN
@@ -74,6 +75,7 @@ public:
   double get_remaining_ratio() const;
   ExecPtr set_host(Host* host);
   ExecPtr set_hosts(const std::vector<Host*>& hosts);
+  ExecPtr unset_host();
 
   ExecPtr set_flops_amount(double flops_amount);
   ExecPtr set_flops_amounts(const std::vector<double>& flops_amounts);
index a7f68d4..84ec670 100644 (file)
@@ -94,7 +94,7 @@ ExecImpl* ExecImpl::start()
 
 double ExecImpl::get_remaining() const
 {
-  if (state_ == State::WAITING)
+  if (state_ == State::WAITING || state_ == State::FAILED)
     return flops_amounts_.front();
   return ActivityImpl::get_remaining();
 }
@@ -160,7 +160,6 @@ void ExecImpl::post()
   timeout_detector_.reset();
   if (actor_) {
     actor_->activities_.remove(this);
-    actor_ = nullptr;
   }
   if (state_ != State::FAILED && cb_id_ >= 0)
     s4u::Host::on_state_change.disconnect(cb_id_);
@@ -235,6 +234,14 @@ void ExecImpl::finish()
   }
 }
 
+void ExecImpl::reset()
+{
+  hosts_.clear();
+  bytes_amounts_.clear();
+  flops_amounts_.clear();
+  start_time_ = -1.0;
+}
+
 ActivityImpl* ExecImpl::migrate(s4u::Host* to)
 {
   if (not MC_is_active() && not MC_record_replay_is_active()) {
index a7e5f57..9ce7ef5 100644 (file)
@@ -65,6 +65,7 @@ public:
   void set_exception(actor::ActorImpl* issuer) override;
   void finish() override;
 
+  void reset();
   static void wait_any_for(actor::ActorImpl* issuer, const std::vector<ExecImpl*>& execs, double timeout);
 
   static xbt::signal<void(ExecImpl const&, s4u::Host*)> on_migration;
index ae4367f..06440b4 100644 (file)
@@ -29,6 +29,10 @@ void Exec::complete(Activity::State state)
   Activity::complete(state);
   on_completion(*this);
 }
+void Exec::reset()
+{
+  boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->reset();
+}
 
 ExecPtr Exec::init()
 {
@@ -208,6 +212,22 @@ ExecPtr Exec::set_hosts(const std::vector<Host*>& hosts)
   return this;
 }
 
+ExecPtr Exec::unset_host()
+{
+  if (not is_assigned())
+    throw std::invalid_argument(
+        xbt::string_printf("Exec %s: the activity is not assigned to any host(s)", get_cname()));
+  else {
+    reset();
+
+    if (state_ == State::STARTED)
+      cancel();
+    vetoable_start();
+
+    return this;
+  }
+}
+
 double Exec::get_cost() const
 {
   return (pimpl_->surf_action_ == nullptr) ? -1 : pimpl_->surf_action_->get_cost();