2 #ifndef HAVE_SG_PLUGIN_LB
3 #define HAVE_SG_PLUGIN_LB
7 namespace loadbalancer {
13 /** Each host can have an arbitrary number of actors -> multimap **/
14 typedef std::unordered_multimap<simgrid::s4u::Host*, simgrid::s4u::ActorPtr> host_to_actors_map_t;
15 host_to_actors_map_t host_to_actors;
17 /** Each actor gets assigned to exactly one host -> map **/
18 std::map<simgrid::s4u::ActorPtr, simgrid::s4u::Host*> actor_to_host;
20 void assign(simgrid::s4u::ActorPtr actor, simgrid::s4u::Host* host)
22 /* Remove "actor" from its old host -> get all elements that have the current host as key **/
23 auto range = host_to_actors.equal_range(/* current host */actor_to_host[actor]);
24 for (auto it = range.first; it != range.second; it++) {
25 if (it->second == actor) {
26 host_to_actors.erase(it); // unassign this actor
31 actor_to_host[actor] = host;
32 host_to_actors.insert({host, actor});
35 simgrid::s4u::Host* get_host(simgrid::s4u::ActorPtr actor) { return actor_to_host[actor]; }
37 unsigned int count_actors(simgrid::s4u::Host* host)
39 return host_to_actors.count(host); // TODO This is linear in the size of the map. Maybe replace by constant lookup through another map?
42 void for_each_actor(simgrid::s4u::Host* host, std::function<void(simgrid::s4u::ActorPtr)> callback)
44 auto range = host_to_actors.equal_range(host);
48 [&callback](host_to_actors_map_t::value_type& x) { callback(x.second); }
55 std::map<int, double> actor_computation;
56 std::map<simgrid::s4u::ActorPtr, simgrid::s4u::Host*> new_mapping;
62 void assign(simgrid::s4u::ActorPtr actor, simgrid::s4u::Host* host);
65 * FIXME These are functions used for testing and should be re-written or removed
67 simgrid::s4u::Host* get_mapping();
68 void record_actor_computation(simgrid::s4u::ActorPtr actor, double load);