6 #include <unistd.h> // getopt
8 #include "loba_simple.h"
9 #include "loba_fairstrategy.h"
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
16 std::string program_name;
17 int help_requested = 0;
18 bool version_requested = false;
20 // Simulation parameters
21 unsigned log_rate = 1;
23 // Platform and deployment
24 std::string platform_file;
25 std::string deployment_file;
27 // Automatic deployment
30 std::string topology("clique");
35 // Load balancing algorithm
36 std::string loba_algo("simple");
37 bool bookkeeping = false;
39 // Application parameters
40 cost_func comp_cost("1e9, 0"); // fixme: find better defaults
41 cost_func comm_cost("1, 0"); // fixme: find better defaults
42 unsigned maxiter = 10; // fixme: find better defaults
43 bool exit_on_close = false;
45 // Named parameters lists
46 loba_algorithms_type loba_algorithms;
47 loba_algorithms_type::loba_algorithms_type()
49 NOL_INSERT("fairstrategy", "balance with fair strategy", loba_fairstrategy);
50 NOL_INSERT("none", "no load-balancing (for testing)", process);
51 NOL_INSERT("simple", "balance with least loaded neighbor", loba_simple);
54 topologies_type topologies;
55 topologies_type::topologies_type()
57 NOL_INSERT("btree", "binary tree topologym intiial load at root",
59 NOL_INSERT("clique", "all connected topology", deployment_clique);
60 NOL_INSERT("hcube", "hypercube topology", deployment_hcube);
61 NOL_INSERT("line", "line topology, initial load at one end",
63 NOL_INSERT("ring", "ring topology", deployment_ring);
64 NOL_INSERT("star", "star topology, initial load at center",
66 NOL_INSERT("torus", "torus topology", deployment_torus);
71 int opt::parse_args(int* argc, char* argv[])
75 opt::program_name = argv[0];
76 opt::program_name.erase(0, 1 + opt::program_name.find_last_of('/'));
80 while ((c = getopt(*argc, argv, "a:bc:C:ehi:l:L:N:T:vV")) != -1) {
83 opt::loba_algo = optarg;
84 if (!opt::loba_algorithms.exists(opt::loba_algo)) {
85 ERROR1("unknownw load balancing algorithm -- %s",
86 opt::loba_algo.c_str());
91 opt::bookkeeping = true;
94 opt::exit_on_close = true;
97 opt::help_requested++;
100 opt::comp_cost = cost_func(optarg);
103 opt::comm_cost = cost_func(optarg);
106 std::istringstream(optarg) >> opt::maxiter;
109 std::istringstream(optarg) >> opt::log_rate;
112 std::istringstream(optarg) >> opt::auto_depl::load;
115 std::istringstream(optarg) >> opt::auto_depl::nhosts;
118 opt::auto_depl::topology = optarg;
119 if (!opt::topologies.exists(opt::auto_depl::topology)) {
120 ERROR1("unknownw topology -- %s",
121 opt::auto_depl::topology.c_str());
126 // nothing to do: this option is checked at the very
127 // beginning of main()
130 opt::version_requested = true;
133 ERROR1("invalid option -- '%c'", optopt);
139 if (opt::version_requested || opt::help_requested)
142 if (optind < *argc) {
143 opt::platform_file = argv[optind++];
145 ERROR0("missing parameter -- <plaform_file>");
148 if (optind < *argc) {
149 opt::deployment_file = argv[optind++];
151 opt::auto_depl::enabled = opt::deployment_file.empty();
153 while (optind < *argc) {
154 ERROR1("unused parameter -- \"%s\"", argv[optind++]);
163 // some helper functions for opt::print()
165 const char* on_off(bool b)
167 return b ? "on" : "off";
170 template <typename T>
171 const char* val_or_string(const T& val, const char* str, const T& deflt = 0)
173 static std::string res;
175 std::ostringstream oss;
188 INFO0(",----[ Simulation parameters ]");
189 INFO1("| log rate.....................: %s",
190 val_or_string(opt::log_rate, "disabled"));
191 INFO1("| platform file................: \"%s\"", opt::platform_file.c_str());
192 if (opt::auto_depl::enabled) {
193 INFO0("| automatic deployment enabled");
194 INFO1("| - topology...................: %s", opt::auto_depl::topology.c_str());
195 INFO1("| - number of hosts............: %s",
196 val_or_string(opt::auto_depl::nhosts, "auto"));
197 INFO1("| - initial load...............: %s",
198 val_or_string(opt::auto_depl::load, "auto"));
200 INFO1("| deployment file..............: \"%s\"", opt::deployment_file.c_str());
202 INFO1("| load balancing algorithm.....: %s", opt::loba_algo.c_str());
203 INFO1("| bookkeeping..................: %s", on_off(opt::bookkeeping));
204 INFO1("| computation cost factors.....: [%s]", opt::comp_cost.to_string().c_str());
205 INFO1("| communication cost factors...: [%s]", opt::comm_cost.to_string().c_str());
206 INFO1("| maximum number of iterations.: %s",
207 val_or_string(opt::maxiter, "infinity"));
208 INFO1("| exit on close................: %s", on_off(opt::exit_on_close));
215 #define o(opt) " " << std::setw(14) \
216 << std::left << (opt) << std::right << " "
218 #define so(subopt) std::setw(18) << (subopt) << " : "
220 #define so_list(name) do { \
221 name ## _type::iterator it; \
222 for (it = name.begin() ; it != name.end() ; ++it) \
223 std::clog << so(name.get_name(it)) \
224 << name.get_descr(it) << "\n"; \
228 std::clog << "Usage: " << opt::program_name
229 << " [options] <platform_file> [<deployment_file>]\n";
231 std::clog << "\nGlobal options\n";
233 << "print help and exit (use -hh or -hhh for extended help)\n";
234 if (opt::help_requested < 1)
237 std::clog << o("--help") << "print help from SimGrid framework and exit\n";
238 std::clog << o("-V") << "print version and exit\n";
240 std::clog << "\nSimulation parameters\n";
241 std::clog << o("-l value")
242 << "print current load every n-th iterations, 0 to disable"
243 << " (" << opt::log_rate << ")\n";
245 << "verbose: do not override the default logging parameters\n";
247 std::clog << "\nAutomatic deployment options\n";
248 std::clog << o("-T name")
249 << "enable automatic deployment with selected topology"
250 << " (" << opt::auto_depl::topology << ")\n";
251 if (opt::help_requested > 1)
252 so_list(opt::topologies);
253 std::clog << o("-L value")
254 << "total load with auto deployment, 0 for number of hosts"
255 << " (" << opt::auto_depl::load << ")\n";
256 std::clog << o("-N value")
257 << "number of hosts to use with auto deployment,"
258 << " 0 for max. (" << opt::auto_depl::nhosts << ")\n";
260 std::clog << "\nLoad balancing algorithm\n";
261 std::clog << o("-a name") << "load balancing algorithm"
262 << " (" << opt::loba_algo << ")\n";
263 if (opt::help_requested > 1)
264 so_list(opt::loba_algorithms);
265 std::clog << o("-b") << "enable bookkeeping\n";
267 std::clog << "\nApplication parameters\n";
268 std::clog << o("-c [fn,...]f0")
269 << "polynomial factors for computation cost"
270 << " (" << opt::comp_cost.to_string() << ")\n";
271 std::clog << o("-C [fn,...]f0")
272 << "polynomial factors for communication cost"
273 << " (" << opt::comm_cost.to_string() << ")\n";
274 std::clog << o("-e") << "exit on reception of \"close\" message\n";
275 std::clog << o("-i value")
276 << "maximum number of iterations, 0 for infinity"
277 << " (" << opt::maxiter << ")\n";
279 if (opt::help_requested < 3)
282 std::clog << "\nLogging support\n"
283 << " See SimGrid documentation on:\n"
284 << " http://simgrid.gforge.inria.fr/doc/group__XBT__log.html#log_user\n"
285 << " Existing categories are:\n"
286 << " simu : root of following categories\n"
287 << " main : messages from global infrastructure\n"
288 << " depl : messages from auto deployment (inherited from main)\n"
289 << " comm : messages from asynchronous pipes\n"
290 << " proc : messages from base process class\n"
291 << " loba : messages from load-balancer\n";