3 #include <cstring> // strrchr
7 #include <unistd.h> // getopt
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
15 const char* program_name;
17 const char* platform_file;
18 const char* application_file;
20 int help_requested = 0;
21 bool version_requested = false;
23 unsigned log_rate = 1;
26 bool exit_on_close = false;
28 bool bookkeeping = false;
30 cost_func comp_cost("1e9, 0"); // fixme: find better defaults
31 cost_func comm_cost("1, 0"); // fixme: find better defaults
37 const char* on_off(bool b)
39 return b ? "on" : "off";
44 int opt::parse_args(int* argc, char* argv[])
48 char* tmp = strrchr(argv[0], '/');
49 opt::program_name = (tmp ? tmp + 1 : argv[0]);
53 while ((c = getopt(*argc, argv, "bc:C:ehi:l:V")) != -1) {
56 opt::bookkeeping = true;
59 opt::exit_on_close = true;
62 opt::help_requested++;
65 opt::comp_cost = cost_func(optarg);
68 opt::comm_cost = cost_func(optarg);
71 std::istringstream(optarg) >> opt::maxiter;
74 std::istringstream(optarg) >> opt::log_rate;
77 opt::version_requested = true;
80 ERROR1("invalid option -- '%c'", optopt);
85 if (opt::version_requested || opt::help_requested)
88 int rem_args = *argc - optind;
91 ERROR0("missing parameter -- <plaform_file>");
93 ERROR0("missing parameter -- <application_file>");
98 opt::platform_file = argv[optind];
99 opt::application_file = argv[optind + 1];
102 for (int i = optind + 2 ; i < *argc ; ++i)
103 ERROR1("unused parameter -- \"%s\"", argv[i]);
113 INFO0(",----[ Simulation parameters ]");
114 INFO1("| platform_file.......: \"%s\"", opt::platform_file);
115 INFO1("| application_file....: \"%s\"", opt::application_file);
116 INFO1("| log rate............: %u", opt::log_rate);
117 INFO1("| maxiter.............: %u", opt::maxiter);
118 INFO1("| exit on close.......: %s", on_off(opt::exit_on_close));
119 INFO1("| bookkeeping.........: %s", on_off(opt::bookkeeping));
120 INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str());
121 INFO1("| comm. cost factors..: [%s]", opt::comm_cost.to_string().c_str());
127 const int indent1 = 6;
128 const int indent2 = 12;
130 #define oo(opt, arg) std::setw(indent1) << (opt) << " " \
131 << std::setw(indent2) << std::left << (arg) << std::right
132 #define o(opt) oo(opt, "")
134 std::clog << "Usage: " << opt::program_name
135 << " [options] <platform_file> <application_file>\n";
138 << "print help and exit (use -hh or -hhh for extended help)\n";
139 if (opt::help_requested < 1)
142 std::clog << o("-V") << "print version and exit\n";
144 std::clog << o("-b") << "activate bookkeeping\n";
145 std::clog << oo("-c", "[fn,...]f0")
146 << "polynomial factors for computation cost ("
147 << opt::comp_cost.to_string() << ")\n";
148 std::clog << oo("-C", "[fn,...]f0")
149 << "polynomial factors for communication cost ("
150 << opt::comm_cost.to_string() << ")\n";
151 std::clog << o("-e") << "exit on close reception\n";
152 std::clog << oo("-i", "value")
153 << "maximum number of iterations, 0 for infinity ("
154 << opt::maxiter << ")\n";
155 std::clog << oo("-l", "value")
156 << "print current load every \"value\" iterations, 0 to disable ("
157 << opt::log_rate << ")\n";