From: Arnaud Giersch Date: Tue, 14 Dec 2010 18:22:16 +0000 (+0100) Subject: Wip++... X-Git-Tag: v0.1~243 X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/commitdiff_plain/d43e446400ac7b65d7d2dd3acd57f8f669484449 Wip++... * sort hosts by name in hostdata * remove old "Calculs" binding * add some stuff for automatic deployment * add cluster1000.xml * rename application.xml -> deployment.xml --- diff --git a/Dep.xml b/Dep.xml index c796848..a48504d 100644 --- a/Dep.xml +++ b/Dep.xml @@ -1,7 +1,7 @@ - + @@ -53,7 +53,7 @@ - + @@ -105,7 +105,7 @@ - + @@ -157,7 +157,7 @@ - + @@ -209,7 +209,7 @@ - + @@ -261,7 +261,7 @@ - + @@ -313,7 +313,7 @@ - + @@ -365,7 +365,7 @@ - + @@ -417,7 +417,7 @@ - + @@ -469,7 +469,7 @@ - + @@ -521,7 +521,7 @@ - + @@ -573,7 +573,7 @@ - + @@ -625,7 +625,7 @@ - + @@ -677,7 +677,7 @@ - + @@ -729,7 +729,7 @@ - + @@ -781,7 +781,7 @@ - + @@ -833,7 +833,7 @@ - + @@ -885,7 +885,7 @@ - + @@ -937,7 +937,7 @@ - + @@ -989,7 +989,7 @@ - + @@ -1041,7 +1041,7 @@ - + @@ -1093,7 +1093,7 @@ - + @@ -1145,7 +1145,7 @@ - + @@ -1197,7 +1197,7 @@ - + @@ -1249,7 +1249,7 @@ - + @@ -1301,7 +1301,7 @@ - + @@ -1353,7 +1353,7 @@ - + @@ -1405,7 +1405,7 @@ - + @@ -1457,7 +1457,7 @@ - + @@ -1509,7 +1509,7 @@ - + @@ -1561,7 +1561,7 @@ - + @@ -1613,7 +1613,7 @@ - + @@ -1665,7 +1665,7 @@ - + @@ -1717,7 +1717,7 @@ - + @@ -1769,7 +1769,7 @@ - + @@ -1821,7 +1821,7 @@ - + @@ -1873,7 +1873,7 @@ - + @@ -1925,7 +1925,7 @@ - + @@ -1977,7 +1977,7 @@ - + @@ -2029,7 +2029,7 @@ - + @@ -2081,7 +2081,7 @@ - + @@ -2133,7 +2133,7 @@ - + @@ -2185,7 +2185,7 @@ - + @@ -2237,7 +2237,7 @@ - + @@ -2289,7 +2289,7 @@ - + @@ -2341,7 +2341,7 @@ - + @@ -2393,7 +2393,7 @@ - + @@ -2445,7 +2445,7 @@ - + @@ -2497,7 +2497,7 @@ - + @@ -2549,7 +2549,7 @@ - + diff --git a/Makefile b/Makefile index 80ab4fe..7cf5a65 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -SIMGRID_INSTALL_DIR := ./simgrid-3.5-install -#SIMGRID_INSTALL_DIR := ../simgrid-git-install +SIMGRID_INSTALL_DIR := ./simgrid-stable +#SIMGRID_INSTALL_DIR := ./simgrid-dev OPTIM_FLAGS += -O3 DEBUG_FLAGS += -g diff --git a/TODO b/TODO index c68c38d..07ec631 100644 --- a/TODO +++ b/TODO @@ -7,5 +7,11 @@ * implement automatic process topology (line, ring, star, btree, clique, hypercube, etc..) -* implement automatic platform generation - (number of hosts, all connected, constant bandwidth/latency) + + use MSG_process_create_with_arguments + name function name (is duped...) + code use MSG_get_registered_function + data NULL + argc + argv argv[0] = process_name + diff --git a/cluster1000.xml b/cluster1000.xml new file mode 100644 index 0000000..62660d5 --- /dev/null +++ b/cluster1000.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/application.xml b/deployment.xml similarity index 100% rename from application.xml rename to deployment.xml diff --git a/hostdata.cpp b/hostdata.cpp index b75633a..a92527e 100644 --- a/hostdata.cpp +++ b/hostdata.cpp @@ -1,42 +1,55 @@ #include "hostdata.h" -#include +#include +#include #include +#include +#include "misc.h" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main); -hostdata* hostdata::instances = NULL; +std::vector hostdata::hosts; + +// used to compare m_host_t's by name +struct hostdata::m_host_less { + bool operator()(const m_host_t& a, const m_host_t& b) + { + const char* na = MSG_host_get_name(a); + const char* nb = MSG_host_get_name(b); + return strcmp(na, nb) < 0; + } +}; void hostdata::create() { int nhosts = MSG_get_host_number(); m_host_t* host_list = MSG_get_host_table(); - VERB1("Got %d hosts.", nhosts); + // fixme: only sort hosts for automatically created deployment + // fixme: add an option to disable sorting + std::sort(host_list, host_list + nhosts, m_host_less()); + hosts.assign(host_list, host_list + nhosts); + xbt_free(host_list); + + e_xbt_log_priority_t logp = xbt_log_priority_verbose; + if (!LOG_ISENABLED(logp)) + return; + LOG1(logp, "Got %lu hosts.", (unsigned long)hosts.size()); for (int i = 0; i < nhosts; i++) { - hostdata* h = new hostdata(host_list[i]); - MSG_host_set_data(host_list[i], h); - VERB2("Host #%d named \"%s\".", i, h->get_name()); - h->next = instances; - instances = h; + LOG2(logp, "Host #%d named \"%s\".", i, hosts[i].get_name()); } - xbt_free(host_list); } void hostdata::destroy() { - while (instances) { - hostdata* h = instances; - instances = h->next; - delete h; - } + // hosts are automatically destroyed... } hostdata::hostdata(m_host_t host) - : next(NULL) - , name(MSG_host_get_name(host)) + : name(MSG_host_get_name(host)) , ctrl_mbox(std::string(name) + "_ctrl") , data_mbox(std::string(name) + "_data") { + MSG_host_set_data(host, this); } hostdata::~hostdata() diff --git a/hostdata.h b/hostdata.h index 82e133f..59ca35d 100644 --- a/hostdata.h +++ b/hostdata.h @@ -2,28 +2,32 @@ #define HOSTDATA_H #include +#include #include class hostdata { public: static void create(); static void destroy(); + static size_t size() { return hosts.size(); } + static const hostdata& at(size_t i) { return hosts[i]; } hostdata(m_host_t host); ~hostdata(); - const char* get_name() const { return name; } + const char* get_name() const { return name; } const char* get_ctrl_mbox() const { return ctrl_mbox.c_str(); } const char* get_data_mbox() const { return data_mbox.c_str(); } private: - // linked list of hostdata's, used by create/destroy - static hostdata* instances; - hostdata* next; + // static list of hostdata's, used by create/destroy + static std::vector hosts; + struct m_host_less; const char* name; std::string ctrl_mbox; std::string data_mbox; + }; #endif // !HOSTDATA_H diff --git a/main.cpp b/main.cpp index a4e9fdb..f171425 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "hostdata.h" @@ -31,9 +32,15 @@ enum { int simulation_main(int argc, char* argv[]) { int result; - process* proc = new loba_least_loaded(argc, argv); - result = proc->run(); - delete proc; + process* proc; + try { + proc = new loba_least_loaded(argc, argv); + result = proc->run(); + delete proc; + } + catch (std::invalid_argument& e) { + THROW1(arg_error, 0, "%s", e.what()); + } return result; } @@ -62,7 +69,8 @@ int main(int argc, char* argv[]) if (!parse_res || opt::version_requested || opt::help_requested) { if (opt::version_requested) - std::clog << version::name << " version " << version::num << "\n" + std::clog << version::name << " (" << opt::program_name << ")" + << " version " << version::num << "\n" << version::copyright << "\n" "Compiled on " << version::date << "\n\n"; if (!parse_res || opt::help_requested) @@ -77,13 +85,22 @@ int main(int argc, char* argv[]) // Register the main function of an agent in a global table. MSG_function_register("simulation_main", simulation_main); - // Preserve some compatibility with old code... - MSG_function_register("Calculs", simulation_main); // Create the platform and the application. - MSG_create_environment(opt::platform_file); + MSG_create_environment(opt::platform_file.c_str()); hostdata::create(); - MSG_launch_application(opt::application_file); + if (opt::auto_depl::enabled) { + opt::auto_depl::nhosts = hostdata::size(); + opt::auto_depl::load = hostdata::size(); + try { + // fixme: do auto deployment + } + catch (std::exception& e) { + THROW1(0, 0, "%s", e.what()); + } + } else { + MSG_launch_application(opt::deployment_file.c_str()); + } exit_status = EXIT_FAILURE_SIMU; // ===== diff --git a/options.cpp b/options.cpp index 4f9c52c..6880969 100644 --- a/options.cpp +++ b/options.cpp @@ -1,6 +1,5 @@ #include "options.h" -#include // strrchr #include #include #include @@ -12,17 +11,24 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main); namespace opt { - const char* program_name; + std::string program_name; - const char* platform_file; - const char* application_file; + std::string platform_file; + std::string deployment_file; int help_requested = 0; bool version_requested = false; unsigned log_rate = 1; - unsigned maxiter = 4; + namespace auto_depl { + bool enabled = false; + std::string topology; + unsigned nhosts = 0; + double load = 0.0; + } + + unsigned maxiter = 4; // fixme bool exit_on_close = false; bool bookkeeping = false; @@ -45,12 +51,12 @@ int opt::parse_args(int* argc, char* argv[]) { int result = 1; - char* tmp = strrchr(argv[0], '/'); - opt::program_name = (tmp ? tmp + 1 : argv[0]); - + opt::program_name = argv[0]; + opt::program_name.erase(0, 1 + opt::program_name.find_last_of('/')); + int c; opterr = 0; - while ((c = getopt(*argc, argv, "bc:C:ehi:l:V")) != -1) { + while ((c = getopt(*argc, argv, "bc:C:ehi:l:L:N:T:V")) != -1) { switch (c) { case 'b': opt::bookkeeping = true; @@ -73,6 +79,15 @@ int opt::parse_args(int* argc, char* argv[]) case 'l': std::istringstream(optarg) >> opt::log_rate; break; + case 'L': + std::istringstream(optarg) >> opt::auto_depl::load; + break; + case 'N': + std::istringstream(optarg) >> opt::auto_depl::nhosts; + break; + case 'T': + opt::auto_depl::topology = optarg; + break; case 'V': opt::version_requested = true; break; @@ -82,27 +97,29 @@ int opt::parse_args(int* argc, char* argv[]) break; } } + opt::auto_depl::enabled = !opt::auto_depl::topology.empty(); + if (opt::version_requested || opt::help_requested) return 1; - int rem_args = *argc - optind; - switch (rem_args) { - case 0: + if (optind < *argc) { + opt::platform_file = argv[optind++]; + } else { ERROR0("missing parameter -- "); - case 1: - ERROR0("missing parameter -- "); result = 0; - break; + } + if (!opt::auto_depl::enabled) { + if (optind < *argc) { + opt::deployment_file = argv[optind++]; + } else { + ERROR0("missing parameter -- "); + result = 0; + } + } - default: - opt::platform_file = argv[optind]; - opt::application_file = argv[optind + 1]; - if (rem_args == 2) - break; - for (int i = optind + 2 ; i < *argc ; ++i) - ERROR1("unused parameter -- \"%s\"", argv[i]); + while (optind < *argc) { + ERROR1("unused parameter -- \"%s\"", argv[optind++]); result = 0; - break; } return result; @@ -111,8 +128,15 @@ int opt::parse_args(int* argc, char* argv[]) void opt::print() { INFO0(",----[ Simulation parameters ]"); - INFO1("| platform_file.......: \"%s\"", opt::platform_file); - INFO1("| application_file....: \"%s\"", opt::application_file); + INFO1("| platform file.......: \"%s\"", opt::platform_file.c_str()); + if (opt::auto_depl::enabled) { + INFO0("| automatic deployment enabled with:"); + INFO1("| topology........: %s", opt::auto_depl::topology.c_str()); + INFO1("| number of hosts.: %u", opt::auto_depl::nhosts); + INFO1("| initial load....: %g", opt::auto_depl::load); + } else { + INFO1("| deployment file.....: \"%s\"", opt::deployment_file.c_str()); + } INFO1("| log rate............: %u", opt::log_rate); INFO1("| maxiter.............: %u", opt::maxiter); INFO1("| exit on close.......: %s", on_off(opt::exit_on_close)); @@ -124,37 +148,47 @@ void opt::print() void opt::usage() { - const int indent1 = 6; - const int indent2 = 12; - -#define oo(opt, arg) std::setw(indent1) << (opt) << " " \ - << std::setw(indent2) << std::left << (arg) << std::right -#define o(opt) oo(opt, "") +#define o(opt) " " << std::setw(14) \ + << std::left << (opt) << std::right << " " +#define so(subopt) std::setw(10) << (subopt) << ": " std::clog << "Usage: " << opt::program_name - << " [options] \n"; + << " [options] \n"; std::clog << o("-h") - << "print help and exit (use -hh or -hhh for extended help)\n"; + << "print help and exit (use -hh for extended help)\n"; if (opt::help_requested < 1) return; + std::clog << o("--help") << "print help from SimGrid framework and exit\n"; std::clog << o("-V") << "print version and exit\n"; std::clog << o("-b") << "activate bookkeeping\n"; - std::clog << oo("-c", "[fn,...]f0") - << "polynomial factors for computation cost (" - << opt::comp_cost.to_string() << ")\n"; - std::clog << oo("-C", "[fn,...]f0") - << "polynomial factors for communication cost (" - << opt::comm_cost.to_string() << ")\n"; - std::clog << o("-e") << "exit on close reception\n"; - std::clog << oo("-i", "value") - << "maximum number of iterations, 0 for infinity (" - << opt::maxiter << ")\n"; - std::clog << oo("-l", "value") - << "print current load every \"value\" iterations, 0 to disable (" - << opt::log_rate << ")\n"; + std::clog << o("-c [fn,...]f0") + << "polynomial factors for computation cost" + << " (" << opt::comp_cost.to_string() << ")\n"; + std::clog << o("-C [fn,...]f0") + << "polynomial factors for communication cost" + << " (" << opt::comm_cost.to_string() << ")\n"; + std::clog << o("-e") << "exit on reception of \"close\" message\n"; + std::clog << o("-i value") + << "maximum number of iterations, 0 for infinity" + << " (" << opt::maxiter << ")\n"; + std::clog << o("-l value") + << "print current load every n-th iterations, 0 to disable" + << " (" << opt::log_rate << ")\n"; + std::clog << o("-L value") + << "total load with auto deployment, 0 for number of hosts" + << " (" << opt::auto_depl::load << ")\n"; + std::clog << o("-N value") + << "number of hosts to use with auto deployment," + << " 0 for max. (" << opt::auto_depl::nhosts << ")\n"; + std::clog << o("-T type") + << "enable automatic deployment with selected topology\n"; + if (opt::help_requested > 1) { + std::clog << so(1) << "pipo\n"; + std::clog << so(42) << "atchoum\n"; + } #undef o #undef oo diff --git a/options.h b/options.h index 70c9f5d..8d89808 100644 --- a/options.h +++ b/options.h @@ -1,21 +1,32 @@ #ifndef OPTIONS_H #define OPTIONS_H +#include #include "cost_func.h" // Global parameters, shared by all the processes namespace opt { - extern const char* program_name; + extern std::string program_name; - extern const char* platform_file; - extern const char* application_file; + extern std::string platform_file; + extern std::string deployment_file; extern int help_requested; extern bool version_requested; extern unsigned log_rate; + namespace auto_depl { + extern bool enabled; + extern std::string topology; + extern unsigned nhosts; + extern double load; + } + + extern std::string topology; + extern double init_load; + extern unsigned maxiter; extern bool exit_on_close; diff --git a/process.cpp b/process.cpp index 339938a..3b37123 100644 --- a/process.cpp +++ b/process.cpp @@ -16,7 +16,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(proc); process::process(int argc, char* argv[]) { if (argc < 2 || !(std::istringstream(argv[1]) >> load)) - throw std::invalid_argument("bad or missing initial load"); + throw std::invalid_argument("bad or missing initial load parameter"); neigh.assign(argv + 2, argv + argc); diff --git a/version.cpp b/version.cpp index db840a1..9f1a023 100644 --- a/version.cpp +++ b/version.cpp @@ -2,7 +2,7 @@ namespace version { - const char name[] = "Asynchronous Load Balancing (loba)"; + const char name[] = "Asynchronous Load Balancing"; const char num[] = "0x00" #include "localversion" ;