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("none");
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 THIS_INSERT("none", "no load-balancing", process);
49 THIS_INSERT("simple", "balance with least loaded neighbor",
54 topologies_type topologies;
55 topologies_type::topologies_type()
57 THIS_INSERT("none", "no load-balancing", process);
58 THIS_INSERT("simple", "balance with least loaded neighbor",
67 const char* on_off(bool b)
69 return b ? "on" : "off";
74 int opt::parse_args(int* argc, char* argv[])
78 opt::program_name = argv[0];
79 opt::program_name.erase(0, 1 + opt::program_name.find_last_of('/'));
83 while ((c = getopt(*argc, argv, "a:bc:C:ehi:l:L:N:T:V")) != -1) {
86 opt::loba_algo = optarg;
89 opt::bookkeeping = true;
92 opt::exit_on_close = true;
95 opt::help_requested++;
98 opt::comp_cost = cost_func(optarg);
101 opt::comm_cost = cost_func(optarg);
104 std::istringstream(optarg) >> opt::maxiter;
107 std::istringstream(optarg) >> opt::log_rate;
110 std::istringstream(optarg) >> opt::auto_depl::load;
113 std::istringstream(optarg) >> opt::auto_depl::nhosts;
116 opt::auto_depl::topology = optarg;
119 opt::version_requested = true;
122 ERROR1("invalid option -- '%c'", optopt);
127 opt::auto_depl::enabled = !opt::auto_depl::topology.empty();
129 if (opt::version_requested || opt::help_requested)
132 if (optind < *argc) {
133 opt::platform_file = argv[optind++];
135 ERROR0("missing parameter -- <plaform_file>");
138 if (!opt::auto_depl::enabled) {
139 if (optind < *argc) {
140 opt::deployment_file = argv[optind++];
142 ERROR0("missing parameter -- <deployment_file>");
147 while (optind < *argc) {
148 ERROR1("unused parameter -- \"%s\"", argv[optind++]);
157 INFO0(",----[ Simulation parameters ]");
158 INFO1("| platform file.......: \"%s\"", opt::platform_file.c_str());
159 if (opt::auto_depl::enabled) {
160 INFO0("| automatic deployment enabled with:");
161 INFO1("| topology........: %s", opt::auto_depl::topology.c_str());
162 INFO1("| number of hosts.: %u", opt::auto_depl::nhosts);
163 INFO1("| initial load....: %g", opt::auto_depl::load);
165 INFO1("| deployment file.....: \"%s\"", opt::deployment_file.c_str());
167 INFO1("| log rate............: %u", opt::log_rate);
168 INFO1("| maxiter.............: %u", opt::maxiter);
169 INFO1("| exit on close.......: %s", on_off(opt::exit_on_close));
170 INFO1("| bookkeeping.........: %s", on_off(opt::bookkeeping));
171 INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str());
172 INFO1("| comm. cost factors..: [%s]", opt::comm_cost.to_string().c_str());
179 #define o(opt) " " << std::setw(14) \
180 << std::left << (opt) << std::right << " "
182 #define so(subopt) std::setw(18) << (subopt) << " : "
184 #define so_list(name) do { \
185 name ## _type::iterator it; \
186 for (it = name.begin() ; it != name.end() ; ++it) \
187 std::clog << so(name.get_name(it)) \
188 << name.get_descr(it) << "\n"; \
192 std::clog << "Usage: " << opt::program_name
193 << " [options] <platform_file> <deployment_file>\n";
194 std::clog << " " << opt::program_name
195 << " [options] -T type <platform_file>\n";
197 std::clog << "\nGlobal options\n";
199 << "print help and exit (use -hh for extended help)\n";
200 if (opt::help_requested < 1)
203 std::clog << o("--help") << "print help from SimGrid framework and exit\n";
204 std::clog << o("-V") << "print version and exit\n";
206 std::clog << "\nSimulation parameters\n";
207 std::clog << o("-l value")
208 << "print current load every n-th iterations, 0 to disable"
209 << " (" << opt::log_rate << ")\n";
211 std::clog << "\nAutomatic deployment options\n";
212 std::clog << o("-T name")
213 << "enable automatic deployment with selected topology\n";
214 if (opt::help_requested > 1)
216 so_list(opt::topologies);
218 std::clog << so("name") << "FIXME\n"; // fixme
220 std::clog << o("-L value")
221 << "total load with auto deployment, 0 for number of hosts"
222 << " (" << opt::auto_depl::load << ")\n";
223 std::clog << o("-N value")
224 << "number of hosts to use with auto deployment,"
225 << " 0 for max. (" << opt::auto_depl::nhosts << ")\n";
227 std::clog << "\nLoad balancing algorithm\n";
228 std::clog << o("-a name") << "load balancing algorithm"
229 << " (" << opt::loba_algo << ")\n";
230 if (opt::help_requested > 1)
231 so_list(opt::loba_algorithms);
232 std::clog << o("-b") << "enable bookkeeping\n";
234 std::clog << "\nApplication parameters\n";
235 std::clog << o("-c [fn,...]f0")
236 << "polynomial factors for computation cost"
237 << " (" << opt::comp_cost.to_string() << ")\n";
238 std::clog << o("-C [fn,...]f0")
239 << "polynomial factors for communication cost"
240 << " (" << opt::comm_cost.to_string() << ")\n";
241 std::clog << o("-e") << "exit on reception of \"close\" message\n";
242 std::clog << o("-i value")
243 << "maximum number of iterations, 0 for infinity"
244 << " (" << opt::maxiter << ")\n";