From b8dae0fb0df3dd5c66241e88f1f574c687c504f9 Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Fri, 1 Jun 2018 10:20:35 +0200 Subject: [PATCH] [S4U] Implement Engine::get_filtered_hosts This method takes any callable object (lambda, function, functor = function object) that returns a boolean value (true = use this host, false = don't use it) and that takes a Host* as parameter. This allows to filter within the Engine rather than returning a list with all hosts --- examples/s4u/CMakeLists.txt | 4 ++++ include/simgrid/s4u/Engine.hpp | 1 + src/s4u/s4u_Engine.cpp | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index abcace22f3..7b24fc1462 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -1,9 +1,12 @@ +# THIS IS ONLY FOR THE FILES. To add your test (tesh) as well, make sure you add +# the same at the bottom of the file as well. foreach (example actor-create actor-daemon actor-join actor-kill actor-lifetime actor-migration actor-suspend actor-yield app-chainsend app-masterworker app-pingpong app-token-ring async-wait async-waitany async-waitall cloud-capping cloud-migration cloud-simple energy-exec energy-boot energy-link energy-vm + engine-filtering exec-async exec-basic exec-dvfs exec-monitor exec-ptask exec-remote io-file-system io-file-remote io-storage-raw mutex @@ -86,6 +89,7 @@ foreach(example actor-create actor-daemon actor-join actor-kill cloud-capping cloud-migration cloud-simple dht-chord dht-kademlia energy-exec energy-boot energy-link energy-vm + engine-filtering exec-async exec-basic exec-dvfs exec-monitor exec-ptask exec-remote platform-properties plugin-hostload mutex io-file-system io-file-remote io-storage-raw diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 381563fa91..767891b124 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -95,6 +95,7 @@ protected: public: size_t get_host_count(); std::vector get_all_hosts(); + std::vector get_filtered_hosts(std::function filter); simgrid::s4u::Host* host_by_name(std::string name); simgrid::s4u::Host* host_by_name_or_null(std::string name); diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index ab520f2f59..d522abf243 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -108,6 +108,17 @@ std::vector Engine::get_all_hosts() return res; } +std::vector Engine::get_filtered_hosts(std::function filter) +{ + std::vector hosts; + for (auto const& kv : pimpl->hosts_) { + if (filter(kv.second)) + hosts.push_back(kv.second); + } + + return hosts; +} + void Engine::host_register(std::string name, simgrid::s4u::Host* host) { pimpl->hosts_[name] = host; -- 2.20.1