<?xml version='1.0'?>
<!DOCTYPE platform SYSTEM "simgrid.dtd">
<platform version="3">
- <process host="1" function="Calculs">
+ <process host="1" function="simulation_main">
<argument value="777"/>
<argument value="2"/>
<argument value="3"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="2" function="Calculs">
+ <process host="2" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="3"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="3" function="Calculs">
+ <process host="3" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="4" function="Calculs">
+ <process host="4" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="5" function="Calculs">
+ <process host="5" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="6" function="Calculs">
+ <process host="6" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="7" function="Calculs">
+ <process host="7" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="8" function="Calculs">
+ <process host="8" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="9" function="Calculs">
+ <process host="9" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="10" function="Calculs">
+ <process host="10" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="11" function="Calculs">
+ <process host="11" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="12" function="Calculs">
+ <process host="12" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="13" function="Calculs">
+ <process host="13" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="14" function="Calculs">
+ <process host="14" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="15" function="Calculs">
+ <process host="15" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="16" function="Calculs">
+ <process host="16" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="17" function="Calculs">
+ <process host="17" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="18" function="Calculs">
+ <process host="18" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="19" function="Calculs">
+ <process host="19" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="20" function="Calculs">
+ <process host="20" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="21" function="Calculs">
+ <process host="21" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="22" function="Calculs">
+ <process host="22" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="23" function="Calculs">
+ <process host="23" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="24" function="Calculs">
+ <process host="24" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="25" function="Calculs">
+ <process host="25" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="26" function="Calculs">
+ <process host="26" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="27" function="Calculs">
+ <process host="27" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="28" function="Calculs">
+ <process host="28" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="29" function="Calculs">
+ <process host="29" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="30" function="Calculs">
+ <process host="30" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="31" function="Calculs">
+ <process host="31" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="32" function="Calculs">
+ <process host="32" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="33" function="Calculs">
+ <process host="33" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="34" function="Calculs">
+ <process host="34" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="35" function="Calculs">
+ <process host="35" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="36" function="Calculs">
+ <process host="36" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="37" function="Calculs">
+ <process host="37" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="38" function="Calculs">
+ <process host="38" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="39" function="Calculs">
+ <process host="39" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="40" function="Calculs">
+ <process host="40" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="41" function="Calculs">
+ <process host="41" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="42" function="Calculs">
+ <process host="42" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="43" function="Calculs">
+ <process host="43" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="44" function="Calculs">
+ <process host="44" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="45" function="Calculs">
+ <process host="45" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="46" function="Calculs">
+ <process host="46" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="47" function="Calculs">
+ <process host="47" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="48" function="Calculs">
+ <process host="48" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="49"/>
<argument value="50"/>
</process>
- <process host="49" function="Calculs">
+ <process host="49" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
<argument value="48"/>
<argument value="50"/>
</process>
- <process host="50" function="Calculs">
+ <process host="50" function="simulation_main">
<argument value="0"/>
<argument value="1"/>
<argument value="2"/>
-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
* 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
+
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="3">
+<AS id="AS0" routing="Full">
+ <cluster id="c" prefix="h-" suffix=""
+ radical="100000-100999" power="1000000000" bw="125000000" lat="5E-5"
+ bb_bw="2250000000" bb_lat="5E-4"/>
+</AS>
+</platform>
#include "hostdata.h"
-#include <xbt/log.h>
+#include <cstring>
+#include <algorithm>
#include <stdexcept>
+#include <xbt/log.h>
+#include "misc.h"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
-hostdata* hostdata::instances = NULL;
+std::vector<hostdata> 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()
#define HOSTDATA_H
#include <string>
+#include <vector>
#include <msg/msg.h>
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<hostdata> hosts;
+ struct m_host_less;
const char* name;
std::string ctrl_mbox;
std::string data_mbox;
+
};
#endif // !HOSTDATA_H
#include <cstring>
#include <iostream>
+#include <stdexcept>
#include <msg/msg.h>
#include <xbt/log.h>
#include "hostdata.h"
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;
}
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)
// 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; // =====
#include "options.h"
-#include <cstring> // strrchr
#include <iomanip>
#include <iostream>
#include <sstream>
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;
{
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;
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;
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 -- <plaform_file>");
- case 1:
- ERROR0("missing parameter -- <application_file>");
result = 0;
- break;
+ }
+ if (!opt::auto_depl::enabled) {
+ if (optind < *argc) {
+ opt::deployment_file = argv[optind++];
+ } else {
+ ERROR0("missing parameter -- <deployment_file>");
+ 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;
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));
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] <platform_file> <application_file>\n";
+ << " [options] <platform_file> <deployment_file>\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
#ifndef OPTIONS_H
#define OPTIONS_H
+#include <string>
#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;
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);
namespace version {
- const char name[] = "Asynchronous Load Balancing (loba)";
+ const char name[] = "Asynchronous Load Balancing";
const char num[] = "0x00"
#include "localversion"
;