From: Martin Quinson Date: Tue, 14 Mar 2017 08:59:57 +0000 (+0100) Subject: New: Engine::hostList() and Engine::hostCount(). Still clumsy. X-Git-Tag: v3_15~109 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7fc148e54129356298bb2708d9681b66d1d36330 New: Engine::hostList() and Engine::hostCount(). Still clumsy. - the underlaying data is not part of Engine - ranged for loops are still difficult to write --- diff --git a/ChangeLog b/ChangeLog index d7bfa97605..5deb010419 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,7 @@ SimGrid (3.15) UNRELEASED; urgency=low - s4u::Host::onSpeedChange: when the pstate is changed, or when an event from the availability_file changes the avail speed. - Links are now usable from s4u + - New: Engine::hostList() and Engine::hostCount(). Still clumsy. - Drop Host::getPstateSpeedCurrent() which dupplicates Host::speed() SimDag 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 303529be92..266b60cf73 100644 --- a/examples/s4u/app-token-ring/s4u_app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u_app-token-ring.cpp @@ -11,8 +11,6 @@ #include XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_token_ring, "Messages specific for this s4u example"); -// FIXME: The following duplicates the content of s4u::Host -extern std::map host_list; class RelayRunner { size_t task_comm_size = 1000000; /* The token is 1MB long*/ @@ -28,7 +26,7 @@ public: rank = xbt_str_parse_int(simgrid::s4u::this_actor::name().c_str(), "Any process of this example must have a numerical name, not %s"); my_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(rank)); - if (rank + 1 == host_list.size()) + if (rank + 1 == simgrid::s4u::Engine::instance()->hostCount()) /* The last process, which sends the token back to rank 0 */ neighbor_mailbox = simgrid::s4u::Mailbox::byName("0"); else @@ -57,10 +55,11 @@ int main(int argc, char** argv) xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]); e->loadPlatform(argv[1]); - XBT_INFO("Number of hosts '%zu'", host_list.size()); + XBT_INFO("Number of hosts '%zu'", e->hostCount()); int id = 0; - for (auto h : host_list) { - simgrid::s4u::Host* host = h.second; + std::vector list; + e->hostList(&list); + for (auto 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()); id++; diff --git a/include/simgrid/s4u/engine.hpp b/include/simgrid/s4u/engine.hpp index 413f7ef92e..9a1a5d98c9 100644 --- a/include/simgrid/s4u/engine.hpp +++ b/include/simgrid/s4u/engine.hpp @@ -57,6 +57,9 @@ public: /** @brief Load a deployment file and launch the actors that it contains */ void loadDeployment(const char *deploy); + unsigned int hostCount(); + void hostList(std::vector*); + /** @brief Run the simulation */ void run(); diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index bcb18208a2..0434602c9f 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -78,6 +78,19 @@ void Engine::loadDeployment(const char *deploy) { SIMIX_launch_application(deploy); } +// FIXME: The following duplicates the content of s4u::Host +extern std::map host_list; +/** @brief Returns the amount of hosts in the platform */ +unsigned int Engine::hostCount() +{ + return host_list.size(); +} +/** @brief Fills the passed list with all hosts found in the platform */ +void Engine::hostList(std::vector* list) +{ + for (auto kv : host_list) + list->push_back(kv.second); +} void Engine::run() { if (MC_is_active()) { diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index e3c363563c..4d74e354f3 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -23,8 +23,6 @@ XBT_LOG_EXTERNAL_CATEGORY(surf_route); -std::map host_list; // FIXME: move it to Engine - int USER_HOST_LEVEL = -1; namespace simgrid { @@ -35,6 +33,8 @@ template class Extendable; namespace s4u { +std::map host_list; // FIXME: move it to Engine + simgrid::xbt::signal Host::onCreation; simgrid::xbt::signal Host::onDestruction; simgrid::xbt::signal Host::onStateChange; diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 21f311f00c..5bf67431eb 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -19,7 +19,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_host, sd, "Logging specific to sg_hosts"); // FIXME: The following duplicates the content of s4u::Host +namespace simgrid { +namespace s4u { extern std::map host_list; +} +} extern "C" { @@ -33,20 +37,20 @@ void sg_host_exit() * the tests. */ std::vector names = std::vector(); - for (auto kv : host_list) + for (auto kv : simgrid::s4u::host_list) names.push_back(kv.second->name()); std::sort(names.begin(), names.end()); for (auto name : names) - host_list.at(name)->destroy(); + simgrid::s4u::host_list.at(name)->destroy(); // host_list.clear(); This would be sufficient if the dict would contain smart_ptr. It's now useless } size_t sg_host_count() { - return host_list.size(); + return simgrid::s4u::host_list.size(); } /** @brief Returns the host list * @@ -93,7 +97,7 @@ xbt_dynar_t sg_hosts_as_dynar() { xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),nullptr); - for (auto kv : host_list) { + for (auto kv : simgrid::s4u::host_list) { simgrid::s4u::Host* host = kv.second; if (host && host->pimpl_netpoint && host->pimpl_netpoint->isHost()) xbt_dynar_push(res, &host);