Skip to content

Commit

Permalink
removed some simgrid::Host *
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Oct 3, 2023
1 parent d3af2c2 commit 15526ef
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 83 deletions.
2 changes: 2 additions & 0 deletions include/wrench/services/Service.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ namespace wrench {
/** \cond INTERNAL */
/***********************/

simgrid::s4u::Host *getHost();

double getMessagePayloadValue(WRENCH_MESSAGEPAYLOAD_TYPE);
const WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE &getMessagePayloadList() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ namespace wrench {
std::shared_ptr<PilotJob> pj, const std::string &suffix,
std::shared_ptr<StorageService> scratch_space);// reference to upper level scratch space

BareMetalComputeService(const std::string &hostname,
std::map<simgrid::s4u::Host *, std::tuple<unsigned long, double>> compute_resources,
WRENCH_PROPERTY_COLLECTION_TYPE property_list,
WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE messagepayload_list,
std::shared_ptr<PilotJob> pj, const std::string &suffix,
std::shared_ptr<StorageService> scratch_space);// reference to upper level scratch space

BareMetalComputeService(const std::string &hostname,
const std::map<std::string, std::tuple<unsigned long, double>> &compute_resources,
WRENCH_PROPERTY_COLLECTION_TYPE property_list,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace wrench {

bool IsThereAtLeastOneHostWithAvailableResources(unsigned long num_cores, double ram);

std::map<std::string, std::tuple<unsigned long, double>> &getComputeResources();
std::map<simgrid::s4u::Host *, std::tuple<unsigned long, double>> &getComputeResources();

std::map<std::string, double> getResourceInformation(const std::string &key);

Expand All @@ -92,11 +92,11 @@ namespace wrench {
void validateProperties();


std::map<std::string, std::tuple<unsigned long, double>> compute_resources;
std::map<simgrid::s4u::Host *, std::tuple<unsigned long, double>> compute_resources;

// Core availabilities (for each hosts, how many cores and how many bytes of RAM are currently available on it)
std::unordered_map<std::string, double> ram_availabilities;
std::unordered_map<std::string, unsigned long> running_thread_counts;
std::unordered_map<simgrid::s4u::Host *, double> ram_availabilities;
std::unordered_map<simgrid::s4u::Host *, unsigned long> running_thread_counts;

std::shared_ptr<Service> parent_service = nullptr;

Expand Down Expand Up @@ -154,9 +154,9 @@ namespace wrench {

void processSubmitAction(simgrid::s4u::Mailbox *answer_mailbox, const std::shared_ptr<Action> &action);

std::tuple<std::string, unsigned long> pickAllocation(const std::shared_ptr<Action> &action,
std::tuple<simgrid::s4u::Host *, unsigned long> pickAllocation(const std::shared_ptr<Action> &action,
const std::string &required_host, unsigned long required_num_cores,
std::set<std::string> &hosts_to_avoid);
std::set<simgrid::s4u::Host *> &hosts_to_avoid);


bool isThereAtLeastOneHostWithResources(unsigned long num_cores, double ram);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace wrench {

public:
explicit HostStateChangeDetector(std::string host_on_which_to_run,
std::vector<std::string> hosts_to_monitor,
std::vector<simgrid::s4u::Host *> hosts_to_monitor,
bool notify_when_turned_on,
bool notify_when_turned_off,
bool notify_when_speed_change,
Expand All @@ -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<std::string> hosts_to_monitor;
std::vector<simgrid::s4u::Host *> hosts_to_monitor;
bool notify_when_turned_on;
bool notify_when_turned_off;
bool notify_when_speed_change;
Expand Down
5 changes: 5 additions & 0 deletions include/wrench/simgrid_S4U_util/S4U_Daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;


Expand Down
3 changes: 2 additions & 1 deletion include/wrench/simgrid_S4U_util/S4U_Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::vector<std::string>> &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;
Expand Down
20 changes: 10 additions & 10 deletions src/wrench/action/MPIAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ namespace wrench {

// Make A COPY of the list of usable hosts
auto resources_ref = action_executor->getActionExecutionService()->getComputeResources();
std::map<std::string, std::tuple<unsigned long, double>> resources(resources_ref.begin(), resources_ref.end());
std::vector<std::string> hostnames;
hostnames.reserve(resources.size());
std::map<simgrid::s4u::Host *, std::tuple<unsigned long, double>> resources(resources_ref.begin(), resources_ref.end());
std::vector<simgrid::s4u::Host *> 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<std::string> hosts;
std::vector<simgrid::s4u::Host *> 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;
Expand All @@ -74,7 +74,7 @@ namespace wrench {
std::vector<simgrid::s4u::Host *> 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!!!
Expand Down
8 changes: 8 additions & 0 deletions src/wrench/services/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 39 additions & 2 deletions src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 '" +
Expand Down Expand Up @@ -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 <host, num_cores, memory_manager_service> 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<simgrid::s4u::Host *, std::tuple<unsigned long, double>> compute_resources,
WRENCH_PROPERTY_COLLECTION_TYPE property_list,
WRENCH_MESSAGE_PAYLOADCOLLECTION_TYPE messagepayload_list,
std::shared_ptr<PilotJob> pj,
const std::string &suffix, std::shared_ptr<StorageService> scratch_space) : ComputeService(hostname,
"bare_metal" + suffix,
std::move(scratch_space)) {

std::map<std::string, std::tuple<unsigned long, double>> 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
*
Expand Down
Loading

0 comments on commit 15526ef

Please sign in to comment.