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"
21 // A sum of loads if considered null if it is less than
22 // load_ratio_threshold percent of the sum of loads at init.
23 const double load_ratio_threshold = 1e-4;
26 std::string program_name;
27 int help_requested = 0;
28 bool version_requested = false;
30 // Simulation parameters
31 unsigned log_rate = 1;
33 // Platform and deployment
34 std::string platform_file;
35 std::string deployment_file;
37 // Automatic deployment
40 std::string topology("clique");
45 // Load balancing algorithm
46 std::string loba_algo("simple");
47 bool bookkeeping = false;
49 // Application parameters
50 // fixme: find better defaults
51 cost_func comp_cost("1e9, 0");
52 cost_func comm_cost("1, 0");
53 double min_iter_duration = 1.0;
55 // Parameters for the end of the simulation
56 // fixme: find better defaults
57 unsigned comp_maxiter = 10;
58 unsigned lb_maxiter = comp_maxiter;
59 double time_limit = 0;
60 bool exit_on_close = false;
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("none", "no load-balancing (for testing only)", process);
68 NOL_INSERT("simple", "balance with least loaded neighbor", loba_simple);
71 topologies_type topologies;
72 topologies_type::topologies_type()
74 NOL_INSERT("btree", "binary tree topology, initial load at root",
76 NOL_INSERT("clique", "all connected topology", deployment_clique);
77 NOL_INSERT("hcube", "hypercube topology", deployment_hcube);
78 NOL_INSERT("line", "line topology, initial load at one end",
80 NOL_INSERT("ring", "ring topology", deployment_ring);
81 NOL_INSERT("star", "star topology, initial load at center",
83 NOL_INSERT("torus", "torus topology", deployment_torus);
93 static const char* on_off(bool b);
94 const char* descr(const char* str);
96 const char* val_or_string(const T& val, const char* str,
99 static bool nol_find_prefix(const T& nol, const char* descr,
103 std::string descr_str;
104 std::string val_or_string_str;
109 const char* opt_helper::on_off(bool b)
111 return b ? "on" : "off";
114 const char* opt_helper::descr(const char* str)
116 const int descr_width = 40;
117 std::string& res = descr_str;
119 res.resize(descr_width, '.');
123 template <typename T>
124 const char* opt_helper::val_or_string(const T& val, const char* str,
127 std::string& res = val_or_string_str;
129 std::ostringstream oss;
138 template <typename T>
139 bool opt_helper::nol_find_prefix(const T& nol, const char* descr,
142 bool result = nol.exists(name);
144 std::stack<std::string> candidates;
145 for (typename T::iterator it = nol.begin() ; it != nol.end() ; ++it) {
146 const std::string& fullname = nol.get_name(it);
147 if (fullname.compare(0, name.length(), name) == 0)
148 candidates.push(fullname);
150 switch (candidates.size()) {
152 ERROR2("unknownw %s -- %s", descr, name.c_str());
155 name = candidates.top();
158 DEBUG2("infered %s -- %s", descr, name.c_str());
161 ERROR2("ambiguous %s -- %s", descr, name.c_str());
162 while (!candidates.empty()) {
163 ERROR1(" candidates are -- %s", candidates.top().c_str());
172 bool opt::parse_args(int* argc, char* argv[])
176 opt::program_name = argv[0];
177 opt::program_name.erase(0, 1 + opt::program_name.find_last_of('/'));
181 while ((c = getopt(*argc, argv, "a:bc:C:ehi:I:l:L:N:s:t:T:vV")) != -1) {
184 opt::loba_algo = optarg;
185 result = opt_helper::nol_find_prefix(opt::loba_algorithms,
186 "load balancing algorithm",
191 opt::bookkeeping = true;
194 opt::exit_on_close = true;
197 opt::help_requested++;
200 opt::comp_cost = cost_func(optarg);
203 opt::comm_cost = cost_func(optarg);
206 std::istringstream(optarg) >> opt::comp_maxiter;
209 std::istringstream(optarg) >> opt::lb_maxiter;
210 ERROR0("option -I not implemented yet");
214 std::istringstream(optarg) >> opt::log_rate;
217 std::istringstream(optarg) >> opt::auto_depl::load;
220 std::istringstream(optarg) >> opt::auto_depl::nhosts;
223 std::istringstream(optarg) >> opt::min_iter_duration;
226 std::istringstream(optarg) >> opt::time_limit;
229 opt::auto_depl::topology = optarg;
230 result = opt_helper::nol_find_prefix(opt::topologies, "topology",
231 opt::auto_depl::topology)
235 // nothing to do: this option is checked at the very
236 // beginning of main()
239 opt::version_requested = true;
242 ERROR1("invalid option -- '%c'", optopt);
248 if (opt::version_requested || opt::help_requested)
251 if (optind < *argc) {
252 opt::platform_file = argv[optind++];
254 ERROR0("missing parameter -- <plaform_file>");
257 if (optind < *argc) {
258 opt::deployment_file = argv[optind++];
260 opt::auto_depl::enabled = opt::deployment_file.empty();
262 while (optind < *argc) {
263 ERROR1("unused parameter -- \"%s\"", argv[optind++]);
274 #define DESCR(description, format, value) \
275 INFO2("| %s: " format, h.descr(description), value)
277 INFO0(",----[ Simulation parameters ]");
278 DESCR("log rate", "%s", h.val_or_string(log_rate, "disabled"));
279 DESCR("platform file", "\"%s\"", platform_file.c_str());
280 if (auto_depl::enabled) {
281 INFO0("| automatic deployment enabled");
282 DESCR("- topology", "%s", auto_depl::topology.c_str());
283 DESCR("- number of hosts", "%s", h.val_or_string(auto_depl::nhosts,
285 DESCR("- initial load", "%s", h.val_or_string(auto_depl::load,
288 DESCR("deployment file", "\"%s\"", deployment_file.c_str());
290 DESCR("load balancing algorithm", "%s", loba_algo.c_str());
291 DESCR("bookkeeping", "%s", h.on_off(bookkeeping));
292 DESCR("computation cost factors", "[%s]", comp_cost.to_string().c_str());
293 DESCR("communication cost factors", "[%s]", comm_cost.to_string().c_str());
294 DESCR("minimum duration between iterations", "%g", min_iter_duration);
295 DESCR("maximum number of comp. iterations", "%s",
296 h.val_or_string(comp_maxiter, "infinity"));
297 DESCR("maximum number of lb. iterations", "%s",
298 h.val_or_string(lb_maxiter, "infinity"));
299 DESCR("time limit", "%s", h.val_or_string(time_limit, "infinity"));
300 DESCR("exit on close", "%s", h.on_off(exit_on_close));
309 #define o(opt) " " << std::setw(14) \
310 << std::left << (opt) << std::right << " "
312 #define so(subopt) std::setw(18) << (subopt) << " : "
314 #define so_list(name) do { \
315 name ## _type::iterator it; \
316 for (it = name.begin() ; it != name.end() ; ++it) \
317 std::clog << so(name.get_name(it)) \
318 << name.get_descr(it) << "\n"; \
322 std::clog << "Usage: " << opt::program_name
323 << " [options] <platform_file> [<deployment_file>]\n";
325 std::clog << "\nGlobal options\n";
327 << "print help and exit (use -hh or -hhh for extended help)\n";
328 if (opt::help_requested < 1)
331 std::clog << o("--help") << "print help from SimGrid framework and exit\n";
332 std::clog << o("-V") << "print version and exit\n";
334 std::clog << "\nSimulation parameters\n";
335 std::clog << o("-l value")
336 << "print current load every n-th iterations, 0 to disable"
337 << " (" << opt::log_rate << ")\n";
339 << "verbose: do not override the default logging parameters\n";
341 std::clog << "\nAutomatic deployment options\n";
342 std::clog << o("-T name")
343 << "enable automatic deployment with selected topology"
344 << " (" << opt::auto_depl::topology << ")\n";
345 if (opt::help_requested > 1)
346 so_list(opt::topologies);
347 std::clog << o("-L value")
348 << "total load with auto deployment, 0 for number of hosts"
349 << " (" << opt::auto_depl::load << ")\n";
350 std::clog << o("-N value")
351 << "number of hosts to use with auto deployment,"
352 << " 0 for max. (" << opt::auto_depl::nhosts << ")\n";
354 std::clog << "\nLoad balancing algorithm\n";
355 std::clog << o("-a name") << "load balancing algorithm"
356 << " (" << opt::loba_algo << ")\n";
357 if (opt::help_requested > 1)
358 so_list(opt::loba_algorithms);
359 std::clog << o("-b") << "enable bookkeeping (\"virtual load\")\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 comp. iterations, 0 for infinity"
375 << " (" << opt::comp_maxiter << ")\n";
376 std::clog << o("-I value")
377 << "maximum number of lb. iterations, 0 for infinity"
378 << " (" << opt::lb_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") << "exit on reception of \"close\" message\n";
384 if (opt::help_requested < 3)
387 std::clog << "\nLogging support\n"
388 << " See SimGrid documentation on:\n"
389 << " http://simgrid.gforge.inria.fr/doc/group__XBT__log.html#log_user\n"
390 << " Existing categories are:\n"
391 << " simu : root of following categories\n"
392 << " main : messages from global infrastructure\n"
393 << " depl : messages from auto deployment (inherited from main)\n"
394 << " comm : messages from asynchronous pipes\n"
395 << " proc : messages from base process class\n"
396 << " loba : messages from load-balancer\n";
398 // std::clog << "\nMiscellaneous low-level parameters\n";