Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[S4U] Implement Engine::get_filtered_hosts
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Fri, 1 Jun 2018 08:20:35 +0000 (10:20 +0200)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Fri, 1 Jun 2018 16:21:42 +0000 (18:21 +0200)
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
include/simgrid/s4u/Engine.hpp
src/s4u/s4u_Engine.cpp

index abcace2..7b24fc1 100644 (file)
@@ -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
index 381563f..767891b 100644 (file)
@@ -95,6 +95,7 @@ protected:
 public:
   size_t get_host_count();
   std::vector<Host*> get_all_hosts();
+  std::vector<Host*> get_filtered_hosts(std::function<bool(Host*)> filter);
   simgrid::s4u::Host* host_by_name(std::string name);
   simgrid::s4u::Host* host_by_name_or_null(std::string name);
 
index ab520f2..d522abf 100644 (file)
@@ -108,6 +108,17 @@ std::vector<Host*> Engine::get_all_hosts()
   return res;
 }
 
+std::vector<Host*> Engine::get_filtered_hosts(std::function<bool(Host*)> filter)
+{
+  std::vector<Host*> 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;