Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
factorize code between SIMIX_execution_start and SIMIX_execution_parallel_start
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 10 May 2018 09:16:01 +0000 (11:16 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 11 May 2018 20:06:05 +0000 (22:06 +0200)
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/ExecImpl.hpp
src/simix/smx_host.cpp

index 8bfe3ce..259d5cb 100644 (file)
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
 
-simgrid::kernel::activity::ExecImpl::ExecImpl(const char* name, sg_host_t host) : host_(host)
+simgrid::kernel::activity::ExecImpl::ExecImpl(const char* name, resource::Action* surf_action,
+                                              resource::Action* timeout_detector, s4u::Host* host)
+    : host_(host)
 {
   if (name)
     this->name = name;
   this->state  = SIMIX_RUNNING;
 {
   if (name)
     this->name = name;
   this->state  = SIMIX_RUNNING;
+
+  surfAction_ = surf_action;
+  surfAction_->set_data(this);
+  if (timeout_detector != nullptr) {
+    timeout_detector->set_data(this);
+    timeoutDetector = timeout_detector;
+  }
+
   XBT_DEBUG("Create exec %p", this);
 }
 
   XBT_DEBUG("Create exec %p", this);
 }
 
index 023467a..6aa17c9 100644 (file)
@@ -17,7 +17,8 @@ class XBT_PUBLIC ExecImpl : public ActivityImpl {
   ~ExecImpl() override;
 
 public:
   ~ExecImpl() override;
 
 public:
-  explicit ExecImpl(const char* name, sg_host_t host);
+  explicit ExecImpl(const char* name, resource::Action* surf_action, resource::Action* timeout_detector,
+                    s4u::Host* host);
   void suspend() override;
   void resume() override;
   void post() override;
   void suspend() override;
   void resume() override;
   void post() override;
index 7425bc3..82a0566 100644 (file)
@@ -138,21 +138,18 @@ void SIMIX_host_autorestart(sg_host_t host)
 boost::intrusive_ptr<simgrid::kernel::activity::ExecImpl>
 SIMIX_execution_start(const char* name, double flops_amount, double priority, double bound, sg_host_t host)
 {
 boost::intrusive_ptr<simgrid::kernel::activity::ExecImpl>
 SIMIX_execution_start(const char* name, double flops_amount, double priority, double bound, sg_host_t host)
 {
-  /* alloc structures and initialize */
-  simgrid::kernel::activity::ExecImplPtr exec =
-      simgrid::kernel::activity::ExecImplPtr(new simgrid::kernel::activity::ExecImpl(name, host));
-
   /* set surf's action */
   /* set surf's action */
+  simgrid::kernel::resource::Action* surf_action      = nullptr;
   if (not MC_is_active() && not MC_record_replay_is_active()) {
   if (not MC_is_active() && not MC_record_replay_is_active()) {
-
-    exec->surfAction_ = host->pimpl_cpu->execution_start(flops_amount);
-    exec->surfAction_->set_data(exec.get());
-    exec->surfAction_->set_priority(priority);
-
+    surf_action = host->pimpl_cpu->execution_start(flops_amount);
+    surf_action->set_priority(priority);
     if (bound > 0)
     if (bound > 0)
-      static_cast<simgrid::surf::CpuAction*>(exec->surfAction_)->set_bound(bound);
+      static_cast<simgrid::surf::CpuAction*>(surf_action)->set_bound(bound);
   }
 
   }
 
+  simgrid::kernel::activity::ExecImplPtr exec = simgrid::kernel::activity::ExecImplPtr(
+      new simgrid::kernel::activity::ExecImpl(name, surf_action, /*timeout_detector*/ nullptr, host));
+
   XBT_DEBUG("Create execute synchro %p: %s", exec.get(), exec->name.c_str());
   simgrid::kernel::activity::ExecImpl::onCreation(exec);
 
   XBT_DEBUG("Create execute synchro %p: %s", exec.get(), exec->name.c_str());
   simgrid::kernel::activity::ExecImpl::onCreation(exec);
 
@@ -164,10 +161,6 @@ SIMIX_execution_parallel_start(const char* name, int host_nb, sg_host_t* host_li
                                double* bytes_amount, double rate, double timeout)
 {
 
                                double* bytes_amount, double rate, double timeout)
 {
 
-  /* alloc structures and initialize */
-  simgrid::kernel::activity::ExecImplPtr exec =
-      simgrid::kernel::activity::ExecImplPtr(new simgrid::kernel::activity::ExecImpl(name, nullptr));
-
   /* Check that we are not mixing VMs and PMs in the parallel task */
   bool is_a_vm = (nullptr != dynamic_cast<simgrid::s4u::VirtualMachine*>(host_list[0]));
   for (int i = 1; i < host_nb; i++) {
   /* Check that we are not mixing VMs and PMs in the parallel task */
   bool is_a_vm = (nullptr != dynamic_cast<simgrid::s4u::VirtualMachine*>(host_list[0]));
   for (int i = 1; i < host_nb; i++) {
@@ -176,17 +169,20 @@ SIMIX_execution_parallel_start(const char* name, int host_nb, sg_host_t* host_li
   }
 
   /* set surf's synchro */
   }
 
   /* set surf's synchro */
+  simgrid::kernel::resource::Action* surf_action      = nullptr;
+  simgrid::kernel::resource::Action* timeout_detector = nullptr;
   if (not MC_is_active() && not MC_record_replay_is_active()) {
   if (not MC_is_active() && not MC_record_replay_is_active()) {
-    /* set surf's synchro */
     sg_host_t* host_list_cpy = new sg_host_t[host_nb];
     std::copy_n(host_list, host_nb, host_list_cpy);
     sg_host_t* host_list_cpy = new sg_host_t[host_nb];
     std::copy_n(host_list, host_nb, host_list_cpy);
-    exec->surfAction_ = surf_host_model->execute_parallel(host_nb, host_list_cpy, flops_amount, bytes_amount, rate);
-    exec->surfAction_->set_data(exec.get());
+    surf_action = surf_host_model->execute_parallel(host_nb, host_list_cpy, flops_amount, bytes_amount, rate);
     if (timeout > 0) {
     if (timeout > 0) {
-      exec->timeoutDetector = host_list[0]->pimpl_cpu->sleep(timeout);
-      exec->timeoutDetector->set_data(exec.get());
+      timeout_detector = host_list[0]->pimpl_cpu->sleep(timeout);
     }
   }
     }
   }
+
+  simgrid::kernel::activity::ExecImplPtr exec = simgrid::kernel::activity::ExecImplPtr(
+      new simgrid::kernel::activity::ExecImpl(name, surf_action, timeout_detector, nullptr));
+
   XBT_DEBUG("Create parallel execute synchro %p", exec.get());
 
   return exec;
   XBT_DEBUG("Create parallel execute synchro %p", exec.get());
 
   return exec;