6 #include <unistd.h> // getopt
8 #include "loba_simple.h"
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
15 std::string program_name;
16 int help_requested = 0;
17 bool version_requested = false;
19 // Simulation parameters
20 unsigned log_rate = 1;
22 // Platform and deployment
23 std::string platform_file;
24 std::string deployment_file;
26 // Automatic deployment
34 // Load balancing algorithm
35 std::string loba_algo("simple");
36 bool bookkeeping = false;
38 // Application parameters
39 cost_func comp_cost("1e9, 0"); // fixme: find better defaults
40 cost_func comm_cost("1, 0"); // fixme: find better defaults
41 unsigned maxiter = 4; // fixme
42 bool exit_on_close = false;
44 // Named parameters lists
45 loba_algorithms_type loba_algorithms;
46 loba_algorithms_type::loba_algorithms_type()
48 NOL_INSERT("none", "no load-balancing (for testing)", process);
49 NOL_INSERT("simple", "balance with least loaded neighbor", loba_simple);
53 topologies_type topologies;
54 topologies_type::topologies_type()
56 NOL_INSERT("line", "line topology, initial load at one end", xxx);
57 NOL_INSERT("ring", "ring topology", xxx);
58 NOL_INSERT("star", "star topology, initial load at center", xxx);
59 NOL_INSERT("clique", "all connected topology", xxx);
60 NOL_INSERT("btree", "binary tree topologym intiial load at root", xxx);
61 NOL_INSERT("hcube", "hypercube topology", xxx);
69 const char* on_off(bool b)
71 return b ? "on" : "off";
76 int opt::parse_args(int* argc, char* argv[])
80 opt::program_name = argv[0];
81 opt::program_name.erase(0, 1 + opt::program_name.find_last_of('/'));
85 while ((c = getopt(*argc, argv, "a:bc:C:ehi:l:L:N:T:V")) != -1) {
88 opt::loba_algo = optarg;
89 if (!opt::loba_algorithms.exists(opt::loba_algo)) {
90 ERROR1("unknownw load balancing algorithm -- %s",
91 opt::loba_algo.c_str());
96 opt::bookkeeping = true;
99 opt::exit_on_close = true;
102 opt::help_requested++;
105 opt::comp_cost = cost_func(optarg);
108 opt::comm_cost = cost_func(optarg);
111 std::istringstream(optarg) >> opt::maxiter;
114 std::istringstream(optarg) >> opt::log_rate;
117 std::istringstream(optarg) >> opt::auto_depl::load;
120 std::istringstream(optarg) >> opt::auto_depl::nhosts;
123 opt::auto_depl::topology = optarg;
126 opt::version_requested = true;
129 ERROR1("invalid option -- '%c'", optopt);
134 opt::auto_depl::enabled = !opt::auto_depl::topology.empty();
136 if (opt::version_requested || opt::help_requested)
139 if (optind < *argc) {
140 opt::platform_file = argv[optind++];
142 ERROR0("missing parameter -- <plaform_file>");
145 if (!opt::auto_depl::enabled) {
146 if (optind < *argc) {
147 opt::deployment_file = argv[optind++];
149 ERROR0("missing parameter -- <deployment_file>");
154 while (optind < *argc) {
155 ERROR1("unused parameter -- \"%s\"", argv[optind++]);
164 INFO0(",----[ Simulation parameters ]");
165 INFO1("| log rate.....................: %u", opt::log_rate);
166 INFO1("| platform file................: \"%s\"", opt::platform_file.c_str());
167 if (opt::auto_depl::enabled) {
168 INFO0("| automatic deployment enabled");
169 INFO1("| - topology...................: %s", opt::auto_depl::topology.c_str());
170 INFO1("| - number of hosts............: %u", opt::auto_depl::nhosts);
171 INFO1("| - initial load...............: %g", opt::auto_depl::load);
173 INFO1("| deployment file..............: \"%s\"", opt::deployment_file.c_str());
175 INFO1("| load balancing algorithm.....: %s", opt::loba_algo.c_str());
176 INFO1("| bookkeeping..................: %s", on_off(opt::bookkeeping));
177 INFO1("| computation cost factors.....: [%s]", opt::comp_cost.to_string().c_str());
178 INFO1("| communication cost factors...: [%s]", opt::comm_cost.to_string().c_str());
179 INFO1("| maximum number of iterations.: %u", opt::maxiter);
180 INFO1("| exit on close................: %s", on_off(opt::exit_on_close));
187 #define o(opt) " " << std::setw(14) \
188 << std::left << (opt) << std::right << " "
190 #define so(subopt) std::setw(18) << (subopt) << " : "
192 #define so_list(name) do { \
193 name ## _type::iterator it; \
194 for (it = name.begin() ; it != name.end() ; ++it) \
195 std::clog << so(name.get_name(it)) \
196 << name.get_descr(it) << "\n"; \
200 std::clog << "Usage: " << opt::program_name
201 << " [options] <platform_file> <deployment_file>\n";
202 std::clog << " " << opt::program_name
203 << " [options] -T type <platform_file>\n";
205 std::clog << "\nGlobal options\n";
207 << "print help and exit (use -hh for extended help)\n";
208 if (opt::help_requested < 1)
211 std::clog << o("--help") << "print help from SimGrid framework and exit\n";
212 std::clog << o("-V") << "print version and exit\n";
214 std::clog << "\nSimulation parameters\n";
215 std::clog << o("-l value")
216 << "print current load every n-th iterations, 0 to disable"
217 << " (" << opt::log_rate << ")\n";
219 std::clog << "\nAutomatic deployment options\n";
220 std::clog << o("-T name")
221 << "enable automatic deployment with selected topology\n";
222 if (opt::help_requested > 1)
224 so_list(opt::topologies);
226 std::clog << so("name") << "FIXME\n"; // fixme
228 std::clog << o("-L value")
229 << "total load with auto deployment, 0 for number of hosts"
230 << " (" << opt::auto_depl::load << ")\n";
231 std::clog << o("-N value")
232 << "number of hosts to use with auto deployment,"
233 << " 0 for max. (" << opt::auto_depl::nhosts << ")\n";
235 std::clog << "\nLoad balancing algorithm\n";
236 std::clog << o("-a name") << "load balancing algorithm"
237 << " (" << opt::loba_algo << ")\n";
238 if (opt::help_requested > 1)
239 so_list(opt::loba_algorithms);
240 std::clog << o("-b") << "enable bookkeeping\n";
242 std::clog << "\nApplication parameters\n";
243 std::clog << o("-c [fn,...]f0")
244 << "polynomial factors for computation cost"
245 << " (" << opt::comp_cost.to_string() << ")\n";
246 std::clog << o("-C [fn,...]f0")
247 << "polynomial factors for communication cost"
248 << " (" << opt::comm_cost.to_string() << ")\n";
249 std::clog << o("-e") << "exit on reception of \"close\" message\n";
250 std::clog << o("-i value")
251 << "maximum number of iterations, 0 for infinity"
252 << " (" << opt::maxiter << ")\n";