From: Martin Quinson Date: Thu, 10 May 2018 09:16:01 +0000 (+0200) Subject: factorize code between SIMIX_execution_start and SIMIX_execution_parallel_start X-Git-Tag: v3.20~247 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/fb475fe04cd3abb4e87e9b89f60f736e2afb496e factorize code between SIMIX_execution_start and SIMIX_execution_parallel_start --- diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index 8bfe3cea16..259d5cbde8 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -15,11 +15,21 @@ 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; + + 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); } diff --git a/src/kernel/activity/ExecImpl.hpp b/src/kernel/activity/ExecImpl.hpp index 023467af3c..6aa17c9ef3 100644 --- a/src/kernel/activity/ExecImpl.hpp +++ b/src/kernel/activity/ExecImpl.hpp @@ -17,7 +17,8 @@ class XBT_PUBLIC ExecImpl : public ActivityImpl { ~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; diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 7425bc3735..82a0566eea 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -138,21 +138,18 @@ void SIMIX_host_autorestart(sg_host_t host) boost::intrusive_ptr 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 */ + simgrid::kernel::resource::Action* surf_action = nullptr; 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) - static_cast(exec->surfAction_)->set_bound(bound); + static_cast(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); @@ -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) { - /* 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(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 */ + 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()) { - /* 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); - 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) { - 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;