- définir une nouvelle classe dérivant de process
- attention, il faut construire le process explicitement
- redéfinir la méthode load_balance qui :
- - reçoit en paramètre la charge à prendre en compte ;
+ - peut récupérer la charge courante avec get_load()
- peut utiliser et éventuellement réordonner le tableau process::pneigh ;
- peut récupérer l'information de charge d'un voisin avec
pneigh[i]->get_load() ;
- définit la charge à envoyer avec
- pneigh[i]->set_to_send(quantité) ;
- - retourne la somme des quantités définies avec set_to_send.
+ send(pneigh[i], quantité) ;
2. Ajouter l'algorithme dans la liste des options. Dans options.cpp :
- faire le #include adéquat ;
}
};
-double loba_fairstrategy::load_balance(double my_load)
+void loba_fairstrategy::load_balance()
{
std::sort(pneigh.begin(), pneigh.end(), compare());
print_loads_p(false, xbt_log_priority_debug);
- double sum_sent = 0;
bool found = true;
while (found) {
found = false;
for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
- if (pneigh[i]->get_load() <= my_load - 2) {
+ if (pneigh[i]->get_load() <= get_load() - 2) {
found = true;
- pneigh[i]->add_load(1);
- pneigh[i]->add_to_send(1);
+ send(pneigh[i], 1);
DEBUG1("sent to %s", pneigh[i]->get_name());
- my_load--;
- sum_sent++;
}
}
}
-
- return sum_sent;
}
// Local variables:
~loba_fairstrategy() { }
private:
- double load_balance(double my_load);
+ void load_balance();
};
#endif //!LOBA_SIMPLE
* load balance with a least-loaded neighbor,
* without breaking the ping-pong condition
*/
-double loba_simple::load_balance(double my_load)
+void loba_simple::load_balance()
{
int imin = -1;
int imax = -1;
- double min = my_load;
+ double min = get_load();
double max = -1.0;
for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
double l = pneigh[i]->get_load();
- if (l >= my_load)
+ if (l >= get_load())
continue;
if (l < min) {
imin = i;
}
if (imin != -1) {
// found someone
- double balance = (my_load - max) / 2;
- DEBUG6("%d:%g %d:%g %g %g", imin, min, imax, max, my_load, balance);
- pneigh[imin]->set_to_send(balance);
- pneigh[imin]->add_load(balance);
- return balance;
- } else {
- return 0.0;
+ double balance = (get_load() - max) / 2;
+ DEBUG6("%d:%g %d:%g %g %g", imin, min, imax, max, get_load(), balance);
+ send(pneigh[imin], balance);
}
}
~loba_simple() { }
private:
- double load_balance(double my_load);
+ void load_balance();
};
#endif //!LOBA_SIMPLE
// Getter and setter for load
double get_load() const { return load; }
void set_load(double amount) { load = amount; }
- void add_load(double amount) { load += amount; }
// Getter and setter for debt
double get_debt() const { return debt; }
// Getter and setter for to_send
double get_to_send() const { return to_send; }
void set_to_send(double amount) { to_send = amount; }
- void add_to_send(double amount) { to_send += amount; }
// Prints its name and load on given category, with given
// priority. If verbose is true, prints debt and to_send too.
VERB0("Starting...");
comp_iter = lb_iter = 0;
while (true) {
- double ld = get_load();
- if (ld > 0.0) {
+ if (get_load() > 0.0) {
double now = MSG_get_clock();
if (now < next_iter_after_date)
MSG_process_sleep(next_iter_after_date - now);
lb_iter, real_load);
}
- ld -= load_balance(ld);
+ load_balance();
print_loads(true, xbt_log_priority_debug);
}
- set_load(ld);
// send load information, and load (data) if any
send_all();
return 0;
}
-double process::load_balance(double /*my_load*/)
+void process::load_balance()
{
if (lb_iter == 1) // warn only once
WARN0("process::load_balance() is a no-op!");
- return 0.0;
}
void process::compute()
}
}
+void process::send(neighbor& nb, double amount)
+{
+ set_load(get_load() - amount);
+ nb.set_to_send(nb.get_to_send() + amount);
+ nb.set_load(nb.get_load() + amount); // fixme: make this optional?
+}
+
void process::send1_no_bookkeeping(neighbor& nb)
{
if (real_load != prev_load_broadcast)
double get_load() const;
void set_load(double load);
+ // Register some amount of load to send to given neighbor.
+ void send(neighbor& nb, double amount);
+ void send(neighbor* nb, double amount) { send(*nb, amount); }
+
// Calls neighbor::print(verbose, logp, cat) for each member of neigh.
void print_loads(bool verbose = false,
e_xbt_log_priority_t logp = xbt_log_priority_info,
double expected_load; // expected load in bookkeeping mode
// The load balancing algorithm comes here...
- // Parameter "my_load" is the load to take into account for myself
- // (may be real load or expected load).
- // Returns the total load sent to neighbors.
- virtual double load_balance(double my_load);
+ virtual void load_balance();
// Virtually do some computation
void compute();