From 06b0d2707f37e788c6d54a8fb49ceb4f9ec8ceba Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 19 Jan 2011 11:58:01 +0100 Subject: [PATCH 01/16] Change default values. exit_on_close is now enabled by default, and no limits are given for stopping the simulation. --- options.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/options.cpp b/options.cpp index 89f8b18..fd9da4e 100644 --- a/options.cpp +++ b/options.cpp @@ -53,11 +53,10 @@ namespace opt { double min_iter_duration = 1.0; // Parameters for the end of the simulation - // fixme: find better defaults - unsigned lb_maxiter = 10; + unsigned lb_maxiter = 0; unsigned comp_maxiter = 0; double time_limit = 0; - bool exit_on_close = false; + bool exit_on_close = true; // Named parameters lists loba_algorithms_type loba_algorithms; -- 2.39.5 From 4fe47748b018bd1d159839fe9e2bb6685a895e85 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 21 Jan 2011 15:23:15 +0100 Subject: [PATCH 02/16] Makefile: improve rules for target "full". Do not build simple_async, and "make -j" should now work correctly. --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 127476b..8a6bff4 100644 --- a/Makefile +++ b/Makefile @@ -56,8 +56,11 @@ TARGETS := $(DEFAULT_TARGETS) \ all: $(DEFAULT_TARGETS) full: - $(MAKE) $(FLAVOURED_LOBA) - $(MAKE) $(TARGETS) + @for target in $(FLAVOURED_LOBA); do \ + echo $(MAKE) "$$target"; \ + $(MAKE) "$$target"; \ + done + $(MAKE) $(DEFAULT_TARGETS) clean: $(RM) core core.[0-9]* vgcore.[0-9]* -- 2.39.5 From 02bc7d3657348548782811722d73a8d06bdc4afc Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 21 Jan 2011 15:25:05 +0100 Subject: [PATCH 03/16] Makefile: add a rule to generate xml files conforming to the latest dtd. --- Makefile | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8a6bff4..2760531 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,14 @@ FLAVOURED_LOBA := loba-dev loba-stable TARGETS := $(DEFAULT_TARGETS) \ simple_async -.PHONY: all full clean realclean $(FLAVOURED_LOBA) +XML_FILES = \ + Dep.xml Plat.xml \ + platform.xml deployment.xml simple_async.xml \ + cluster1000.xml + +XML_DEV_FILES = $(XML_FILES:%.xml=%_dev.xml) + +.PHONY: all full xml clean realclean $(FLAVOURED_LOBA) all: $(DEFAULT_TARGETS) @@ -60,7 +67,9 @@ full: echo $(MAKE) "$$target"; \ $(MAKE) "$$target"; \ done - $(MAKE) $(DEFAULT_TARGETS) + $(MAKE) xml $(DEFAULT_TARGETS) + +xml: $(XML_DEV_FILES) clean: $(RM) core core.[0-9]* vgcore.[0-9]* @@ -72,10 +81,14 @@ clean: realclean: clean $(RM) $(FLAVOURED_LOBA) + $(RM) $(XML_DEV_FILES) $(RM) *~ %.d: %.cpp ; $(MAKEDEPEND.CXX) +%_dev.xml: %.xml + sed '/DOCTYPE/s,simgrid.dtd,http://simgrid.gforge.inria.fr/&,' $< > $@ + $(FLAVOURED_LOBA): $(MAKE) clean $(MAKE) SIMGRID_INSTALL_DIR=./simgrid-$(patsubst loba-%,%,$@) loba -- 2.39.5 From 154e14a116d8937ffbab194594ba2b744fcc4330 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 21 Jan 2011 16:57:04 +0100 Subject: [PATCH 04/16] Experimental tracing support. --- communicator.cpp | 4 ++++ main.cpp | 6 ++++++ process.cpp | 2 ++ tracing.h | 12 ++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 tracing.h diff --git a/communicator.cpp b/communicator.cpp index 90cf990..7784a48 100644 --- a/communicator.cpp +++ b/communicator.cpp @@ -9,6 +9,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(comm); #include "misc.h" #include "options.h" +#include "tracing.h" #include "communicator.h" @@ -79,6 +80,9 @@ void communicator::send(const char* dest, message* msg) if (msg->get_type() == message::LOAD) msg_size += opt::comm_cost(msg->get_amount()); m_task_t task = MSG_task_create("message", 0.0, msg_size, msg); + TRACE_msg_set_task_category(task, + msg->get_type() == message::LOAD ? + TRACE_CAT_DATA : TRACE_CAT_CTRL); msg_comm_t comm = MSG_task_isend(task, dest); sent_comm.push_back(comm); } diff --git a/main.cpp b/main.cpp index 92e4882..b5ab711 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main); #include "options.h" #include "process.h" #include "timer.h" +#include "tracing.h" #include "version.h" namespace { @@ -196,6 +197,11 @@ int main(int argc, char* argv[]) MSG_launch_application(opt::deployment_file.c_str()); } + // Register tracing categories + TRACE_category(TRACE_CAT_COMP); + TRACE_category(TRACE_CAT_CTRL); + TRACE_category(TRACE_CAT_DATA); + exit_status = EXIT_FAILURE_SIMU; // ===== // Launch the MSG simulation. diff --git a/process.cpp b/process.cpp index 80fd618..03c1734 100644 --- a/process.cpp +++ b/process.cpp @@ -11,6 +11,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(proc); #include "misc.h" #include "options.h" +#include "tracing.h" #include "process.h" @@ -196,6 +197,7 @@ void process::compute() if (load > 0.0) { double flops = opt::comp_cost(load); m_task_t task = MSG_task_create("computation", flops, 0.0, NULL); + TRACE_msg_set_task_category(task, TRACE_CAT_COMP); DEBUG2("compute %g flop%s", flops, ESSE(flops)); MSG_task_execute(task); comp += flops; diff --git a/tracing.h b/tracing.h new file mode 100644 index 0000000..f283465 --- /dev/null +++ b/tracing.h @@ -0,0 +1,12 @@ +#ifndef TRACING_H +#define TRACING_H + +#define TRACE_CAT_COMP "comp_task" +#define TRACE_CAT_CTRL "ctrl_mesg" +#define TRACE_CAT_DATA "data_mesg" + +#endif // !TRACING_H + +// Local variables: +// mode: c++ +// End: -- 2.39.5 From 7c16f589594608d2269921e11d5298c09fe2512b Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 24 Jan 2011 18:01:49 +0100 Subject: [PATCH 05/16] Move final outputs into destructor. --- process.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/process.cpp b/process.cpp index 03c1734..acd7aed 100644 --- a/process.cpp +++ b/process.cpp @@ -64,6 +64,17 @@ process::process(int argc, char* argv[]) process::~process() { total_load_exit += load; + if (opt::bookkeeping) { + INFO4("Final load after %d:%d iterations: %g ; expected: %g", + lb_iter, comp_iter, load, expected_load); + } else { + INFO2("Final load after %d iterations: %g", + lb_iter, load); + if (lb_iter != comp_iter) + WARN2("lb_iter (%d) and comp_iter (%d) differ!", + lb_iter, comp_iter); + } + VERB1("Total computation for this process: %g", comp); } int process::run() @@ -161,16 +172,6 @@ int process::run() */ VERB0("Done."); - if (opt::bookkeeping) { - INFO4("Final load after %d:%d iterations: %g ; expected: %g", - lb_iter, comp_iter, load, expected_load); - } else { - INFO2("Final load after %d iterations: %g", - lb_iter, load); - if (lb_iter != comp_iter) - WARN2("lb_iter (%d) and comp_iter (%d) differ!", - lb_iter, comp_iter); - } return 0; } -- 2.39.5 From 69ea6636935b8fae72f3915d521eeb2b12aabd34 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 24 Jan 2011 18:03:43 +0100 Subject: [PATCH 06/16] Use verbose level for logging results of final checks on total load. --- main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index b5ab711..5da797a 100644 --- a/main.cpp +++ b/main.cpp @@ -79,7 +79,7 @@ static void check_for_lost_load() CRITICAL2("Lost load at exit! %g (%g%%) <============", lost, lost_ratio); else - DEBUG2("Total load at exit looks good: %g (%g%%)", lost, lost_ratio); + VERB2("Total load at exit looks good: %g (%g%%)", lost, lost_ratio); double total_running = process::get_total_load_running(); double running_ratio = 100.0 * total_running / total_init; @@ -90,7 +90,7 @@ static void check_for_lost_load() CRITICAL2("Remaining running load at exit! %g (%g%%) <============", total_running, running_ratio); else - DEBUG2("Running load at exit looks good: %g (%g%%)", + VERB2("Running load at exit looks good: %g (%g%%)", total_running, running_ratio); } -- 2.39.5 From 825abbb3bde6c35ab1d1cdfba25fba4be5dcea2f Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 24 Jan 2011 18:04:05 +0100 Subject: [PATCH 07/16] Define class statistics for computing sum, mean, and standard deviation. --- Makefile | 1 + main.cpp | 62 ++++++++--------------------------------- statistics.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ statistics.h | 33 ++++++++++++++++++++++ 4 files changed, 120 insertions(+), 51 deletions(-) create mode 100644 statistics.cpp create mode 100644 statistics.h diff --git a/Makefile b/Makefile index 2760531..2b0df87 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ SRC.loba := main.cpp \ neighbor.cpp \ options.cpp \ process.cpp \ + statistics.cpp \ version.cpp SRC.simple_async := simple_async.cpp diff --git a/main.cpp b/main.cpp index 5da797a..3a47b92 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,6 @@ -#include -#include #include -#include #include -#include #include -#include #include #include @@ -24,6 +19,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main); #include "misc.h" #include "options.h" #include "process.h" +#include "statistics.h" #include "timer.h" #include "tracing.h" #include "version.h" @@ -38,14 +34,9 @@ namespace { EXIT_FAILURE_CLEAN = 0x08, // error at cleanup }; - std::vector comps; - double comp_total; - double comp_avg; - double comp_stddev; + struct statistics comps; + struct statistics loads; - std::vector loads; - double load_avg; - double load_stddev; } static int simulation_main(int argc, char* argv[]) @@ -55,8 +46,8 @@ static int simulation_main(int argc, char* argv[]) try { proc = opt::loba_algorithms.new_instance(opt::loba_algo, argc, argv); result = proc->run(); - comps.push_back(proc->get_comp()); - loads.push_back(proc->get_load()); + comps.push(proc->get_comp()); + loads.push(proc->get_load()); delete proc; } catch (std::invalid_argument& e) { @@ -94,38 +85,10 @@ static void check_for_lost_load() total_running, running_ratio); } -static void statistics(const std::vector& vec, - double* sum, double* avg, double* stddev) -{ - using std::tr1::bind; - using std::tr1::placeholders::_1; - - unsigned n = vec.size(); - double vec_sum = std::accumulate(vec.begin(), vec.end(), 0.0); - double vec_avg = vec_sum / n; - - if (sum) - *sum = vec_sum; - if (avg) - *avg = vec_avg; - - if (stddev) { - std::vector diff(vec); - std::transform(diff.begin(), diff.end(), diff.begin(), - bind(std::minus(), _1, vec_avg)); - double epsilon = std::accumulate(diff.begin(), diff.end(), 0.0); - double square_sum = std::inner_product(diff.begin(), diff.end(), - diff.begin(), 0.0); - double variance = (square_sum - (epsilon * epsilon) / n) / n; - *stddev = sqrt(variance); - } -} - -static void compute_metrics() -{ - statistics(comps, &comp_total, &comp_avg, &comp_stddev); - statistics(loads, NULL, &load_avg, &load_stddev); -} +#define PR_STATS(descr, st) \ + INFO5("| %.*s: %g / %g / %g", 39, \ + descr " total/avg./stddev. at exit.........................", \ + st.get_sum(), st.get_avg(), st.get_stddev()) int main(int argc, char* argv[]) { @@ -235,12 +198,9 @@ int main(int argc, char* argv[]) if (simulated_time >= 0.0) { simulation_time.stop(); check_for_lost_load(); - compute_metrics(); INFO0(",----[ Results ]"); - INFO2("| Load avg./stddev. at exit..............: %g / %g", - load_avg, load_stddev); - INFO3("| Computation total/avg./stddev. at exit.: %g / %g / %g", - comp_total, comp_avg, comp_stddev); + PR_STATS("Load", loads); + PR_STATS("Computation", comps); INFO1("| Total simulated time...................: %g", simulated_time); INFO1("| Total simulation time..................: %g", simulation_time.duration()); diff --git a/statistics.cpp b/statistics.cpp new file mode 100644 index 0000000..77f415f --- /dev/null +++ b/statistics.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include + +#include "statistics.h" + +statistics::statistics() + : up2date(false) +{ +} + +void statistics::reset() +{ + values.clear(); + up2date = false; +} + +void statistics::push(double val) +{ + values.push_back(val); + up2date = false; +} + +size_t statistics::get_count() +{ + return values.size(); +} + +double statistics::get_sum() +{ + update(); + return sum; +} + +double statistics::get_avg() +{ + update(); + return avg; +} + +double statistics::get_stddev() +{ + update(); + return stddev; +} + +void statistics::update() +{ + if (up2date) + return; + + if (values.empty()) { + sum = 0.0; + avg = stddev = 0.0 / 0.0; + } + + using std::tr1::bind; + using std::tr1::placeholders::_1; + + unsigned n = values.size(); + sum = std::accumulate(values.begin(), values.end(), 0.0); + avg = sum / n; + + std::vector diff(values); + std::transform(diff.begin(), diff.end(), diff.begin(), + bind(std::minus(), _1, avg)); + double epsilon = std::accumulate(diff.begin(), diff.end(), 0.0); + double square_sum = std::inner_product(diff.begin(), diff.end(), + diff.begin(), 0.0); + double variance = (square_sum - (epsilon * epsilon) / n) / n; + stddev = sqrt(variance); + + up2date = true; +} diff --git a/statistics.h b/statistics.h new file mode 100644 index 0000000..2978747 --- /dev/null +++ b/statistics.h @@ -0,0 +1,33 @@ +#ifndef STATISTICS_H +#define STATISTICS_H + +#include + +class statistics { +public: + statistics(); + + void reset(); + void push(double value); + + size_t get_count(); + double get_sum(); + double get_avg(); + double get_stddev(); + +private: + bool up2date; + + std::vector values; + double sum; + double avg; + double stddev; + + void update(); +}; + +#endif // !STATISTICS_H + +// Local variables: +// mode: c++ +// End: -- 2.39.5 From ea9e469b934dd81706ec3f727156b9057e4cf2bb Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 10:14:22 +0100 Subject: [PATCH 08/16] Rename process::send() -> process::send_all(). --- process.cpp | 6 +++--- process.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/process.cpp b/process.cpp index acd7aed..a0447de 100644 --- a/process.cpp +++ b/process.cpp @@ -36,7 +36,7 @@ process::process(int argc, char* argv[]) comp = 0.0; - prev_load_broadcast = -1; // force sending of load on first send() + prev_load_broadcast = -1; // force sending of load on first send_all() expected_load = load; total_load_running += load; total_load_init += load; @@ -109,7 +109,7 @@ int process::run() lb_load() = ld; // send load information, and load (data) if any - send(); + send_all(); if (load > 0.0) { ++comp_iter; compute(); @@ -248,7 +248,7 @@ void process::send1_bookkeeping(neighbor& nb) comm.send(nb.get_data_mbox(), new message(message::LOAD, load_to_send)); } -void process::send() +void process::send_all() { using std::tr1::bind; using std::tr1::placeholders::_1; diff --git a/process.h b/process.h index fb1fe3f..a197e9a 100644 --- a/process.h +++ b/process.h @@ -94,7 +94,7 @@ private: // Send procedures, with helpers for bookkeeping mode or not void send1_no_bookkeeping(neighbor& nb); void send1_bookkeeping(neighbor& nb); - void send(); + void send_all(); // Returns true if there remains neighbors to listen for bool may_receive() { return ctrl_close_pending || data_close_pending; } -- 2.39.5 From 29d6013f6a85f43d958add37f8317cf038cf335b Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 10:21:01 +0100 Subject: [PATCH 09/16] Delete process::sum_of_to_send(). --- README | 4 +--- process.cpp | 12 ------------ process.h | 3 --- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/README b/README index ff8c438..37c51be 100644 --- a/README +++ b/README @@ -98,9 +98,7 @@ Pour ajouter un nouvel algorithme d'équilibrage 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, - éventuellement à l'aide de la méthode process::sum_of_to_send() - qui clacule cette somme. + - retourne la somme des quantités définies avec set_to_send. 2. Ajouter l'algorithme dans la liste des options. Dans options.cpp : - faire le #include adéquat ; diff --git a/process.cpp b/process.cpp index a0447de..cd11433 100644 --- a/process.cpp +++ b/process.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -175,17 +174,6 @@ int process::run() return 0; } -double process::sum_of_to_send() const -{ - using std::tr1::bind; - using std::tr1::placeholders::_1; - using std::tr1::placeholders::_2; - - return std::accumulate(neigh.begin(), neigh.end(), 0.0, - bind(std::plus(), - _1, bind(&neighbor::get_to_send, _2))); -} - double process::load_balance(double /*my_load*/) { if (lb_iter == 1) // warn only once diff --git a/process.h b/process.h index a197e9a..3978e3a 100644 --- a/process.h +++ b/process.h @@ -39,9 +39,6 @@ protected: pneigh_type pneigh; // list of pointers to neighbors that // we are free to reorder - // Returns the sum of "to_send" for all neighbors. - double sum_of_to_send() const; - // 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, -- 2.39.5 From 1bba96ae977208a57bd80c7011c2033435a64d44 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 10:26:29 +0100 Subject: [PATCH 10/16] Rename process::load -> process::real_load. --- main.cpp | 2 +- process.cpp | 48 ++++++++++++++++++++++++------------------------ process.h | 8 ++++---- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/main.cpp b/main.cpp index 3a47b92..ccd11bd 100644 --- a/main.cpp +++ b/main.cpp @@ -47,7 +47,7 @@ static int simulation_main(int argc, char* argv[]) proc = opt::loba_algorithms.new_instance(opt::loba_algo, argc, argv); result = proc->run(); comps.push(proc->get_comp()); - loads.push(proc->get_load()); + loads.push(proc->get_real_load()); delete proc; } catch (std::invalid_argument& e) { diff --git a/process.cpp b/process.cpp index cd11433..6d791bd 100644 --- a/process.cpp +++ b/process.cpp @@ -20,7 +20,7 @@ double process::total_load_exit = 0.0; process::process(int argc, char* argv[]) { - if (argc < 2 || !(std::istringstream(argv[1]) >> load)) + if (argc < 2 || !(std::istringstream(argv[1]) >> real_load)) throw std::invalid_argument("bad or missing initial load parameter"); neigh.assign(argv + 2, argv + argc); @@ -36,9 +36,9 @@ process::process(int argc, char* argv[]) comp = 0.0; prev_load_broadcast = -1; // force sending of load on first send_all() - expected_load = load; - total_load_running += load; - total_load_init += load; + expected_load = real_load; + total_load_running += real_load; + total_load_init += real_load; ctrl_close_pending = data_close_pending = neigh.size(); close_received = false; @@ -62,13 +62,13 @@ process::process(int argc, char* argv[]) process::~process() { - total_load_exit += load; + total_load_exit += real_load; if (opt::bookkeeping) { INFO4("Final load after %d:%d iterations: %g ; expected: %g", - lb_iter, comp_iter, load, expected_load); + lb_iter, comp_iter, real_load, expected_load); } else { INFO2("Final load after %d iterations: %g", - lb_iter, load); + lb_iter, real_load); if (lb_iter != comp_iter) WARN2("lb_iter (%d) and comp_iter (%d) differ!", lb_iter, comp_iter); @@ -79,7 +79,7 @@ process::~process() int process::run() { double next_iter_after_date = 0.0; - INFO1("Initial load: %g", load); + INFO1("Initial load: %g", real_load); VERB0("Starting..."); comp_iter = lb_iter = 0; while (true) { @@ -95,10 +95,10 @@ int process::run() if (opt::log_rate && lb_iter % opt::log_rate == 0) { if (opt::bookkeeping) INFO4("(%u:%u) current load: %g ; expected: %g", - lb_iter, comp_iter, load, expected_load); + lb_iter, comp_iter, real_load, expected_load); else INFO2("(%u) current load: %g", - lb_iter, load); + lb_iter, real_load); } ld -= load_balance(ld); @@ -109,7 +109,7 @@ int process::run() // send load information, and load (data) if any send_all(); - if (load > 0.0) { + if (real_load > 0.0) { ++comp_iter; compute(); } @@ -130,7 +130,7 @@ int process::run() // block on receiving unless there is something to compute or // to send double timeout; - if (load != 0 || lb_load() != prev_load_broadcast) + if (real_load != 0 || lb_load() != prev_load_broadcast) timeout = 0.0; else if (opt::min_iter_duration) timeout = opt::min_iter_duration; @@ -145,7 +145,7 @@ int process::run() } // have no load and cannot receive anything - if (load == 0.0 && !may_receive()) { + if (real_load == 0.0 && !may_receive()) { VERB0("I'm a poor lonesome process, and I have no load..."); break; } @@ -183,8 +183,8 @@ double process::load_balance(double /*my_load*/) void process::compute() { - if (load > 0.0) { - double flops = opt::comp_cost(load); + if (real_load > 0.0) { + double flops = opt::comp_cost(real_load); m_task_t task = MSG_task_create("computation", flops, 0.0, NULL); TRACE_msg_set_task_category(task, TRACE_CAT_COMP); DEBUG2("compute %g flop%s", flops, ESSE(flops)); @@ -198,8 +198,8 @@ void process::compute() void process::send1_no_bookkeeping(neighbor& nb) { - if (load != prev_load_broadcast) - comm.send(nb.get_ctrl_mbox(), new message(message::INFO, load)); + if (real_load != prev_load_broadcast) + comm.send(nb.get_ctrl_mbox(), new message(message::INFO, real_load)); double load_to_send = nb.get_to_send(); if (load_to_send > 0.0) { comm.send(nb.get_data_mbox(), new message(message::LOAD, load_to_send)); @@ -223,14 +223,14 @@ void process::send1_bookkeeping(neighbor& nb) } else { new_debt = nb.get_debt(); } - if (load <= new_debt) { - load_to_send = load; + if (real_load <= new_debt) { + load_to_send = real_load; nb.set_debt(new_debt - load_to_send); - load = 0.0; + real_load = 0.0; } else { load_to_send = new_debt; nb.set_debt(0.0); - load -= load_to_send; + real_load -= load_to_send; } if (load_to_send > 0.0) comm.send(nb.get_data_mbox(), new message(message::LOAD, load_to_send)); @@ -248,7 +248,7 @@ void process::send_all() } else { std::for_each(neigh.begin(), neigh.end(), bind(&process::send1_no_bookkeeping, this, _1)); - prev_load_broadcast = load; + prev_load_broadcast = real_load; } comm.flush(false); } @@ -271,7 +271,7 @@ void process::receive(double timeout) break; case message::LOAD: { double ld = msg->get_amount(); - load += ld; + real_load += ld; if (finalizing) total_load_running -= ld; break; @@ -303,7 +303,7 @@ void process::finalize() using std::tr1::placeholders::_1; finalizing = true; - total_load_running -= load; + total_load_running -= real_load; DEBUG2("send CLOSE to %lu neighbor%s", (unsigned long )neigh.size(), ESSE(neigh.size())); diff --git a/process.h b/process.h index 3978e3a..8f96fd8 100644 --- a/process.h +++ b/process.h @@ -28,7 +28,7 @@ public: virtual ~process(); double get_comp() const { return comp; } - double get_load() const { return load; } + double get_real_load() const { return real_load; } int run(); @@ -74,14 +74,14 @@ private: double prev_load_broadcast; // used to ensure that we do not send // a same information messages - double load; // current load + double real_load; // current load double expected_load; // expected load in bookkeeping mode - double& lb_load() { return opt::bookkeeping ? expected_load : load; } + double& lb_load() { return opt::bookkeeping ? expected_load : real_load; } // The load balancing algorithm comes here... // Parameter "my_load" is the load to take into account for myself - // (may be load or expected load). + // (may be real load or expected load). // Returns the total load sent to neighbors. virtual double load_balance(double my_load); -- 2.39.5 From 6f372378ef955f9fbc8af757568a417e3d348ff3 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 10:35:51 +0100 Subject: [PATCH 11/16] Define process::get_load() and set_load() instead of lb_load(). --- process.cpp | 6 +++--- process.h | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/process.cpp b/process.cpp index 6d791bd..a74b114 100644 --- a/process.cpp +++ b/process.cpp @@ -83,7 +83,7 @@ int process::run() VERB0("Starting..."); comp_iter = lb_iter = 0; while (true) { - double ld = lb_load(); + double ld = get_load(); if (ld > 0.0) { double now = MSG_get_clock(); if (now < next_iter_after_date) @@ -105,7 +105,7 @@ int process::run() print_loads(true, xbt_log_priority_debug); } - lb_load() = ld; + set_load(ld); // send load information, and load (data) if any send_all(); @@ -130,7 +130,7 @@ int process::run() // block on receiving unless there is something to compute or // to send double timeout; - if (real_load != 0 || lb_load() != prev_load_broadcast) + if (real_load != 0 || get_load() != prev_load_broadcast) timeout = 0.0; else if (opt::min_iter_duration) timeout = opt::min_iter_duration; diff --git a/process.h b/process.h index 8f96fd8..1374bf4 100644 --- a/process.h +++ b/process.h @@ -39,6 +39,11 @@ protected: pneigh_type pneigh; // list of pointers to neighbors that // we are free to reorder + // Get and set current load, which may be real load, or expected + // load if opt::bookkeeping is true. + double get_load() const; + void set_load(double load); + // 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, @@ -77,8 +82,6 @@ private: double real_load; // current load double expected_load; // expected load in bookkeeping mode - double& lb_load() { return opt::bookkeeping ? expected_load : real_load; } - // 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). @@ -107,6 +110,24 @@ private: void finalize(); }; +inline +double process::get_load() const +{ + if (opt::bookkeeping) + return expected_load; + else + return real_load; +} + +inline +void process::set_load(double load) +{ + if (opt::bookkeeping) + expected_load = load; + else + real_load = load; +} + #endif // !PROCESS_H // Local variables: -- 2.39.5 From 7541e1aae11493fc2da5479f385154e78714397f Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 11:33:39 +0100 Subject: [PATCH 12/16] Cosmetics: add spaces around operators, and other whitespace cleanups. --- loba_fairstrategy.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/loba_fairstrategy.cpp b/loba_fairstrategy.cpp index 4573776..7495655 100644 --- a/loba_fairstrategy.cpp +++ b/loba_fairstrategy.cpp @@ -11,9 +11,9 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba); */ class compare { -public : - bool operator()(const neighbor*a, const neighbor*b) { - return a->get_load()>b->get_load(); +public: + bool operator()(const neighbor*a, const neighbor*b) { + return a->get_load() > b->get_load(); } }; @@ -23,20 +23,20 @@ double loba_fairstrategy::load_balance(double my_load) print_loads_p(); - double sum_sent=0; - bool found=true; - - while(found) { - found=false; + double sum_sent = 0; + bool found = true; + + while (found) { + found = false; for (unsigned i = 0 ; i < pneigh.size() ; ++i) { double l = pneigh[i]->get_load(); if (l >= my_load) continue; - if (l < my_load+2) { - found=true; + if (l < my_load + 2) { + found = true; pneigh[i]->add_load(1); pneigh[i]->add_to_send(1); - INFO1("sent to %s",pneigh[i]->get_name()); + INFO1("sent to %s", pneigh[i]->get_name()); my_load--; sum_sent++; } -- 2.39.5 From 3bbce140c762cb8f3aaf9526e835aaa72cdec632 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 11:55:12 +0100 Subject: [PATCH 13/16] Partially revert "modif simple" This reverts commit ffea735548f5d4940dae32d8071a2676f6716ad0. Conflicts: loba_simple.cpp --- loba_simple.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loba_simple.cpp b/loba_simple.cpp index 5702fba..26622c8 100644 --- a/loba_simple.cpp +++ b/loba_simple.cpp @@ -29,7 +29,7 @@ double loba_simple::load_balance(double my_load) } if (imin != -1) { // found someone - double balance = (my_load - min) / 2; + 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); -- 2.39.5 From 61856fb5422e392a34106b1c698cf5d67a9647b4 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 12:00:43 +0100 Subject: [PATCH 14/16] Improve warning message. --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index ccd11bd..4e8864c 100644 --- a/main.cpp +++ b/main.cpp @@ -65,7 +65,7 @@ static void check_for_lost_load() double lost_ratio = 100.0 * lost / total_init; if (lost_ratio < -opt::load_ratio_threshold) CRITICAL2("Gained load at exit! %g (%g%%) <============", - lost, lost_ratio); + -lost, -lost_ratio); else if (lost_ratio > opt::load_ratio_threshold) CRITICAL2("Lost load at exit! %g (%g%%) <============", lost, lost_ratio); -- 2.39.5 From 9380d7c32eed77c15a12068a4c37d78705271837 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 12:05:47 +0100 Subject: [PATCH 15/16] Bug fix: only send to a lesser loaded neighbor! --- TODO | 4 ++++ loba_fairstrategy.cpp | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 2083dab..42ec277 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,7 @@ +* BUG + ./loba cluster1000.xml -N64 -L100 -i100 -a fair -T hcube + leads to deadlock + * review receive with timeout. * verify bookkeeping version. diff --git a/loba_fairstrategy.cpp b/loba_fairstrategy.cpp index 7495655..9942fac 100644 --- a/loba_fairstrategy.cpp +++ b/loba_fairstrategy.cpp @@ -29,10 +29,7 @@ double loba_fairstrategy::load_balance(double my_load) while (found) { found = false; for (unsigned i = 0 ; i < pneigh.size() ; ++i) { - double l = pneigh[i]->get_load(); - if (l >= my_load) - continue; - if (l < my_load + 2) { + if (pneigh[i]->get_load() <= my_load - 2) { found = true; pneigh[i]->add_load(1); pneigh[i]->add_to_send(1); -- 2.39.5 From d772022386ea3878a949578f097b23571e241b75 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 25 Jan 2011 13:01:56 +0100 Subject: [PATCH 16/16] Use debug log level in loba_fairstrategy. --- loba_fairstrategy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loba_fairstrategy.cpp b/loba_fairstrategy.cpp index 9942fac..c372f74 100644 --- a/loba_fairstrategy.cpp +++ b/loba_fairstrategy.cpp @@ -21,7 +21,7 @@ double loba_fairstrategy::load_balance(double my_load) { std::sort(pneigh.begin(), pneigh.end(), compare()); - print_loads_p(); + print_loads_p(false, xbt_log_priority_debug); double sum_sent = 0; bool found = true; @@ -33,7 +33,7 @@ double loba_fairstrategy::load_balance(double my_load) found = true; pneigh[i]->add_load(1); pneigh[i]->add_to_send(1); - INFO1("sent to %s", pneigh[i]->get_name()); + DEBUG1("sent to %s", pneigh[i]->get_name()); my_load--; sum_sent++; } -- 2.39.5