From 3fa3906dc915820b34bce8bf2c006e980195b2bd Mon Sep 17 00:00:00 2001 From: Fabien Chaix Date: Thu, 19 May 2022 10:12:45 +0300 Subject: [PATCH] Move hosts_ to private, and deal with consequences --- src/kernel/activity/ActivityImpl.cpp | 2 +- src/kernel/activity/ActivityImpl.hpp | 14 ++++++++------ src/kernel/activity/CommImpl.cpp | 4 ++-- src/kernel/activity/ExecImpl.cpp | 24 +++++++++++++----------- src/kernel/activity/ExecImpl.hpp | 4 +--- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/kernel/activity/ActivityImpl.cpp b/src/kernel/activity/ActivityImpl.cpp index c75799ab3f..86cd48a36c 100644 --- a/src/kernel/activity/ActivityImpl.cpp +++ b/src/kernel/activity/ActivityImpl.cpp @@ -59,7 +59,7 @@ const char* ActivityImpl::get_state_str() const { return to_c_str(state_); } - + bool ActivityImpl::test(actor::ActorImpl* issuer) { if (state_ != State::WAITING && state_ != State::RUNNING) { diff --git a/src/kernel/activity/ActivityImpl.hpp b/src/kernel/activity/ActivityImpl.hpp index a5feea5a0a..ff05528c66 100644 --- a/src/kernel/activity/ActivityImpl.hpp +++ b/src/kernel/activity/ActivityImpl.hpp @@ -29,6 +29,7 @@ class XBT_PUBLIC ActivityImpl { State state_ = State::WAITING; /* State of the activity */ double start_time_ = -1.0; double finish_time_ = -1.0; + std::vector hosts_; public: virtual ~ActivityImpl(); @@ -38,10 +39,6 @@ public: resource::Action* surf_action_ = nullptr; protected: - - std::vector hosts_; - - void inline set_name(std::string_view name) { // This is to keep name_ private while allowing ActivityImpl_T to set it and then return a Ptr to qualified @@ -49,8 +46,12 @@ protected: name_ = name; } void set_start_time(double start_time) { start_time_ = start_time; } - + void clear_hosts() { hosts_.clear(); } + void add_host(s4u::Host* host) { hosts_.push_back(host); } + void set_hosts(const std::vector& hosts) { hosts_=hosts; } + public: + const std::string& get_name() const { return name_; } const char* get_cname() const { return name_.c_str(); } @@ -85,7 +86,8 @@ public: virtual void finish() = 0; // Unlock all simcalls blocked on that activity, either because it was marked as done by // the model or because it terminated without waiting for the model - virtual const std::vector& get_hosts() const { return hosts_;} ; + s4u::Host* get_host() const { return hosts_.front(); } + const std::vector& get_hosts() const { return hosts_;} ; void register_simcall(actor::Simcall* simcall); void unregister_simcall(actor::Simcall* simcall); diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index 87e8c5eeea..e0272554cc 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -64,7 +64,7 @@ CommImpl& CommImpl::set_source(s4u::Host* from) { xbt_assert( from_ == nullptr ); from_ = from; - hosts_.push_back(from); + add_host(from); return *this; } @@ -72,7 +72,7 @@ CommImpl& CommImpl::set_destination(s4u::Host* to) { xbt_assert( to_ == nullptr ); to_ = to; - hosts_.push_back(to_); + add_host(to_); return *this; } diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index 4b2ad5c7e4..fdaf2dcc04 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -31,20 +31,21 @@ ExecImpl::ExecImpl() ExecImpl& ExecImpl::set_host(s4u::Host* host) { - hosts_.assign(1, host); + clear_hosts(); + add_host(host); return *this; } ExecImpl& ExecImpl::set_hosts(const std::vector& hosts) { - hosts_ = hosts; + ActivityImpl::set_hosts(hosts); return *this; } ExecImpl& ExecImpl::set_timeout(double timeout) { if (timeout >= 0 && not MC_is_active() && not MC_record_replay_is_active()) { - timeout_detector_.reset(hosts_.front()->get_cpu()->sleep(timeout)); + timeout_detector_.reset(get_host()->get_cpu()->sleep(timeout)); timeout_detector_->set_activity(this); } return *this; @@ -79,19 +80,19 @@ ExecImpl* ExecImpl::start() { set_state(State::RUNNING); if (not MC_is_active() && not MC_record_replay_is_active()) { - if (hosts_.size() == 1) { + if (get_hosts().size() == 1) { if (thread_count_ == 1) { - surf_action_ = hosts_.front()->get_cpu()->execution_start(flops_amounts_.front(), bound_); + surf_action_ = get_host()->get_cpu()->execution_start(flops_amounts_.front(), bound_); surf_action_->set_sharing_penalty(sharing_penalty_); } else { - auto host_model = hosts_.front()->get_netpoint()->get_englobing_zone()->get_host_model(); - surf_action_ = host_model->execute_thread(hosts_.front(), flops_amounts_.front(), thread_count_); + auto host_model = get_host()->get_netpoint()->get_englobing_zone()->get_host_model(); + surf_action_ = host_model->execute_thread(get_host(), flops_amounts_.front(), thread_count_); } surf_action_->set_category(get_tracing_category()); } else { // get the model from first host since we have only 1 by now - auto host_model = hosts_.front()->get_netpoint()->get_englobing_zone()->get_host_model(); - surf_action_ = host_model->execute_parallel(hosts_, flops_amounts_.data(), bytes_amounts_.data(), -1); + auto host_model = get_host()->get_netpoint()->get_englobing_zone()->get_host_model(); + surf_action_ = host_model->execute_parallel(get_hosts(), flops_amounts_.data(), bytes_amounts_.data(), -1); } surf_action_->set_activity(this); set_start_time(surf_action_->get_start_time()); @@ -145,7 +146,8 @@ ExecImpl& ExecImpl::update_sharing_penalty(double sharing_penalty) void ExecImpl::post() { xbt_assert(surf_action_ != nullptr); - if (std::any_of(hosts_.begin(), hosts_.end(), [](const s4u::Host* host) { return not host->is_on(); })) { + auto hosts=get_hosts(); + if (std::any_of(hosts.begin(), hosts.end(), [](const s4u::Host* host) { return not host->is_on(); })) { /* If one of the hosts running the synchro failed, notice it. This way, the asking * process can be killed if it runs on that host itself */ set_state(State::FAILED); @@ -223,7 +225,7 @@ void ExecImpl::finish() void ExecImpl::reset() { - hosts_.clear(); + clear_hosts(); bytes_amounts_.clear(); flops_amounts_.clear(); set_start_time(-1.0); diff --git a/src/kernel/activity/ExecImpl.hpp b/src/kernel/activity/ExecImpl.hpp index a6c691b423..22dfb5c00f 100644 --- a/src/kernel/activity/ExecImpl.hpp +++ b/src/kernel/activity/ExecImpl.hpp @@ -35,15 +35,13 @@ public: ExecImpl& set_flops_amount(double flop_amount); ExecImpl& set_host(s4u::Host* host); - s4u::Host* get_host() const { return hosts_.front(); } - const std::vector& get_hosts() const { return hosts_; } ExecImpl& set_flops_amounts(const std::vector& flops_amounts); ExecImpl& set_bytes_amounts(const std::vector& bytes_amounts); ExecImpl& set_thread_count(int thread_count); ExecImpl& set_hosts(const std::vector& hosts); - unsigned int get_host_number() const { return static_cast(hosts_.size()); } + unsigned int get_host_number() const { return static_cast(get_hosts().size()); } double get_seq_remaining_ratio(); double get_par_remaining_ratio(); double get_remaining() const override; -- 2.20.1