From d77b02b38c73cf34e18a45339d3c3cf8cd23c72b Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 9 Mar 2018 16:28:56 +0100 Subject: [PATCH] provide a simpler API of Engine::getHostList (returning the structure) and use it --- examples/s4u/actor-suspend/s4u-actor-suspend.cpp | 3 +-- examples/s4u/app-bittorrent/s4u-bittorrent.cpp | 3 +-- examples/s4u/app-token-ring/s4u-app-token-ring.cpp | 3 +-- examples/s4u/dht-chord/s4u-dht-chord.cpp | 3 +-- examples/s4u/exec-ptask/s4u-exec-ptask.cpp | 3 +-- .../s4u/platform-properties/s4u-platform-properties.cpp | 3 +-- include/simgrid/s4u/Engine.hpp | 1 + src/s4u/s4u_engine.cpp | 8 ++++++++ src/simdag/sd_dotloader.cpp | 3 +-- src/simgrid/host.cpp | 6 ++---- src/smpi/internals/smpi_deployment.cpp | 3 +-- src/surf/plugins/host_energy.cpp | 6 ++---- src/surf/sg_platf.cpp | 3 +-- teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp | 3 +-- 14 files changed, 23 insertions(+), 28 deletions(-) diff --git a/examples/s4u/actor-suspend/s4u-actor-suspend.cpp b/examples/s4u/actor-suspend/s4u-actor-suspend.cpp index b663e8e026..967e8034c8 100644 --- a/examples/s4u/actor-suspend/s4u-actor-suspend.cpp +++ b/examples/s4u/actor-suspend/s4u-actor-suspend.cpp @@ -70,8 +70,7 @@ int main(int argc, char* argv[]) xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); e.loadPlatform(argv[1]); /* - Load the platform description */ - std::vector list; - e.getHostList(&list); + std::vector list = e.getHostList(); simgrid::s4u::Actor::createActor("dream_master", list.front(), dream_master); e.run(); /* - Run the simulation */ diff --git a/examples/s4u/app-bittorrent/s4u-bittorrent.cpp b/examples/s4u/app-bittorrent/s4u-bittorrent.cpp index 38709b0be3..9307ba0031 100644 --- a/examples/s4u/app-bittorrent/s4u-bittorrent.cpp +++ b/examples/s4u/app-bittorrent/s4u-bittorrent.cpp @@ -21,8 +21,7 @@ int main(int argc, char* argv[]) HostBittorrent::EXTENSION_ID = simgrid::s4u::Host::extension_create(); - std::vector list; - simgrid::s4u::Engine::getInstance()->getHostList(&list); + std::vector list = simgrid::s4u::Engine::getInstance()->getHostList(); for (auto const& host : list) host->extension_set(new HostBittorrent(host)); diff --git a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp index 388e19f6fe..893e6df539 100644 --- a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp @@ -60,8 +60,7 @@ int main(int argc, char** argv) XBT_INFO("Number of hosts '%zu'", e.getHostCount()); int id = 0; - std::vector list; - e.getHostList(&list); + std::vector list = e.getHostList(); for (auto const& host : list) { /* - Give a unique rank to each host and create a @ref relay_runner process on each */ simgrid::s4u::Actor::createActor((std::to_string(id)).c_str(), host, RelayRunner()); diff --git a/examples/s4u/dht-chord/s4u-dht-chord.cpp b/examples/s4u/dht-chord/s4u-dht-chord.cpp index 5c819f1f7b..f18cf54d6e 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.cpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.cpp @@ -28,8 +28,7 @@ static void chord_init() HostChord::EXTENSION_ID = simgrid::s4u::Host::extension_create(); - std::vector list; - simgrid::s4u::Engine::getInstance()->getHostList(&list); + std::vector list = simgrid::s4u::Engine::getInstance()->getHostList(); for (auto const& host : list) host->extension_set(new HostChord(host)); } diff --git a/examples/s4u/exec-ptask/s4u-exec-ptask.cpp b/examples/s4u/exec-ptask/s4u-exec-ptask.cpp index 7a9a31ff94..4de50c26ad 100644 --- a/examples/s4u/exec-ptask/s4u-exec-ptask.cpp +++ b/examples/s4u/exec-ptask/s4u-exec-ptask.cpp @@ -28,8 +28,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_energyptask, "Messages specific for this s4u ex static void runner() { /* Retrieve the list of all hosts as an array of hosts */ - std::vector hosts; - simgrid::s4u::Engine::getInstance()->getHostList(&hosts); + std::vector hosts = simgrid::s4u::Engine::getInstance()->getHostList(); int hosts_count = hosts.size(); XBT_INFO("First, build a classical parallel task, with 1 Gflop to execute on each node, " diff --git a/examples/s4u/platform-properties/s4u-platform-properties.cpp b/examples/s4u/platform-properties/s4u-platform-properties.cpp index dabffc1553..2d9f388494 100644 --- a/examples/s4u/platform-properties/s4u-platform-properties.cpp +++ b/examples/s4u/platform-properties/s4u-platform-properties.cpp @@ -106,8 +106,7 @@ int main(int argc, char* argv[]) size_t totalHosts = sg_host_count(); XBT_INFO("There are %zu hosts in the environment", totalHosts); - std::vector hosts; - e.getHostList(&hosts); + std::vector hosts = e.getHostList(); for (unsigned int i = 0; i < hosts.size(); i++) XBT_INFO("Host '%s' runs at %.0f flops/s", hosts[i]->getCname(), hosts[i]->getSpeed()); diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index bb204e98b3..bc7d410db6 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -64,6 +64,7 @@ public: simgrid::s4u::Host* hostByNameOrNull(std::string name); size_t getHostCount(); void getHostList(std::vector * whereTo); + std::vector getHostList(); size_t getLinkCount(); void getLinkList(std::vector * list); diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index 0dea4cb784..e5fce94804 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -91,6 +91,14 @@ void Engine::getHostList(std::vector* list) for (auto const& kv : pimpl->hosts_) list->push_back(kv.second); } +/** @brief Returns the list of all hosts found in the platform */ +std::vector Engine::getHostList() +{ + std::vector res; + for (auto const& kv : pimpl->hosts_) + res.push_back(kv.second); + return res; +} void Engine::addHost(std::string name, simgrid::s4u::Host* host) { pimpl->hosts_[name] = host; diff --git a/src/simdag/sd_dotloader.cpp b/src/simdag/sd_dotloader.cpp index 4979a2e2dd..10bb4ad5d0 100644 --- a/src/simdag/sd_dotloader.cpp +++ b/src/simdag/sd_dotloader.cpp @@ -213,8 +213,7 @@ xbt_dynar_t SD_dotload_generic(const char* filename, bool sequential, bool sched if(schedule){ if (schedule_success) { - std::vector hosts; - simgrid::s4u::Engine::getInstance()->getHostList(&hosts); + std::vector hosts = simgrid::s4u::Engine::getInstance()->getHostList(); for (auto const& elm : computers) { SD_task_t previous_task = nullptr; diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index e49a988134..faf160f219 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -37,8 +37,7 @@ size_t sg_host_count() */ sg_host_t *sg_host_list() { xbt_assert(sg_host_count() > 0, "There is no host!"); - std::vector hosts; - simgrid::s4u::Engine::getInstance()->getHostList(&hosts); + std::vector hosts = simgrid::s4u::Engine::getInstance()->getHostList(); sg_host_t* res = (sg_host_t*)malloc(sizeof(sg_host_t) * hosts.size()); memcpy(res, hosts.data(), sizeof(sg_host_t) * hosts.size()); @@ -76,8 +75,7 @@ xbt_dynar_t sg_hosts_as_dynar() { xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),nullptr); - std::vector list; - simgrid::s4u::Engine::getInstance()->getHostList(&list); + std::vector list = simgrid::s4u::Engine::getInstance()->getHostList(); for (auto const& host : list) { if (host && host->pimpl_netpoint && host->pimpl_netpoint->isHost()) diff --git a/src/smpi/internals/smpi_deployment.cpp b/src/smpi/internals/smpi_deployment.cpp index 76052cfc13..174447a972 100644 --- a/src/smpi/internals/smpi_deployment.cpp +++ b/src/smpi/internals/smpi_deployment.cpp @@ -57,8 +57,7 @@ void SMPI_app_instance_register(const char *name, xbt_main_func_t code, int num_ static int already_called = 0; if (not already_called) { already_called = 1; - std::vector list; - simgrid::s4u::Engine::getInstance()->getHostList(&list); + std::vector list = simgrid::s4u::Engine::getInstance()->getHostList(); for (auto const& host : list) { host->extension_set(new simgrid::smpi::SmpiHost(host)); } diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index 8826efc78a..f999bd1e9b 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -432,8 +432,7 @@ static void onHostDestruction(simgrid::s4u::Host& host) static void onSimulationEnd() { - std::vector hosts; - simgrid::s4u::Engine::getInstance()->getHostList(&hosts); + std::vector hosts = simgrid::s4u::Engine::getInstance()->getHostList(); double total_energy = 0.0; // Total energy consumption (whole platform) double used_hosts_energy = 0.0; // Energy consumed by hosts that computed something @@ -484,8 +483,7 @@ void sg_host_energy_plugin_init() void sg_host_energy_update_all() { simgrid::simix::kernelImmediate([]() { - std::vector list; - simgrid::s4u::Engine::getInstance()->getHostList(&list); + std::vector list = simgrid::s4u::Engine::getInstance()->getHostList(); for (auto const& host : list) if (dynamic_cast(host) == nullptr) // Ignore virtual machines host->extension()->update(); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 5a3578581a..f372ea8058 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -417,8 +417,7 @@ void sg_platf_new_actor(ActorCreationArgs* actor) std::string msg = std::string("Cannot create actor '") + actor->function + "': host '" + actor->host + "' does not exist\nExisting hosts: '"; - std::vector list; - simgrid::s4u::Engine::getInstance()->getHostList(&list); + std::vector list = simgrid::s4u::Engine::getInstance()->getHostList(); for (auto const& host : list) { msg += host->getName(); diff --git a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp index c82af7b2b3..8dce7585af 100644 --- a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp +++ b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp @@ -182,8 +182,7 @@ int main(int argc, char* argv[]) } xbt_assert(argSend.front().size() == argRecv.front().size(), "Sender and receiver spec must be of the same size"); - std::vector hosts; - e.getHostList(&hosts); + std::vector hosts = e.getHostList(); simgrid::s4u::Actor::createActor("sender", hosts[0], sender, argSend); simgrid::s4u::Actor::createActor("recver", hosts[1], receiver, argRecv); -- 2.20.1