From 15526efcd11f428984f5ac74f1937e4bab98fa56 Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Mon, 2 Oct 2023 16:10:45 -1000 Subject: [PATCH] removed some simgrid::Host * --- include/wrench/services/Service.h | 2 + .../bare_metal/BareMetalComputeService.h | 7 ++ .../ActionExecutionService.h | 12 +-- .../HostStateChangeDetector.h | 8 +- include/wrench/simgrid_S4U_util/S4U_Daemon.h | 5 ++ .../wrench/simgrid_S4U_util/S4U_Simulation.h | 3 +- src/wrench/action/MPIAction.cpp | 20 ++--- src/wrench/services/Service.cpp | 8 ++ .../bare_metal/BareMetalComputeService.cpp | 41 +++++++++- .../ActionExecutionService.cpp | 76 +++++++++---------- .../HostStateChangeDetector.cpp | 20 +++-- src/wrench/simgrid_S4U_util/S4U_Daemon.cpp | 1 + .../simgrid_S4U_util/S4U_Simulation.cpp | 18 ++--- .../helper_services/HostStateChangeTest.cpp | 4 +- 14 files changed, 142 insertions(+), 83 deletions(-) diff --git a/include/wrench/services/Service.h b/include/wrench/services/Service.h index 52382af496..eea8b94e9c 100755 --- a/include/wrench/services/Service.h +++ b/include/wrench/services/Service.h @@ -77,6 +77,8 @@ namespace wrench { /** \cond INTERNAL */ /***********************/ + simgrid::s4u::Host *getHost(); + double getMessagePayloadValue(WRENCH_MESSAGEPAYLOAD_TYPE); const WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE &getMessagePayloadList() const; diff --git a/include/wrench/services/compute/bare_metal/BareMetalComputeService.h b/include/wrench/services/compute/bare_metal/BareMetalComputeService.h index c3500fdc10..c512d2a00f 100755 --- a/include/wrench/services/compute/bare_metal/BareMetalComputeService.h +++ b/include/wrench/services/compute/bare_metal/BareMetalComputeService.h @@ -132,6 +132,13 @@ namespace wrench { std::shared_ptr pj, const std::string &suffix, std::shared_ptr scratch_space);// reference to upper level scratch space + BareMetalComputeService(const std::string &hostname, + std::map> compute_resources, + WRENCH_PROPERTY_COLLECTION_TYPE property_list, + WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE messagepayload_list, + std::shared_ptr pj, const std::string &suffix, + std::shared_ptr scratch_space);// reference to upper level scratch space + BareMetalComputeService(const std::string &hostname, const std::map> &compute_resources, WRENCH_PROPERTY_COLLECTION_TYPE property_list, diff --git a/include/wrench/services/helper_services/action_execution_service/ActionExecutionService.h b/include/wrench/services/helper_services/action_execution_service/ActionExecutionService.h index 477e49ad5b..bd06353463 100755 --- a/include/wrench/services/helper_services/action_execution_service/ActionExecutionService.h +++ b/include/wrench/services/helper_services/action_execution_service/ActionExecutionService.h @@ -76,7 +76,7 @@ namespace wrench { bool IsThereAtLeastOneHostWithAvailableResources(unsigned long num_cores, double ram); - std::map> &getComputeResources(); + std::map> &getComputeResources(); std::map getResourceInformation(const std::string &key); @@ -92,11 +92,11 @@ namespace wrench { void validateProperties(); - std::map> compute_resources; + std::map> compute_resources; // Core availabilities (for each hosts, how many cores and how many bytes of RAM are currently available on it) - std::unordered_map ram_availabilities; - std::unordered_map running_thread_counts; + std::unordered_map ram_availabilities; + std::unordered_map running_thread_counts; std::shared_ptr parent_service = nullptr; @@ -154,9 +154,9 @@ namespace wrench { void processSubmitAction(simgrid::s4u::Mailbox *answer_mailbox, const std::shared_ptr &action); - std::tuple pickAllocation(const std::shared_ptr &action, + std::tuple pickAllocation(const std::shared_ptr &action, const std::string &required_host, unsigned long required_num_cores, - std::set &hosts_to_avoid); + std::set &hosts_to_avoid); bool isThereAtLeastOneHostWithResources(unsigned long num_cores, double ram); diff --git a/include/wrench/services/helper_services/host_state_change_detector/HostStateChangeDetector.h b/include/wrench/services/helper_services/host_state_change_detector/HostStateChangeDetector.h index 056b7593d9..f7cc7ee0f3 100755 --- a/include/wrench/services/helper_services/host_state_change_detector/HostStateChangeDetector.h +++ b/include/wrench/services/helper_services/host_state_change_detector/HostStateChangeDetector.h @@ -31,7 +31,7 @@ namespace wrench { public: explicit HostStateChangeDetector(std::string host_on_which_to_run, - std::vector hosts_to_monitor, + std::vector hosts_to_monitor, bool notify_when_turned_on, bool notify_when_turned_off, bool notify_when_speed_change, @@ -44,10 +44,10 @@ namespace wrench { private: void cleanup(bool has_terminated_cleanly, int return_value) override; - void hostStateChangeCallback(std::string const &hostname); - void hostSpeedChangeCallback(std::string const &hostname); + void hostStateChangeCallback(const simgrid::s4u::Host *host); + void hostSpeedChangeCallback(const simgrid::s4u::Host *host); - std::vector hosts_to_monitor; + std::vector hosts_to_monitor; bool notify_when_turned_on; bool notify_when_turned_off; bool notify_when_speed_change; diff --git a/include/wrench/simgrid_S4U_util/S4U_Daemon.h b/include/wrench/simgrid_S4U_util/S4U_Daemon.h index e8ce321fa1..1cdc3acc4c 100755 --- a/include/wrench/simgrid_S4U_util/S4U_Daemon.h +++ b/include/wrench/simgrid_S4U_util/S4U_Daemon.h @@ -137,6 +137,9 @@ namespace wrench { /** @brief The number of time that this daemon has started (i.e., 1 + number of restarts) */ unsigned int num_starts = 0; + /** @brief The host on which this daemon is running */ + simgrid::s4u::Host *host; + private: // Lock used typically to prevent kill() from killing the actor // while it's in the middle of doing something critical @@ -149,6 +152,8 @@ namespace wrench { bool daemonized{}; // Set to true if daemon is daemonized bool auto_restart{}; // Set to true if daemon is supposed to auto-restart + + static int num_non_daemonized_actors_running; diff --git a/include/wrench/simgrid_S4U_util/S4U_Simulation.h b/include/wrench/simgrid_S4U_util/S4U_Simulation.h index 2e54fe40d4..9a02d546e8 100755 --- a/include/wrench/simgrid_S4U_util/S4U_Simulation.h +++ b/include/wrench/simgrid_S4U_util/S4U_Simulation.h @@ -110,10 +110,11 @@ namespace wrench { static simgrid::s4u::Host *get_host_or_vm_by_name_or_null(const std::string &name); static simgrid::s4u::Host *get_host_or_vm_by_name(const std::string &name); + static double getHostMemoryCapacity(simgrid::s4u::Host *host); + private: static void traverseAllNetZonesRecursive(simgrid::s4u::NetZone *nz, std::map> &result, bool get_subzones, bool get_clusters, bool get_hosts_from_zones, bool get_hosts_from_clusters); - static double getHostMemoryCapacity(simgrid::s4u::Host *host); simgrid::s4u::Engine *engine; bool initialized = false; bool platform_setup = false; diff --git a/src/wrench/action/MPIAction.cpp b/src/wrench/action/MPIAction.cpp index 358a1ff18b..f1ee0d4882 100644 --- a/src/wrench/action/MPIAction.cpp +++ b/src/wrench/action/MPIAction.cpp @@ -42,23 +42,23 @@ namespace wrench { // Make A COPY of the list of usable hosts auto resources_ref = action_executor->getActionExecutionService()->getComputeResources(); - std::map> resources(resources_ref.begin(), resources_ref.end()); - std::vector hostnames; - hostnames.reserve(resources.size()); + std::map> resources(resources_ref.begin(), resources_ref.end()); + std::vector all_hosts; + all_hosts.reserve(resources.size()); for (auto const &h: resources) { - hostnames.push_back(h.first); + all_hosts.push_back(h.first); } // Determine the host list (using worst fit) - std::vector hosts; + std::vector hosts; while (hosts.size() != this->num_processes) { bool added_at_least_one_host = false; - for (auto const &hostname: hostnames) { - auto num_cores = std::get<0>(resources[hostname]); + for (auto const &host: all_hosts) { + auto num_cores = std::get<0>(resources[host]); // std::cerr << hostname << ": " << num_cores << "\n"; if (num_cores >= this->num_cores_per_process) { - hosts.push_back(hostname); - resources[hostname] = std::make_tuple(std::get<0>(resources[hostname]) - this->num_cores_per_process, std::get<1>(resources[hostname])); + hosts.push_back(host); + resources[host] = std::make_tuple(std::get<0>(resources[host]) - this->num_cores_per_process, std::get<1>(resources[host])); added_at_least_one_host = true; if (hosts.size() == this->num_processes) { break; @@ -74,7 +74,7 @@ namespace wrench { std::vector simgrid_hosts; simgrid_hosts.reserve(hosts.size()); for (auto const &host: hosts) { - simgrid_hosts.push_back(S4U_Simulation::get_host_or_vm_by_name(host)); + simgrid_hosts.push_back(host); } // Do the SMPI thing!!! diff --git a/src/wrench/services/Service.cpp b/src/wrench/services/Service.cpp index 895f7f2e9d..73fdabbc45 100755 --- a/src/wrench/services/Service.cpp +++ b/src/wrench/services/Service.cpp @@ -374,6 +374,14 @@ namespace wrench { return this->hostname; } + /** + * @brief Get the host on which the service is / will be running + * @return the hostname + */ + simgrid::s4u::Host *Service::getHost() { + return this->host; + } + /** * @brief Get the physical name of the host on which the service is / will be running * @return the physical hostname diff --git a/src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp b/src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp index 55c6ba9989..0157054b2b 100755 --- a/src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp +++ b/src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp @@ -130,10 +130,10 @@ namespace wrench { parsed_spec = BareMetalComputeService::parseResourceSpec(service_specific_args.at(action->getName())); - std::string target_host = std::get<0>(parsed_spec); + auto target_host = S4U_Simulation::get_host_or_vm_by_name_or_null(std::get<0>(parsed_spec)); unsigned long target_num_cores = std::get<1>(parsed_spec); - if (not target_host.empty()) { + if (target_host != nullptr) { if (compute_resources.find(target_host) == compute_resources.end()) { throw std::invalid_argument( "BareMetalComputeService::validateServiceSpecificArguments(): Invalid service-specific argument '" + @@ -297,6 +297,43 @@ namespace wrench { std::move(pj)); } + /** + * @brief Internal constructor + * + * @param hostname: the name of the host on which the service should be started + * @param compute_resources: a list of tuples, which represent + * the compute resources available to this service + * @param property_list: a property list ({} means "use all defaults") + * @param messagepayload_list: a message payload list ({} means "use all defaults") + * @param pj: a containing PilotJob (nullptr if none) + * @param suffix: a string to append to the process name + * @param scratch_space: the scratch storage service + * + * @throw std::invalid_argument + */ + BareMetalComputeService::BareMetalComputeService( + const std::string &hostname, + std::map> compute_resources, + WRENCH_PROPERTY_COLLECTION_TYPE property_list, + WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE messagepayload_list, + std::shared_ptr pj, + const std::string &suffix, std::shared_ptr scratch_space) : ComputeService(hostname, + "bare_metal" + suffix, + std::move(scratch_space)) { + + std::map> compute_resources_string; + for (const auto &h : compute_resources) { + compute_resources_string[h.first->get_name()] = compute_resources[h.first]; + } + + initiateInstance(hostname, + compute_resources_string, + std::move(property_list), + std::move(messagepayload_list), + std::move(pj)); + } + + /** * @brief Internal constructor * diff --git a/src/wrench/services/helper_services/action_execution_service/ActionExecutionService.cpp b/src/wrench/services/helper_services/action_execution_service/ActionExecutionService.cpp index e37ca8432e..023701c328 100755 --- a/src/wrench/services/helper_services/action_execution_service/ActionExecutionService.cpp +++ b/src/wrench/services/helper_services/action_execution_service/ActionExecutionService.cpp @@ -248,7 +248,7 @@ namespace wrench { std::to_string(requested_ram) + " are requested"); } - this->compute_resources[hname] = std::make_tuple(requested_cores, requested_ram); + this->compute_resources[S4U_Simulation::get_host_or_vm_by_name_or_null(hname)] = std::make_tuple(requested_cores, requested_ram); } @@ -283,7 +283,7 @@ namespace wrench { auto host = cr.first; auto num_cores = std::get<0>(cr.second); auto ram = std::get<1>(cr.second); - msg += " - " + host + ": " + std::to_string(num_cores) + " cores; " + std::to_string(ram / 1000000000) + + msg += " - " + host->get_name() + ": " + std::to_string(num_cores) + " cores; " + std::to_string(ram / 1000000000) + " GB of RAM\n"; } WRENCH_INFO("%s", msg.c_str()); @@ -291,7 +291,7 @@ namespace wrench { // Create and start the host state monitor if necessary if (Simulation::isEnergySimulationEnabled() or Simulation::isHostShutdownSimulationEnabled()) { // Create the host state monitor - std::vector hosts_to_monitor; + std::vector hosts_to_monitor; for (auto const &h: this->compute_resources) { hosts_to_monitor.push_back(h.first); } @@ -329,30 +329,30 @@ namespace wrench { * @param hosts_to_avoid: a list of hosts to not even consider * @return an allocation */ - std::tuple ActionExecutionService::pickAllocation( + std::tuple ActionExecutionService::pickAllocation( const std::shared_ptr &action, const std::string &required_host, unsigned long required_num_cores, - std::set &hosts_to_avoid) { + std::set &hosts_to_avoid) { // Compute possible hosts - std::set possible_hosts; - std::string new_host_to_avoid; + std::set possible_hosts; + simgrid::s4u::Host *new_host_to_avoid = nullptr; double new_host_to_avoid_ram_capacity = 0; for (auto const &r: this->compute_resources) { // If there is a required host, then don't even look at others - if (not required_host.empty() and (r.first != required_host)) { + if (not required_host.empty() and (r.first->get_name() != required_host)) { continue; } // If the host is down, then don't look at it - if (not Simulation::isHostOn(r.first)) { + if (not r.first->is_on()) { continue; } // If the host has compute speed zero, then don't look at it - if (Simulation::getHostFlopRate(r.first) <= 0.0) { + if (r.first->get_speed() <= 0.0) { continue; } @@ -371,7 +371,7 @@ namespace wrench { continue; } if (this->ram_availabilities[r.first] < action->getMinRAMFootprint()) { - if (new_host_to_avoid.empty()) { + if (new_host_to_avoid == nullptr) { new_host_to_avoid = r.first; new_host_to_avoid_ram_capacity = this->ram_availabilities[r.first]; } else { @@ -390,20 +390,20 @@ namespace wrench { // If none, then reply with an empty tuple if (possible_hosts.empty()) { // Host to avoid is the one with the lowest ram availability - if (not new_host_to_avoid.empty()) { + if (new_host_to_avoid != nullptr) { hosts_to_avoid.insert(new_host_to_avoid); } - return std::make_tuple(std::string(), 0); + return std::make_tuple(nullptr, 0); } // Select the "best" host double lowest_load = DBL_MAX; - std::string picked_host; + simgrid::s4u::Host *picked_host; unsigned long picked_num_cores = 0; for (auto const &h: possible_hosts) { unsigned long num_running_threads = this->running_thread_counts[h]; unsigned long num_cores = std::get<0>(this->compute_resources[h]); - double flop_rate = S4U_Simulation::getHostFlopRate(h); + double flop_rate = h->get_speed(); unsigned long used_num_cores; if (required_num_cores == 0) { used_num_cores = std::min(num_cores, action->getMaxNumCores());// as many cores as possible @@ -435,15 +435,15 @@ namespace wrench { // Due to a previously considered actions not being // able to run on that host due to RAM, and because we don't // allow non-zero-ram tasks to jump ahead of other tasks - std::set no_longer_considered_hosts; + std::set no_longer_considered_hosts; for (auto const &action: this->ready_actions) { std::string picked_host; - std::string target_host; + simgrid::s4u::Host *target_host = nullptr; unsigned long target_num_cores; double required_ram; - std::tuple allocation = + auto allocation = pickAllocation(action, std::get<0>(this->action_run_specs[action]), std::get<1>(this->action_run_specs[action]), @@ -454,7 +454,7 @@ namespace wrench { // If we didn't find a host, forget it - if (target_host.empty()) { + if (target_host == nullptr) { continue; } // WRENCH_INFO("ALLOC %s: %s %ld %lf", action->getName().c_str(), target_host.c_str(), target_num_cores, required_ram); @@ -462,7 +462,7 @@ namespace wrench { /** Dispatch it **/ // Create an action executor on the target host auto action_executor = std::shared_ptr( - new ActionExecutor(target_host, + new ActionExecutor(target_host->get_name(), target_num_cores, required_ram, this->getPropertyValueAsTimeInSecond(ActionExecutionServiceProperty::THREAD_CREATION_OVERHEAD), @@ -641,8 +641,8 @@ namespace wrench { // If action is running kill the executor if (this->action_executors.find(action) != this->action_executors.end()) { auto executor = this->action_executors[action]; - this->ram_availabilities[executor->getHostname()] += executor->getMemoryAllocated(); - this->running_thread_counts[executor->getHostname()] -= executor->getNumCoresAllocated(); + this->ram_availabilities[executor->getHost()] += executor->getMemoryAllocated(); + this->running_thread_counts[executor->getHost()] -= executor->getNumCoresAllocated(); executor->kill(killed_due_to_job_cancellation); executor->getAction()->setFailureCause(cause); @@ -744,12 +744,12 @@ namespace wrench { void ActionExecutionService::processActionExecutorCompletion( const std::shared_ptr &executor) { - auto executor_hostname = executor->getHostname(); + auto executor_host = executor->getHost(); auto action = executor->getAction(); // Update RAM availabilities and running thread counts - this->ram_availabilities[executor_hostname] += executor->getMemoryAllocated(); - this->running_thread_counts[executor_hostname] -= executor->getNumCoresAllocated(); + this->ram_availabilities[executor_host] += executor->getMemoryAllocated(); + this->running_thread_counts[executor_host] -= executor->getNumCoresAllocated(); // Forget the action executor this->action_executors.erase(action); @@ -771,8 +771,8 @@ namespace wrench { auto cause = action->getFailureCause(); // Update RAM availabilities and running thread counts - this->ram_availabilities[executor->getHostname()] += executor->getMemoryAllocated(); - this->running_thread_counts[executor->getHostname()] -= executor->getNumCoresAllocated(); + this->ram_availabilities[executor->getHost()] += executor->getMemoryAllocated(); + this->running_thread_counts[executor->getHost()] -= executor->getNumCoresAllocated(); // Forget the action executor this->action_executors.erase(action); @@ -873,10 +873,10 @@ namespace wrench { // Parse the service-specific argument std::tuple parsed_spec = parseResourceSpec( service_specific_arguments[action->getName()]); - std::string desired_host = std::get<0>(parsed_spec); + auto desired_host = S4U_Simulation::get_host_or_vm_by_name_or_null(std::get<0>(parsed_spec)); unsigned long desired_num_cores = std::get<1>(parsed_spec); - if (desired_host.empty()) { + if (desired_host == nullptr) { // At this point the desired num cores in non-zero if (not isThereAtLeastOneHostWithResources(desired_num_cores, action->getMinRAMFootprint())) { return false; @@ -1009,7 +1009,7 @@ namespace wrench { // Num cores per hosts std::map num_cores; for (auto r: this->compute_resources) { - num_cores.insert(std::make_pair(r.first, (double) (std::get<0>(r.second)))); + num_cores.insert(std::make_pair(r.first->get_name(), (double) (std::get<0>(r.second)))); } return num_cores; @@ -1020,7 +1020,7 @@ namespace wrench { unsigned long cores = std::get<0>(this->compute_resources[r.first]); unsigned long running_threads = r.second; num_idle_cores.insert( - std::make_pair(r.first, (double) (std::max(cores - running_threads, 0)))); + std::make_pair(r.first->get_name(), (double) (std::max(cores - running_threads, 0)))); } return num_idle_cores; @@ -1028,7 +1028,7 @@ namespace wrench { // Flop rate per host std::map flop_rates; for (auto h: this->compute_resources) { - flop_rates.insert(std::make_pair(h.first, S4U_Simulation::getHostFlopRate(std::get<0>(h)))); + flop_rates.insert(std::make_pair(h.first->get_name(), h.first->get_speed())); } return flop_rates; @@ -1036,7 +1036,7 @@ namespace wrench { // RAM capacity per host std::map ram_capacities; for (auto h: this->compute_resources) { - ram_capacities.insert(std::make_pair(h.first, S4U_Simulation::getHostMemoryCapacity(std::get<0>(h)))); + ram_capacities.insert(std::make_pair(h.first->get_name(), S4U_Simulation::getHostMemoryCapacity(std::get<0>(h)))); } return ram_capacities; @@ -1044,7 +1044,7 @@ namespace wrench { // RAM availability per host std::map ram_availabilities_to_return; for (auto const &r: this->ram_availabilities) { - ram_availabilities_to_return.insert(std::make_pair(r.first, r.second)); + ram_availabilities_to_return.insert(std::make_pair(r.first->get_name(), r.second)); } return ram_availabilities_to_return; @@ -1079,8 +1079,8 @@ namespace wrench { WRENCH_INFO("Handling an ActionExecutor crash!"); // Update RAM availabilities and running thread counts - this->ram_availabilities[executor->getHostname()] += executor->getMemoryAllocated(); - this->running_thread_counts[executor->getHostname()] -= executor->getNumCoresAllocated(); + this->ram_availabilities[executor->getHost()] += executor->getMemoryAllocated(); + this->running_thread_counts[executor->getHost()] -= executor->getNumCoresAllocated(); // Forget the executor this->action_executors.erase(action); @@ -1113,7 +1113,7 @@ namespace wrench { bool ActionExecutionService::areAllComputeResourcesDownWithNoActionExecutorRunning() { bool all_resources_down = true; for (auto const &h: this->compute_resources) { - if (Simulation::isHostOn(h.first)) { + if (h.first->is_on()) { all_resources_down = false; break; } @@ -1134,7 +1134,7 @@ namespace wrench { * @brief Get a (reference to) the compute resources of this service * @return the compute resources */ - std::map> &ActionExecutionService::getComputeResources() { + std::map> &ActionExecutionService::getComputeResources() { return this->compute_resources; } diff --git a/src/wrench/services/helper_services/host_state_change_detector/HostStateChangeDetector.cpp b/src/wrench/services/helper_services/host_state_change_detector/HostStateChangeDetector.cpp index 6e157f29b3..378496537b 100755 --- a/src/wrench/services/helper_services/host_state_change_detector/HostStateChangeDetector.cpp +++ b/src/wrench/services/helper_services/host_state_change_detector/HostStateChangeDetector.cpp @@ -46,7 +46,7 @@ void wrench::HostStateChangeDetector::cleanup(bool has_returned_from_main, int r * */ wrench::HostStateChangeDetector::HostStateChangeDetector(std::string host_on_which_to_run, - std::vector hosts_to_monitor, + std::vector hosts_to_monitor, bool notify_when_turned_on, bool notify_when_turned_off, bool notify_when_speed_change, std::shared_ptr creator, simgrid::s4u::Mailbox *mailbox_to_notify, @@ -64,30 +64,28 @@ wrench::HostStateChangeDetector::HostStateChangeDetector(std::string host_on_whi // Connect my member method to the on_state_change signal from SimGrid regarding Hosts this->on_state_change_call_back_id = simgrid::s4u::Host::on_onoff.connect( [this](simgrid::s4u::Host const &h) { - this->hostStateChangeCallback(h.get_name()); + this->hostStateChangeCallback(&h); }); // Connect my member method to the on_speed_change signal from SimGrid regarding Hosts this->on_speed_change_call_back_id = simgrid::s4u::Host::on_speed_change.connect( [this](simgrid::s4u::Host const &h) { - this->hostSpeedChangeCallback(h.get_name()); + this->hostSpeedChangeCallback(&h); }); } -void wrench::HostStateChangeDetector::hostStateChangeCallback(std::string const &hostname) { - if (std::find(this->hosts_to_monitor.begin(), this->hosts_to_monitor.end(), hostname) != +void wrench::HostStateChangeDetector::hostStateChangeCallback(const simgrid::s4u::Host *host) { + if (std::find(this->hosts_to_monitor.begin(), this->hosts_to_monitor.end(), host) != this->hosts_to_monitor.end()) { - auto host = S4U_Simulation::get_host_or_vm_by_name(hostname); - this->hosts_that_have_recently_changed_state.push_back(std::make_pair(hostname, host->is_on())); + this->hosts_that_have_recently_changed_state.push_back(std::make_pair(host->get_name(), host->is_on())); } } -void wrench::HostStateChangeDetector::hostSpeedChangeCallback(std::string const &hostname) { - if (std::find(this->hosts_to_monitor.begin(), this->hosts_to_monitor.end(), hostname) != +void wrench::HostStateChangeDetector::hostSpeedChangeCallback(const simgrid::s4u::Host *host) { + if (std::find(this->hosts_to_monitor.begin(), this->hosts_to_monitor.end(), host) != this->hosts_to_monitor.end()) { - auto host = S4U_Simulation::get_host_or_vm_by_name(hostname); double speed = host->get_speed(); - this->hosts_that_have_recently_changed_speed.push_back(std::make_pair(hostname, speed)); + this->hosts_that_have_recently_changed_speed.push_back(std::make_pair(host->get_name(), speed)); } } diff --git a/src/wrench/simgrid_S4U_util/S4U_Daemon.cpp b/src/wrench/simgrid_S4U_util/S4U_Daemon.cpp index 0838ed87ca..9df121a78b 100755 --- a/src/wrench/simgrid_S4U_util/S4U_Daemon.cpp +++ b/src/wrench/simgrid_S4U_util/S4U_Daemon.cpp @@ -72,6 +72,7 @@ namespace wrench { this->state = S4U_Daemon::State::CREATED; this->daemon_lock = simgrid::s4u::Mutex::create(); this->hostname = hostname; + this->host =S4U_Simulation::get_host_or_vm_by_name(hostname); this->simulation = nullptr; unsigned long seq = S4U_Mailbox::generateUniqueSequenceNumber(); this->mailbox = S4U_Mailbox::generateUniqueMailbox("mb"); diff --git a/src/wrench/simgrid_S4U_util/S4U_Simulation.cpp b/src/wrench/simgrid_S4U_util/S4U_Simulation.cpp index b416433989..383612e818 100755 --- a/src/wrench/simgrid_S4U_util/S4U_Simulation.cpp +++ b/src/wrench/simgrid_S4U_util/S4U_Simulation.cpp @@ -486,7 +486,7 @@ namespace wrench { * @throw std::invalid_argument */ double S4U_Simulation::getFlopRate() { - return simgrid::s4u::Host::current()->get_speed();// changed it to speed of the current pstate + return simgrid::s4u::Host::current()->get_speed(); // changed it to speed of the current pstate } /** @@ -681,10 +681,10 @@ namespace wrench { } /** -* @brief Get the memory_manager_service capacity of a host given a hostname -* @param hostname: the name of the host -* @return a memory_manager_service capacity in bytes -*/ + * @brief Get the memory_manager_service capacity of a host given a hostname + * @param hostname: the name of the host + * @return a memory_manager_service capacity in bytes + */ double S4U_Simulation::getHostMemoryCapacity(const std::string &hostname) { auto host = S4U_Simulation::get_host_or_vm_by_name_or_null(hostname); if (host == nullptr) { @@ -702,10 +702,10 @@ namespace wrench { } /** -* @brief Get the memory_manager_service capacity of a S4U host -* @param host: the host -* @return a memory_manager_service capacity in bytes -*/ + * @brief Get the memory_manager_service capacity of a S4U host + * @param host: the host + * @return a memory_manager_service capacity in bytes + */ double S4U_Simulation::getHostMemoryCapacity(simgrid::s4u::Host *host) { static std::map memoized; diff --git a/test/services/helper_services/HostStateChangeTest.cpp b/test/services/helper_services/HostStateChangeTest.cpp index 6b16719f89..3156509a80 100755 --- a/test/services/helper_services/HostStateChangeTest.cpp +++ b/test/services/helper_services/HostStateChangeTest.cpp @@ -62,8 +62,8 @@ class HostStateChangeDetectorTestWMS : public wrench::ExecutionController { int main() override { // Create a StateChangeDetector - std::vector hosts; - hosts.push_back("Host2"); + std::vector hosts; + hosts.push_back(wrench::S4U_Simulation::get_host_or_vm_by_name("Host2")); auto ssd = std::shared_ptr( new wrench::HostStateChangeDetector(this->hostname, hosts, true, true, this->notify_when_speed_change, this->getSharedPtr(), this->mailbox, {}));