4 #include <unistd.h> // getopt
7 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
9 #include "loba_simple.h"
10 #include "loba_fairstrategy.h"
17 std::string program_name;
18 int help_requested = 0;
19 bool version_requested = false;
21 // Simulation parameters
22 unsigned log_rate = 1;
24 // Platform and deployment
25 std::string platform_file;
26 std::string deployment_file;
28 // Automatic deployment
31 std::string topology("clique");
36 // Load balancing algorithm
37 std::string loba_algo("simple");
38 bool bookkeeping = false;
40 // Application parameters
41 cost_func comp_cost("1e9, 0"); // fixme: find better defaults
42 cost_func comm_cost("1, 0"); // fixme: find better defaults
43 unsigned maxiter = 10; // fixme: find better defaults
44 bool exit_on_close = false;
46 // Named parameters lists
47 loba_algorithms_type loba_algorithms;
48 loba_algorithms_type::loba_algorithms_type()
50 NOL_INSERT("fairstrategy", "balance with fair strategy", loba_fairstrategy);
51 NOL_INSERT("none", "no load-balancing (for testing)", process);
52 NOL_INSERT("simple", "balance with least loaded neighbor", loba_simple);
55 topologies_type topologies;
56 topologies_type::topologies_type()
58 NOL_INSERT("btree", "binary tree topologym intiial load at root",
60 NOL_INSERT("clique", "all connected topology", deployment_clique);
61 NOL_INSERT("hcube", "hypercube topology", deployment_hcube);
62 NOL_INSERT("line", "line topology, initial load at one end",
64 NOL_INSERT("ring", "ring topology", deployment_ring);
65 NOL_INSERT("star", "star topology, initial load at center",
67 NOL_INSERT("torus", "torus topology", deployment_torus);
72 int opt::parse_args(int* argc, char* argv[])
76 opt::program_name = argv[0];
77 opt::program_name.erase(0, 1 + opt::program_name.find_last_of('/'));
81 while ((c = getopt(*argc, argv, "a:bc:C:ehi:l:L:N:T:vV")) != -1) {
84 opt::loba_algo = optarg;
85 if (!opt::loba_algorithms.exists(opt::loba_algo)) {
86 ERROR1("unknownw load balancing algorithm -- %s",
87 opt::loba_algo.c_str());
92 opt::bookkeeping = true;
95 opt::exit_on_close = true;
98 opt::help_requested++;
101 opt::comp_cost = cost_func(optarg);
104 opt::comm_cost = cost_func(optarg);
107 std::istringstream(optarg) >> opt::maxiter;
110 std::istringstream(optarg) >> opt::log_rate;
113 std::istringstream(optarg) >> opt::auto_depl::load;
116 std::istringstream(optarg) >> opt::auto_depl::nhosts;
119 opt::auto_depl::topology = optarg;
120 if (!opt::topologies.exists(opt::auto_depl::topology)) {
121 ERROR1("unknownw topology -- %s",
122 opt::auto_depl::topology.c_str());
127 // nothing to do: this option is checked at the very
128 // beginning of main()
131 opt::version_requested = true;
134 ERROR1("invalid option -- '%c'", optopt);
140 if (opt::version_requested || opt::help_requested)
143 if (optind < *argc) {
144 opt::platform_file = argv[optind++];
146 ERROR0("missing parameter -- <plaform_file>");
149 if (optind < *argc) {
150 opt::deployment_file = argv[optind++];
152 opt::auto_depl::enabled = opt::deployment_file.empty();
154 while (optind < *argc) {
155 ERROR1("unused parameter -- \"%s\"", argv[optind++]);
164 // some helper functions for opt::print()
166 const char* on_off(bool b)
168 return b ? "on" : "off";
171 template <typename T>
172 const char* val_or_string(const T& val, const char* str, const T& deflt = 0)
174 static std::string res;
176 std::ostringstream oss;
189 INFO0(",----[ Simulation parameters ]");
190 INFO1("| log rate.....................: %s",
191 val_or_string(opt::log_rate, "disabled"));
192 INFO1("| platform file................: \"%s\"", opt::platform_file.c_str());
193 if (opt::auto_depl::enabled) {
194 INFO0("| automatic deployment enabled");
195 INFO1("| - topology...................: %s", opt::auto_depl::topology.c_str());
196 INFO1("| - number of hosts............: %s",
197 val_or_string(opt::auto_depl::nhosts, "auto"));
198 INFO1("| - initial load...............: %s",
199 val_or_string(opt::auto_depl::load, "auto"));
201 INFO1("| deployment file..............: \"%s\"", opt::deployment_file.c_str());
203 INFO1("| load balancing algorithm.....: %s", opt::loba_algo.c_str());
204 INFO1("| bookkeeping..................: %s", on_off(opt::bookkeeping));
205 INFO1("| computation cost factors.....: [%s]", opt::comp_cost.to_string().c_str());
206 INFO1("| communication cost factors...: [%s]", opt::comm_cost.to_string().c_str());
207 INFO1("| maximum number of iterations.: %s",
208 val_or_string(opt::maxiter, "infinity"));
209 INFO1("| exit on close................: %s", on_off(opt::exit_on_close));
216 #define o(opt) " " << std::setw(14) \
217 << std::left << (opt) << std::right << " "
219 #define so(subopt) std::setw(18) << (subopt) << " : "
221 #define so_list(name) do { \
222 name ## _type::iterator it; \
223 for (it = name.begin() ; it != name.end() ; ++it) \
224 std::clog << so(name.get_name(it)) \
225 << name.get_descr(it) << "\n"; \
229 std::clog << "Usage: " << opt::program_name
230 << " [options] <platform_file> [<deployment_file>]\n";
232 std::clog << "\nGlobal options\n";
234 << "print help and exit (use -hh or -hhh for extended help)\n";
235 if (opt::help_requested < 1)
238 std::clog << o("--help") << "print help from SimGrid framework and exit\n";
239 std::clog << o("-V") << "print version and exit\n";
241 std::clog << "\nSimulation parameters\n";
242 std::clog << o("-l value")
243 << "print current load every n-th iterations, 0 to disable"
244 << " (" << opt::log_rate << ")\n";
246 << "verbose: do not override the default logging parameters\n";
248 std::clog << "\nAutomatic deployment options\n";
249 std::clog << o("-T name")
250 << "enable automatic deployment with selected topology"
251 << " (" << opt::auto_depl::topology << ")\n";
252 if (opt::help_requested > 1)
253 so_list(opt::topologies);
254 std::clog << o("-L value")
255 << "total load with auto deployment, 0 for number of hosts"
256 << " (" << opt::auto_depl::load << ")\n";
257 std::clog << o("-N value")
258 << "number of hosts to use with auto deployment,"
259 << " 0 for max. (" << opt::auto_depl::nhosts << ")\n";
261 std::clog << "\nLoad balancing algorithm\n";
262 std::clog << o("-a name") << "load balancing algorithm"
263 << " (" << opt::loba_algo << ")\n";
264 if (opt::help_requested > 1)
265 so_list(opt::loba_algorithms);
266 std::clog << o("-b") << "enable bookkeeping\n";
268 std::clog << "\nApplication parameters\n";
269 std::clog << o("-c [fn,...]f0")
270 << "polynomial factors for computation cost"
271 << " (" << opt::comp_cost.to_string() << ")\n";
272 std::clog << o("-C [fn,...]f0")
273 << "polynomial factors for communication cost"
274 << " (" << opt::comm_cost.to_string() << ")\n";
275 std::clog << o("-e") << "exit on reception of \"close\" message\n";
276 std::clog << o("-i value")
277 << "maximum number of iterations, 0 for infinity"
278 << " (" << opt::maxiter << ")\n";
280 if (opt::help_requested < 3)
283 std::clog << "\nLogging support\n"
284 << " See SimGrid documentation on:\n"
285 << " http://simgrid.gforge.inria.fr/doc/group__XBT__log.html#log_user\n"
286 << " Existing categories are:\n"
287 << " simu : root of following categories\n"
288 << " main : messages from global infrastructure\n"
289 << " depl : messages from auto deployment (inherited from main)\n"
290 << " comm : messages from asynchronous pipes\n"
291 << " proc : messages from base process class\n"
292 << " loba : messages from load-balancer\n";