From: Arnaud Giersch Date: Fri, 25 Feb 2011 16:19:31 +0000 (+0100) Subject: Implement random initial load distribution. X-Git-Tag: v0.1~93 X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/commitdiff_plain/15ace044d0d9e82ef744e22cf84168771e669678?ds=inline;hp=-c Implement random initial load distribution. Using drand48() for an uniform distribution. --- 15ace044d0d9e82ef744e22cf84168771e669678 diff --git a/TODO b/TODO index f95d336..d59eb3c 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,3 @@ -* Implement some random initial distribution of load - Options -r seed, -R [algo ?] - * Support heterogeneous platforms? Not sure yet. Should be doable if each process also sends its speed to its neighbors. diff --git a/deployment.cpp b/deployment.cpp index 70bd8b3..705c1ea 100644 --- a/deployment.cpp +++ b/deployment.cpp @@ -1,5 +1,10 @@ +#include +#include +#include #include +#include #include +#include #include #include #include @@ -17,6 +22,7 @@ void MY_launch_application() deployment_generator* gen; gen = opt::topologies.new_instance(opt::auto_depl::topology); gen->generate(); + gen->distribute_load(); gen->deploy(); delete gen; } @@ -24,7 +30,6 @@ void MY_launch_application() deployment_generator::deployment_generator() : hosts(opt::auto_depl::nhosts) { - set_load(0, opt::auto_depl::load); } void deployment_generator::set_load(int host, double load) @@ -43,6 +48,26 @@ void deployment_generator::set_link(int host1, int host2) set_neighbor(host2, host1); } +void deployment_generator::distribute_load() +{ + using std::tr1::bind; + using std::tr1::placeholders::_1; + + if (!opt::auto_depl::random_distribution) { + set_load(0, opt::auto_depl::load); + return; + } + srand48(opt::auto_depl::random_seed); + std::vector loads(hosts.size()); + std::generate(loads.begin(), loads.end(), drand48); + double factor = opt::auto_depl::load / + std::accumulate(loads.begin(), loads.end(), 0.0); + std::transform(loads.begin(), loads.end(), loads.begin(), + bind(std::multiplies(), _1, factor)); + for (unsigned i = 0 ; i < hosts.size() ; ++i) + set_load(i, loads[i]); +} + void deployment_generator::deploy() { xbt_dynar_t args = xbt_dynar_new(sizeof(const char*), NULL); diff --git a/deployment.h b/deployment.h index d308ff6..b3fa43a 100644 --- a/deployment.h +++ b/deployment.h @@ -17,6 +17,7 @@ public: void set_link(int host1, int host2); virtual void generate() = 0; + void distribute_load(); void deploy(); private: diff --git a/options.cpp b/options.cpp index 2994640..96542f6 100644 --- a/options.cpp +++ b/options.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -47,6 +48,8 @@ namespace opt { std::string topology("clique"); unsigned nhosts = 0; double load = 0.0; + bool random_distribution = false; + unsigned long random_seed = 0; } // Load balancing algorithm @@ -211,7 +214,7 @@ bool opt::parse_args(int* argc, char* argv[]) int c; opterr = 0; while ((c = getopt(*argc, argv, - "a:bc:C:d:D:ehi:I:l:L:m:M:N:s:S:t:T:vV")) != -1) { + "a:bc:C:d:D:ehi:I:l:L:m:M:N:r:Rs:S:t:T:vV")) != -1) { switch (c) { case 'a': opt::loba_algo = optarg; @@ -274,6 +277,13 @@ bool opt::parse_args(int* argc, char* argv[]) case 'N': PARSE_ARG(opt::auto_depl::nhosts); break; + case 'r': + PARSE_ARG(opt::auto_depl::random_seed); + break; + case 'R': + opt::auto_depl::random_distribution = + !opt::auto_depl::random_distribution; + break; case 's': PARSE_ARG(opt::min_lb_iter_duration); break; @@ -330,6 +340,9 @@ bool opt::parse_args(int* argc, char* argv[]) result = false; } + if (!opt::auto_depl::random_seed) + opt::auto_depl::random_seed = time(NULL); + return result; } @@ -350,6 +363,10 @@ void opt::print() "auto")); DESCR("- initial load", "%s", h.val_or_string(auto_depl::load, "auto")); + DESCR("- random initial load distribution", "%s", + h.on_off(auto_depl::random_distribution)); + DESCR("- random seed", "%s", + h.val_or_string(auto_depl::random_seed, "time based")); } else { DESCR("deployment file", "\"%s\"", deployment_file.c_str()); } @@ -424,6 +441,13 @@ void opt::usage() std::clog << o("-N value") << "number of hosts to use with auto deployment, 0 for max." << " [" << opt::auto_depl::nhosts << "]\n"; + std::clog << o("-R") + << "toggle random initial load distribution" + << " [" << opt_helper::on_off(opt::auto_depl::random_distribution) + << "]\n"; + std::clog << o("-r value") + << "random seed, 0 for using it on time()" + << " [" << opt::auto_depl::random_seed << "]\n"; std::clog << "\nLoad balancing algorithm\n"; std::clog << o("-a name") << "load balancing algorithm" diff --git a/options.h b/options.h index 0abec0f..dee2953 100644 --- a/options.h +++ b/options.h @@ -34,6 +34,8 @@ namespace opt { extern std::string topology; extern unsigned nhosts; extern double load; + extern bool random_distribution; + extern unsigned long random_seed; } // Load balancing algorithm