6 #include <unistd.h> // getopt
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
14 std::string program_name;
16 std::string platform_file;
17 std::string deployment_file;
19 int help_requested = 0;
20 bool version_requested = false;
22 unsigned log_rate = 1;
31 unsigned maxiter = 4; // fixme
32 bool exit_on_close = false;
34 bool bookkeeping = false;
36 cost_func comp_cost("1e9, 0"); // fixme: find better defaults
37 cost_func comm_cost("1, 0"); // fixme: find better defaults
43 const char* on_off(bool b)
45 return b ? "on" : "off";
50 int opt::parse_args(int* argc, char* argv[])
54 opt::program_name = argv[0];
55 opt::program_name.erase(0, 1 + opt::program_name.find_last_of('/'));
59 while ((c = getopt(*argc, argv, "bc:C:ehi:l:L:N:T:V")) != -1) {
62 opt::bookkeeping = true;
65 opt::exit_on_close = true;
68 opt::help_requested++;
71 opt::comp_cost = cost_func(optarg);
74 opt::comm_cost = cost_func(optarg);
77 std::istringstream(optarg) >> opt::maxiter;
80 std::istringstream(optarg) >> opt::log_rate;
83 std::istringstream(optarg) >> opt::auto_depl::load;
86 std::istringstream(optarg) >> opt::auto_depl::nhosts;
89 opt::auto_depl::topology = optarg;
92 opt::version_requested = true;
95 ERROR1("invalid option -- '%c'", optopt);
100 opt::auto_depl::enabled = !opt::auto_depl::topology.empty();
102 if (opt::version_requested || opt::help_requested)
105 if (optind < *argc) {
106 opt::platform_file = argv[optind++];
108 ERROR0("missing parameter -- <plaform_file>");
111 if (!opt::auto_depl::enabled) {
112 if (optind < *argc) {
113 opt::deployment_file = argv[optind++];
115 ERROR0("missing parameter -- <deployment_file>");
120 while (optind < *argc) {
121 ERROR1("unused parameter -- \"%s\"", argv[optind++]);
130 INFO0(",----[ Simulation parameters ]");
131 INFO1("| platform file.......: \"%s\"", opt::platform_file.c_str());
132 if (opt::auto_depl::enabled) {
133 INFO0("| automatic deployment enabled with:");
134 INFO1("| topology........: %s", opt::auto_depl::topology.c_str());
135 INFO1("| number of hosts.: %u", opt::auto_depl::nhosts);
136 INFO1("| initial load....: %g", opt::auto_depl::load);
138 INFO1("| deployment file.....: \"%s\"", opt::deployment_file.c_str());
140 INFO1("| log rate............: %u", opt::log_rate);
141 INFO1("| maxiter.............: %u", opt::maxiter);
142 INFO1("| exit on close.......: %s", on_off(opt::exit_on_close));
143 INFO1("| bookkeeping.........: %s", on_off(opt::bookkeeping));
144 INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str());
145 INFO1("| comm. cost factors..: [%s]", opt::comm_cost.to_string().c_str());
151 #define o(opt) " " << std::setw(14) \
152 << std::left << (opt) << std::right << " "
153 #define so(subopt) std::setw(10) << (subopt) << ": "
155 std::clog << "Usage: " << opt::program_name
156 << " [options] <platform_file> <deployment_file>\n";
157 std::clog << " " << opt::program_name
158 << " [options] -T type <platform_file>\n";
160 std::clog << "\nGlobal options\n";
162 << "print help and exit (use -hh for extended help)\n";
163 if (opt::help_requested < 1)
166 std::clog << o("--help") << "print help from SimGrid framework and exit\n";
167 std::clog << o("-V") << "print version and exit\n";
169 std::clog << "\nSimulation parameters\n";
170 std::clog << o("-l value")
171 << "print current load every n-th iterations, 0 to disable"
172 << " (" << opt::log_rate << ")\n";
174 std::clog << "\nApplication parameters\n";
175 std::clog << o("-c [fn,...]f0")
176 << "polynomial factors for computation cost"
177 << " (" << opt::comp_cost.to_string() << ")\n";
178 std::clog << o("-C [fn,...]f0")
179 << "polynomial factors for communication cost"
180 << " (" << opt::comm_cost.to_string() << ")\n";
181 std::clog << o("-e") << "exit on reception of \"close\" message\n";
182 std::clog << o("-i value")
183 << "maximum number of iterations, 0 for infinity"
184 << " (" << opt::maxiter << ")\n";
186 std::clog << "\nLoad balancing algorithm\n";
187 std::clog << o("-b") << "enable bookkeeping\n";
189 std::clog << "\nAutomatic deployment options\n";
190 std::clog << o("-T type")
191 << "enable automatic deployment with selected topology\n";
192 if (opt::help_requested > 1) {
193 std::clog << so(1) << "pipo\n";
194 std::clog << so(42) << "atchoum\n";
196 std::clog << o("-L value")
197 << "total load with auto deployment, 0 for number of hosts"
198 << " (" << opt::auto_depl::load << ")\n";
199 std::clog << o("-N value")
200 << "number of hosts to use with auto deployment,"
201 << " 0 for max. (" << opt::auto_depl::nhosts << ")\n";