5 #include <unistd.h> // getopt
8 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
10 #include "deployment.h"
12 #include "loba_simple.h"
13 #include "loba_fairstrategy.h"
14 #include "loba_makhoul.h"
22 // A sum of loads if considered null if it is less than
23 // load_ratio_threshold percent of the sum of loads at init.
24 const double load_ratio_threshold = 1e-4;
27 std::string program_name;
28 int help_requested = 0;
29 bool version_requested = false;
31 // Simulation parameters
32 unsigned log_rate = 1;
34 // Platform and deployment
35 std::string platform_file;
36 std::string deployment_file;
38 // Automatic deployment
41 std::string topology("clique");
46 // Load balancing algorithm
47 std::string loba_algo("simple");
48 bool bookkeeping = false;
50 // Application parameters
51 // fixme: find better defaults
52 cost_func comp_cost("1e9, 0");
53 cost_func comm_cost("1, 0");
54 double min_iter_duration = 1.0;
56 // Parameters for the end of the simulation
57 unsigned lb_maxiter = 0;
58 unsigned comp_maxiter = 0;
59 double time_limit = 0;
60 bool exit_on_close = true;
62 // Named parameters lists
63 loba_algorithms_type loba_algorithms;
64 loba_algorithms_type::loba_algorithms_type()
66 NOL_INSERT("fairstrategy", "balance with fair strategy", loba_fairstrategy);
67 NOL_INSERT("makhoul", "balance with Makhoul's PhD algorithm", loba_makhoul);
68 NOL_INSERT("none", "no load-balancing (for testing only)", process);
69 NOL_INSERT("simple", "balance with least loaded neighbor", loba_simple);
72 topologies_type topologies;
73 topologies_type::topologies_type()
75 NOL_INSERT("btree", "binary tree topology, initial load at root",
77 NOL_INSERT("clique", "all connected topology", deployment_clique);
78 NOL_INSERT("hcube", "hypercube topology", deployment_hcube);
79 NOL_INSERT("line", "line topology, initial load at one end",
81 NOL_INSERT("ring", "ring topology", deployment_ring);
82 NOL_INSERT("star", "star topology, initial load at center",
84 NOL_INSERT("torus", "torus topology", deployment_torus);
94 static const char* on_off(bool b);
95 const char* descr(const char* str);
97 const char* val_or_string(const T& val, const char* str,
100 static bool nol_find_prefix(const T& nol, const char* descr,
104 std::string descr_str;
105 std::string val_or_string_str;
110 const char* opt_helper::on_off(bool b)
112 return b ? "on" : "off";
115 const char* opt_helper::descr(const char* str)
117 const int descr_width = 40;
118 std::string& res = descr_str;
120 res.resize(descr_width, '.');
124 template <typename T>
125 const char* opt_helper::val_or_string(const T& val, const char* str,
128 std::string& res = val_or_string_str;
130 std::ostringstream oss;
139 template <typename T>
140 bool opt_helper::nol_find_prefix(const T& nol, const char* descr,
143 bool result = nol.exists(name);
145 std::stack<std::string> candidates;
146 for (typename T::iterator it = nol.begin() ; it != nol.end() ; ++it) {
147 const std::string& fullname = nol.get_name(it);
148 if (fullname.compare(0, name.length(), name) == 0)
149 candidates.push(fullname);
151 switch (candidates.size()) {
153 ERROR2("unknownw %s -- %s", descr, name.c_str());
156 name = candidates.top();
159 DEBUG2("infered %s -- %s", descr, name.c_str());
162 ERROR2("ambiguous %s -- %s", descr, name.c_str());
163 while (!candidates.empty()) {
164 ERROR1(" candidates are -- %s", candidates.top().c_str());
173 bool opt::parse_args(int* argc, char* argv[])
177 opt::program_name = argv[0];
178 opt::program_name.erase(0, 1 + opt::program_name.find_last_of('/'));
182 while ((c = getopt(*argc, argv, "a:bc:C:ehi:I:l:L:N:s:t:T:vV")) != -1) {
185 opt::loba_algo = optarg;
186 result = opt_helper::nol_find_prefix(opt::loba_algorithms,
187 "load balancing algorithm",
192 opt::bookkeeping = !opt::bookkeeping;
195 opt::exit_on_close = !opt::exit_on_close;
198 opt::help_requested++;
201 opt::comp_cost = cost_func(optarg);
204 opt::comm_cost = cost_func(optarg);
207 std::istringstream(optarg) >> opt::lb_maxiter;
210 std::istringstream(optarg) >> opt::comp_maxiter;
213 std::istringstream(optarg) >> opt::log_rate;
216 std::istringstream(optarg) >> opt::auto_depl::load;
219 std::istringstream(optarg) >> opt::auto_depl::nhosts;
222 std::istringstream(optarg) >> opt::min_iter_duration;
225 std::istringstream(optarg) >> opt::time_limit;
228 opt::auto_depl::topology = optarg;
229 result = opt_helper::nol_find_prefix(opt::topologies, "topology",
230 opt::auto_depl::topology)
234 // nothing to do: this option is checked at the very
235 // beginning of main()
238 opt::version_requested = true;
241 ERROR1("invalid option -- '%c'", optopt);
247 if (opt::version_requested || opt::help_requested)
250 if (optind < *argc) {
251 opt::platform_file = argv[optind++];
253 ERROR0("missing parameter -- <plaform_file>");
256 if (optind < *argc) {
257 opt::deployment_file = argv[optind++];
259 opt::auto_depl::enabled = opt::deployment_file.empty();
261 while (optind < *argc) {
262 ERROR1("unused parameter -- \"%s\"", argv[optind++]);
273 #define DESCR(description, format, value) \
274 INFO2("| %s: " format, h.descr(description), value)
276 INFO0(",----[ Simulation parameters ]");
277 DESCR("log rate", "%s", h.val_or_string(log_rate, "disabled"));
278 DESCR("platform file", "\"%s\"", platform_file.c_str());
279 if (auto_depl::enabled) {
280 INFO0("| automatic deployment enabled");
281 DESCR("- topology", "%s", auto_depl::topology.c_str());
282 DESCR("- number of hosts", "%s", h.val_or_string(auto_depl::nhosts,
284 DESCR("- initial load", "%s", h.val_or_string(auto_depl::load,
287 DESCR("deployment file", "\"%s\"", deployment_file.c_str());
289 DESCR("load balancing algorithm", "%s", loba_algo.c_str());
290 DESCR("bookkeeping", "%s", h.on_off(bookkeeping));
291 DESCR("computation cost factors", "[%s]", comp_cost.to_string().c_str());
292 DESCR("communication cost factors", "[%s]", comm_cost.to_string().c_str());
293 DESCR("minimum duration between iterations", "%g", min_iter_duration);
294 DESCR("maximum number of lb. iterations", "%s",
295 h.val_or_string(lb_maxiter, "infinity"));
296 DESCR("maximum number of comp. iterations", "%s",
297 h.val_or_string(comp_maxiter, "infinity"));
298 DESCR("time limit", "%s", h.val_or_string(time_limit, "infinity"));
299 DESCR("exit on close", "%s", h.on_off(exit_on_close));
308 #define o(opt) " " << std::setw(14) \
309 << std::left << (opt) << std::right << " "
311 #define so(subopt) std::setw(18) << (subopt) << " : "
313 #define so_list(name) do { \
314 name ## _type::iterator it; \
315 for (it = name.begin() ; it != name.end() ; ++it) \
316 std::clog << so(name.get_name(it)) \
317 << name.get_descr(it) << "\n"; \
321 std::clog << "Usage: " << opt::program_name
322 << " [options] <platform_file> [<deployment_file>]\n";
324 std::clog << "\nGlobal options\n";
326 << "print help and exit (use -hh or -hhh for extended help)\n";
327 if (opt::help_requested < 1)
330 std::clog << o("--help") << "print help from SimGrid framework and exit\n";
331 std::clog << o("-V") << "print version and exit\n";
333 std::clog << "\nSimulation parameters\n";
334 std::clog << o("-l value")
335 << "print current load every n lb iterations, 0 to disable"
336 << " [" << opt::log_rate << "]\n";
338 << "verbose: do not override the default logging parameters\n";
340 std::clog << "\nAutomatic deployment options\n";
341 std::clog << o("-T name")
342 << "enable automatic deployment with selected topology"
343 << " [" << opt::auto_depl::topology << "]\n";
344 if (opt::help_requested > 1)
345 so_list(opt::topologies);
346 std::clog << o("-L value")
347 << "total load with auto deployment, 0 for number of hosts"
348 << " [" << opt::auto_depl::load << "]\n";
349 std::clog << o("-N value")
350 << "number of hosts to use with auto deployment, 0 for max."
351 << " [" << opt::auto_depl::nhosts << "]\n";
353 std::clog << "\nLoad balancing algorithm\n";
354 std::clog << o("-a name") << "load balancing algorithm"
355 << " [" << opt::loba_algo << "]\n";
356 if (opt::help_requested > 1)
357 so_list(opt::loba_algorithms);
358 std::clog << o("-b") << "toggle bookkeeping (\"virtual load\")"
359 << " [" << opt_helper::on_off(opt::bookkeeping) << "]\n";
361 std::clog << "\nApplication parameters\n";
362 std::clog << o("-c [fn,...]f0")
363 << "polynomial factors for computation cost"
364 << " [" << opt::comp_cost.to_string() << "]\n";
365 std::clog << o("-C [fn,...]f0")
366 << "polynomial factors for communication cost"
367 << " [" << opt::comm_cost.to_string() << "]\n";
368 std::clog << o("-s value")
369 << "minimum duration between iterations"
370 << " [" << opt::min_iter_duration << "]\n";
372 std::clog << "\nParameters for the end of the simulation\n";
373 std::clog << o("-i value")
374 << "maximum number of lb. iterations, 0 for infinity"
375 << " [" << opt::lb_maxiter << "]\n";
376 std::clog << o("-I value")
377 << "maximum number of comp. iterations, 0 for infinity"
378 << " [" << opt::comp_maxiter << "]\n";
379 std::clog << o("-t value")
380 << "time limit (simulated time), 0 for infinity"
381 << " [" << opt::time_limit << "]\n";
382 std::clog << o("-e") << "toggle exit on reception of \"close\" message"
383 << " [" << opt_helper::on_off(opt::exit_on_close) << "]\n";
385 if (opt::help_requested < 3)
388 std::clog << "\nLogging support\n"
389 << " See SimGrid documentation on:\n"
390 << " http://simgrid.gforge.inria.fr/doc/group__XBT__log.html#log_user\n"
391 << " Existing categories are:\n"
392 << " simu : root of following categories\n"
393 << " main : messages from global infrastructure\n"
394 << " depl : messages from auto deployment (inherited from main)\n"
395 << " comm : messages from asynchronous pipes\n"
396 << " proc : messages from base process class\n"
397 << " loba : messages from load-balancer\n";
399 // std::clog << "\nMiscellaneous low-level parameters\n";