From 8fb62dc5a69cd10bc48dae3c6e7ecf54b11ba378 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sun, 5 Apr 2020 11:12:59 +0200 Subject: [PATCH] useless morning cleanups --- MANIFEST.in | 1 + examples/c/io-file-system/io-file-system.c | 2 +- src/instr/instr_paje_values.cpp | 3 +- src/instr/instr_private.hpp | 5 +- src/smpi/plugins/ampi/ampi.cpp | 12 ++-- src/smpi/plugins/ampi/ampi.hpp | 12 ++-- .../plugins/load_balancer/LoadBalancer.cpp | 60 +++++++++---------- .../plugins/load_balancer/load_balancer.hpp | 30 +++++----- src/smpi/plugins/sampi_loadbalancer.cpp | 54 ++++++++--------- 9 files changed, 87 insertions(+), 92 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 16bfe38bc9..04946c2d24 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1938,6 +1938,7 @@ include examples/platforms/two_hosts_profiles.xml include examples/platforms/two_peers.xml include examples/platforms/vivaldi.xml include examples/platforms/wifi.xml +include examples/platforms/wifi_decay_2STA.xml include examples/python/CMakeLists.txt include examples/python/actor-create/actor-create_d.xml include examples/python/actor-lifetime/actor-lifetime_d.xml diff --git a/examples/c/io-file-system/io-file-system.c b/examples/c/io-file-system/io-file-system.c index 29b44e132e..618cc5f51b 100644 --- a/examples/c/io-file-system/io-file-system.c +++ b/examples/c/io-file-system/io-file-system.c @@ -22,7 +22,7 @@ static void show_info(unsigned int disk_count, const sg_disk_t* disks) XBT_INFO("Storage info on %s:", sg_host_self_get_name()); for (unsigned int i = 0; i < disk_count; i++) { - const sg_disk_t d = disks[i]; + const_sg_disk_t d = disks[i]; // Retrieve disk's information XBT_INFO(" %s (%s) Used: %llu; Free: %llu; Total: %llu.", sg_disk_name(d), sg_disk_get_mount_point(d), sg_disk_get_size_used(d), sg_disk_get_size_free(d), sg_disk_get_size(d)); diff --git a/src/instr/instr_paje_values.cpp b/src/instr/instr_paje_values.cpp index 5f2bcd4742..743cfaf479 100644 --- a/src/instr/instr_paje_values.cpp +++ b/src/instr/instr_paje_values.cpp @@ -12,8 +12,9 @@ namespace simgrid { namespace instr { EntityValue::EntityValue(const std::string& name, const std::string& color, Type* father) - : id_(instr_new_paje_id()), name_(name), color_(color), father_(father) + : name_(name), color_(color), father_(father) { + id_ = instr_new_paje_id(); on_creation(*this); } } // namespace instr diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index 9ed7048874..755f3493ff 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -234,8 +234,8 @@ public: std::string display_size() override { return "NA"; } }; -} -} +} // namespace instr +} // namespace simgrid XBT_PRIVATE std::string instr_pid(simgrid::s4u::Actor const& proc); @@ -286,5 +286,4 @@ XBT_PRIVATE void dump_comment_file(const std::string& filename); XBT_PRIVATE std::string TRACE_get_filename(); - #endif diff --git a/src/smpi/plugins/ampi/ampi.cpp b/src/smpi/plugins/ampi/ampi.cpp index be0d713f08..24e64ea182 100644 --- a/src/smpi/plugins/ampi/ampi.cpp +++ b/src/smpi/plugins/ampi/ampi.cpp @@ -61,12 +61,12 @@ namespace simgrid { namespace smpi { namespace plugin { namespace ampi { -simgrid::xbt::signal on_iteration_in; -simgrid::xbt::signal on_iteration_out; -} -} -} -} +xbt::signal on_iteration_in; +xbt::signal on_iteration_out; +} // namespace ampi +} // namespace plugin +} // namespace smpi +} // namespace simgrid /* FIXME The following contains several times "rank() + 1". This works for one * instance, but we need to find a way to deal with this for several instances and diff --git a/src/smpi/plugins/ampi/ampi.hpp b/src/smpi/plugins/ampi/ampi.hpp index 2f209af703..307c53056b 100644 --- a/src/smpi/plugins/ampi/ampi.hpp +++ b/src/smpi/plugins/ampi/ampi.hpp @@ -12,11 +12,11 @@ namespace simgrid { namespace smpi { namespace plugin { namespace ampi { -extern simgrid::xbt::signal on_iteration_out; -extern simgrid::xbt::signal on_iteration_in; -} -} -} -} +extern xbt::signal on_iteration_out; +extern xbt::signal on_iteration_in; +} // namespace ampi +} // namespace plugin +} // namespace smpi +} // namespace simgrid #endif diff --git a/src/smpi/plugins/load_balancer/LoadBalancer.cpp b/src/smpi/plugins/load_balancer/LoadBalancer.cpp index 2c93726164..1af847c7fa 100644 --- a/src/smpi/plugins/load_balancer/LoadBalancer.cpp +++ b/src/smpi/plugins/load_balancer/LoadBalancer.cpp @@ -20,45 +20,42 @@ namespace loadbalancer { class XBT_PRIVATE compare_hosts { public: - bool operator()(simgrid::s4u::Host* const a, simgrid::s4u::Host* const b) const; + bool operator()(s4u::Host* const a, s4u::Host* const b) const; }; -typedef boost::heap::fibonacci_heap>::handle_type heap_handle; +typedef boost::heap::fibonacci_heap>::handle_type heap_handle; -/** - * Structure that imitates a std::pair, but it allows us - * to use meaningful names instead of .first and .second - */ +/** Structure that imitates a std::pair, but it allows us to use meaningful names instead of .first and .second */ struct XBT_PRIVATE pair_handle_load { heap_handle update_handle; double load; }; -static std::map additional_load; +static std::map additional_load; -bool compare_hosts::operator()(simgrid::s4u::Host* const a, simgrid::s4u::Host* const b) const { +bool compare_hosts::operator()(s4u::Host* const a, s4u::Host* const b) const +{ return additional_load[a].load > additional_load[b].load; } - void LoadBalancer::run() { - simgrid::s4u::Engine* engine = simgrid::s4u::Engine::get_instance(); - std::vector available_hosts = - engine->get_filtered_hosts([](const simgrid::s4u::Host* host) { return host->is_on(); }); + s4u::Engine* engine = s4u::Engine::get_instance(); + std::vector available_hosts = + engine->get_filtered_hosts([](const s4u::Host* host) { return host->is_on(); }); xbt_assert(available_hosts.size() > 0, "No hosts available; are they all switched off?"); // TODO: Account for daemon background load (-> use especially the availability file) - std::vector all_actors = - engine->get_filtered_actors([](simgrid::s4u::ActorPtr actor) { return not actor->is_daemon(); }); + std::vector all_actors = + engine->get_filtered_actors([](s4u::ActorPtr actor) { return not actor->is_daemon(); }); for (auto const& actor : all_actors) { new_mapping.assign(actor, actor->get_host()); } // Sort the actors, from highest to lowest load; we then just iterate over these actors - std::sort(all_actors.begin(), all_actors.end(), [this](simgrid::s4u::ActorPtr a, simgrid::s4u::ActorPtr b) { + std::sort(all_actors.begin(), all_actors.end(), [this](s4u::ActorPtr a, s4u::ActorPtr b) { return actor_computation[a->get_pid()] > actor_computation[b->get_pid()]; }); @@ -70,12 +67,12 @@ void LoadBalancer::run() // std::priorityQueue is immutable and hence doesn't work for us. // // This heap contains the least loaded host at the top - boost::heap::fibonacci_heap> usable_hosts; + boost::heap::fibonacci_heap> usable_hosts; for (auto& host : available_hosts) { - std::vector actors = host->get_all_actors(); - heap_handle update_handle = usable_hosts.push(host); // Required to update elements in the heap - additional_load[host] = {update_handle, 0}; // Save the handle for later - const double total_flops_computed = sg_host_get_computed_flops(host); + std::vector actors = host->get_all_actors(); + heap_handle update_handle = usable_hosts.push(host); // Required to update elements in the heap + additional_load[host] = {update_handle, 0}; // Save the handle for later + const double total_flops_computed = sg_host_get_computed_flops(host); for (auto const& actor : actors) { additional_load[host].load += actor_computation[actor->get_pid()] / total_flops_computed; // Normalize load - this allows comparison // even between hosts with different frequencies @@ -87,9 +84,9 @@ void LoadBalancer::run() // Implementation of the Greedy algorithm for (auto const& actor : all_actors) { - simgrid::s4u::Host* target_host = usable_hosts.top(); // This is the host with the lowest load + s4u::Host* target_host = usable_hosts.top(); // This is the host with the lowest load - simgrid::s4u::Host* cur_mapped_host = new_mapping.get_host(actor); + s4u::Host* cur_mapped_host = new_mapping.get_host(actor); if (target_host != cur_mapped_host && additional_load[target_host].load + actor_computation[actor->get_pid()] < additional_load[cur_mapped_host].load && new_mapping.count_actors(cur_mapped_host) > 1) { @@ -109,7 +106,7 @@ void LoadBalancer::run() } while (!usable_hosts.empty()) { - simgrid::s4u::Host* host = usable_hosts.top(); + s4u::Host* host = usable_hosts.top(); usable_hosts.pop(); sg_host_load_reset(host); // Reset host load for next iterations @@ -118,10 +115,9 @@ void LoadBalancer::run() /* Debug messages that allow us to verify the load for each host */ XBT_DEBUG("Host: %s, load total: %f", host->get_cname(), additional_load[host].load); double load_verif = 0.0; - new_mapping.for_each_actor(host, - [this, &load_verif](simgrid::s4u::ActorPtr actor) { - load_verif += actor_computation[actor->get_pid()]; - XBT_DEBUG(" %li (load: %f)", actor->get_pid(), actor_computation[actor->get_pid()]); + new_mapping.for_each_actor(host, [this, &load_verif](s4u::ActorPtr actor) { + load_verif += actor_computation[actor->get_pid()]; + XBT_DEBUG(" %li (load: %f)", actor->get_pid(), actor_computation[actor->get_pid()]); }); XBT_DEBUG("Host load verification: %f", load_verif); } @@ -131,15 +127,15 @@ void LoadBalancer::run() } } -simgrid::s4u::Host* LoadBalancer::get_mapping(simgrid::s4u::ActorPtr actor) +s4u::Host* LoadBalancer::get_mapping(s4u::ActorPtr actor) { return new_mapping.get_host(actor); } -void LoadBalancer::record_actor_computation(simgrid::s4u::Actor const& actor, double load) +void LoadBalancer::record_actor_computation(s4u::Actor const& actor, double load) { actor_computation[actor.get_pid()] += load; } -} -} -} +} // namespace loadbalancer +} // namespace plugin +} // namespace simgrid diff --git a/src/smpi/plugins/load_balancer/load_balancer.hpp b/src/smpi/plugins/load_balancer/load_balancer.hpp index 315a7b1c2f..4264966b62 100644 --- a/src/smpi/plugins/load_balancer/load_balancer.hpp +++ b/src/smpi/plugins/load_balancer/load_balancer.hpp @@ -15,13 +15,13 @@ namespace loadbalancer { class XBT_PRIVATE Mapping { public: /** Each host can have an arbitrary number of actors -> multimap **/ - typedef std::unordered_multimap host_to_actors_map_t; + typedef std::unordered_multimap host_to_actors_map_t; host_to_actors_map_t host_to_actors; /** Each actor gets assigned to exactly one host -> map **/ - std::map actor_to_host; + std::map actor_to_host; - void assign(simgrid::s4u::ActorPtr actor, simgrid::s4u::Host* host) + void assign(s4u::ActorPtr actor, s4u::Host* host) { /* Remove "actor" from its old host -> get all elements that have the current host as key **/ auto range = host_to_actors.equal_range(/* current host */actor_to_host[actor]); @@ -36,14 +36,14 @@ public: host_to_actors.insert({host, actor}); } - simgrid::s4u::Host* get_host(simgrid::s4u::ActorPtr actor) { return actor_to_host[actor]; } + s4u::Host* get_host(s4u::ActorPtr actor) { return actor_to_host[actor]; } - unsigned int count_actors(simgrid::s4u::Host* host) + unsigned int count_actors(s4u::Host* host) { return host_to_actors.count(host); // TODO This is linear in the size of the map. Maybe replace by constant lookup through another map? } - void for_each_actor(simgrid::s4u::Host* host, const std::function& callback) + void for_each_actor(s4u::Host* host, const std::function& callback) { auto range = host_to_actors.equal_range(host); std::for_each(range.first, range.second, @@ -58,16 +58,14 @@ class XBT_PRIVATE LoadBalancer public: void run(); - void assign(simgrid::s4u::ActorPtr actor, simgrid::s4u::Host* host); - - /** - * FIXME These are functions used for testing and should be re-written or removed - */ - simgrid::s4u::Host* get_mapping(simgrid::s4u::ActorPtr); - void record_actor_computation(simgrid::s4u::Actor const& actor, double load); + void assign(s4u::ActorPtr actor, s4u::Host* host); + + /** FIXME These are functions used for testing and should be re-written or removed */ + s4u::Host* get_mapping(s4u::ActorPtr); + void record_actor_computation(s4u::Actor const& actor, double load); }; -} -} -} +} // namespace loadbalancer +} // namespace plugin +} // namespace simgrid #endif diff --git a/src/smpi/plugins/sampi_loadbalancer.cpp b/src/smpi/plugins/sampi_loadbalancer.cpp index be546b33fe..c989c3e419 100644 --- a/src/smpi/plugins/sampi_loadbalancer.cpp +++ b/src/smpi/plugins/sampi_loadbalancer.cpp @@ -29,10 +29,10 @@ namespace plugin { static simgrid::plugin::loadbalancer::LoadBalancer lb; -class MigrateParser : public simgrid::smpi::replay::ActionArgParser { +class MigrateParser : public replay::ActionArgParser { public: double memory_consumption; - void parse(simgrid::xbt::ReplayAction& action, const std::string&) + void parse(xbt::ReplayAction& action, const std::string&) { // The only parameter is the amount of memory used by the current process. CHECK_ACTION_PARAMS(action, 1, 0); @@ -40,25 +40,25 @@ public: } }; -/* This function simulates what happens when the original application calls - * (A)MPI_Migrate. It executes the load balancing heuristics, makes the necessary - * migrations and updates the task mapping in the load balancer. +/* This function simulates what happens when the original application calls (A)MPI_Migrate. It executes the load + * balancing heuristics, makes the necessary migrations and updates the task mapping in the load balancer. */ -class MigrateAction : public simgrid::smpi::replay::ReplayAction { +class MigrateAction : public replay::ReplayAction { public: explicit MigrateAction() : ReplayAction("Migrate") {} - void kernel(simgrid::xbt::ReplayAction&) + void kernel(xbt::ReplayAction&) { - static std::map migration_call_counter; - static simgrid::s4u::Barrier smpilb_bar(smpi_get_universe_size()); - simgrid::s4u::Host* cur_host = simgrid::s4u::this_actor::get_host(); - simgrid::s4u::Host* migrate_to_host; + static std::map migration_call_counter; + static s4u::Barrier smpilb_bar(smpi_get_universe_size()); + s4u::Host* cur_host = s4u::this_actor::get_host(); + s4u::Host* migrate_to_host; TRACE_migration_call(get_pid(), nullptr); // We only migrate every "cfg_migration_frequency"-times, not at every call - migration_call_counter[simgrid::s4u::Actor::self()]++; - if ((migration_call_counter[simgrid::s4u::Actor::self()] % simgrid::config::get_value(cfg_migration_frequency.get_name())) != 0) { + migration_call_counter[s4u::Actor::self()]++; + if ((migration_call_counter[s4u::Actor::self()] % config::get_value(cfg_migration_frequency.get_name())) != + 0) { return; } @@ -80,20 +80,20 @@ public: migrate_to_host = lb.get_mapping(simgrid::s4u::Actor::self()); if (cur_host != migrate_to_host) { // Origin and dest are not the same -> migrate - std::vector migration_hosts = {cur_host, migrate_to_host}; + std::vector migration_hosts = {cur_host, migrate_to_host}; std::vector comp_amount = {0, 0}; std::vector comm_amount = {0, /*must not be 0*/ std::max(get_args().memory_consumption, 1.0), 0, 0}; xbt_os_timer_t timer = smpi_process()->timer(); xbt_os_threadtimer_start(timer); - simgrid::s4u::this_actor::parallel_execute(migration_hosts, comp_amount, comm_amount); + s4u::this_actor::parallel_execute(migration_hosts, comp_amount, comm_amount); xbt_os_threadtimer_stop(timer); smpi_execute(xbt_os_timer_elapsed(timer)); // Update the process and host mapping in SimGrid. XBT_DEBUG("Migrating process %li from %s to %s", get_pid(), cur_host->get_cname(), migrate_to_host->get_cname()); TRACE_smpi_process_change_host(get_pid(), migrate_to_host); - simgrid::s4u::this_actor::set_host(migrate_to_host); + s4u::this_actor::set_host(migrate_to_host); } smpilb_bar.wait(); @@ -107,24 +107,24 @@ public: ******************************************************************************/ // FIXME Move declaration -XBT_PRIVATE void action_iteration_in(simgrid::xbt::ReplayAction& action); -void action_iteration_in(simgrid::xbt::ReplayAction& action) +XBT_PRIVATE void action_iteration_in(xbt::ReplayAction& action); +void action_iteration_in(xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 0, 0) - TRACE_Iteration_in(simgrid::s4u::this_actor::get_pid(), nullptr); - simgrid::smpi::plugin::ampi::on_iteration_in(*MPI_COMM_WORLD->group()->actor(std::stol(action[0]))); + TRACE_Iteration_in(s4u::this_actor::get_pid(), nullptr); + smpi::plugin::ampi::on_iteration_in(*MPI_COMM_WORLD->group()->actor(std::stol(action[0]))); } -XBT_PRIVATE void action_iteration_out(simgrid::xbt::ReplayAction& action); -void action_iteration_out(simgrid::xbt::ReplayAction& action) +XBT_PRIVATE void action_iteration_out(xbt::ReplayAction& action); +void action_iteration_out(xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 0, 0) - TRACE_Iteration_out(simgrid::s4u::this_actor::get_pid(), nullptr); - simgrid::smpi::plugin::ampi::on_iteration_out(*MPI_COMM_WORLD->group()->actor(std::stol(action[0]))); -} -} -} + TRACE_Iteration_out(s4u::this_actor::get_pid(), nullptr); + ampi::on_iteration_out(*MPI_COMM_WORLD->group()->actor(std::stol(action[0]))); } +} // namespace plugin +} // namespace smpi +} // namespace simgrid /** @ingroup plugin_loadbalancer * @brief Initializes the load balancer plugin -- 2.20.1