2 #ifndef HAVE_SG_PLUGIN_LB
3 #define HAVE_SG_PLUGIN_LB
5 #include <simgrid/s4u.hpp>
9 namespace loadbalancer {
11 class XBT_PRIVATE Mapping {
15 /** Each host can have an arbitrary number of actors -> multimap **/
16 typedef std::unordered_multimap<simgrid::s4u::Host*, simgrid::s4u::ActorPtr> host_to_actors_map_t;
17 host_to_actors_map_t host_to_actors;
19 /** Each actor gets assigned to exactly one host -> map **/
20 std::map<simgrid::s4u::ActorPtr, simgrid::s4u::Host*> actor_to_host;
22 void assign(simgrid::s4u::ActorPtr actor, simgrid::s4u::Host* host)
24 /* Remove "actor" from its old host -> get all elements that have the current host as key **/
25 auto range = host_to_actors.equal_range(/* current host */actor_to_host[actor]);
26 for (auto it = range.first; it != range.second; it++) {
27 if (it->second == actor) {
28 host_to_actors.erase(it); // unassign this actor
33 actor_to_host[actor] = host;
34 host_to_actors.insert({host, actor});
37 simgrid::s4u::Host* get_host(simgrid::s4u::ActorPtr actor) { return actor_to_host[actor]; }
39 unsigned int count_actors(simgrid::s4u::Host* host)
41 return host_to_actors.count(host); // TODO This is linear in the size of the map. Maybe replace by constant lookup through another map?
44 void for_each_actor(simgrid::s4u::Host* host, std::function<void(simgrid::s4u::ActorPtr)> callback)
46 auto range = host_to_actors.equal_range(host);
50 [&callback](host_to_actors_map_t::value_type& x) { callback(x.second); }
55 class XBT_PRIVATE LoadBalancer
58 std::map</*proc id*/int, double> actor_computation;
64 void assign(simgrid::s4u::ActorPtr actor, simgrid::s4u::Host* host);
67 * FIXME These are functions used for testing and should be re-written or removed
69 simgrid::s4u::Host* get_mapping();
70 void record_actor_computation(simgrid::s4u::ActorPtr actor, double load);