Skip to content

Commit 9be2807

Browse files
committed
command line arguments support added to SDK, copied files used by LF
1 parent fb31d00 commit 9be2807

File tree

11 files changed

+2951
-54
lines changed

11 files changed

+2951
-54
lines changed

examples/sdk-SrcSink-Fanout/main.cc

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,40 @@ using namespace std;
88
using namespace sdk;
99

1010
int main(int argc, char **argv) {
11-
unsigned workers = 1;
11+
cxxopts::Options options("sdk-SrcSink-Fanout", "Multiport source connecting to banked sink reactors");
12+
13+
unsigned workers = std::thread::hardware_concurrency();
1214
bool fast{false};
1315
reactor::Duration timeout = reactor::Duration::max();
16+
bool visualize{false};
17+
18+
// the timeout variable needs to be tested beyond fitting the Duration-type
19+
options
20+
.set_width(120)
21+
.add_options()
22+
("w,workers", "the number of worker threads used by the scheduler", cxxopts::value<unsigned>(workers)->default_value(std::to_string(workers)), "'unsigned'")
23+
("o,timeout", "Time after which the execution is aborted.", cxxopts::value<reactor::Duration>(timeout)->default_value(time_to_string(timeout)), "'FLOAT UNIT'")
24+
("f,fast", "Allow logical time to run faster than physical time.", cxxopts::value<bool>(fast)->default_value("false"))
25+
("v,visualize", "Generate graph.dot file of the topology.", cxxopts::value<bool>(visualize)->default_value("false"))
26+
("help", "Print help");
27+
28+
cxxopts::ParseResult result{};
29+
bool parse_error{false};
30+
try {
31+
result = options.parse(argc, argv);
32+
} catch (const cxxopts::OptionException& e) {
33+
reactor::log::Error() << e.what();
34+
parse_error = true;
35+
}
1436

15-
bool visualize = false;
16-
17-
if (argc > 1) {
18-
string v_str = argv[1];
19-
visualize = (v_str == "true") ? true : false;
37+
// if parameter --help was used or there was a parse error, print help
38+
if (parse_error || result.count("help"))
39+
{
40+
std::cout << options.help({""});
41+
return parse_error ? -1 : 0;
2042
}
2143

22-
std::cout << "parameters - workers:" << workers << " fast:" << (fast ? "True" : "False") << " timeout:" << timeout << " visualize:" << visualize << std::endl;
44+
std::cout << "parameters - workers:" << workers << " fast:" << (fast ? "True" : "False") << " timeout:" << timeout << " visualize:" << (visualize ? "True" : "False") << std::endl;
2345

2446
Environment sim {&cfg_parameters, workers, fast, timeout, visualize};
2547
auto main = new MainReactor("Main", &sim);

examples/sdk-SrcSink/Config-a/Config-a.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ ConfigParameter<int, uint32_t>::ParametersMap UserParameters::homogeneous_config
1111
ConfigParameter<int, uint32_t>::ParametersMap UserParameters::heterogeneous_config() {
1212
return {
1313
{"Main.Source.iterations", ConfigParameterMetadata<int> { 20 } },
14-
{"Main.Source.n_ports", ConfigParameterMetadata<int> { 2 } },
15-
{"Main.n_sinks", ConfigParameterMetadata<int> { 2 } },
14+
{"Main.Source.n_ports", ConfigParameterMetadata<int> { 4 } },
15+
{"Main.n_sinks", ConfigParameterMetadata<int> { 4 } },
1616

1717
};
1818
}

examples/sdk-SrcSink/Main/MainReactor.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,4 @@ void MainReactor::assembling() {
3636
"Starting up reaction\n" << "Bank:" << bank_index << " name:" << parameters.alias.value << " fqn:" << fqn() << " n_sinks:" << parameters.n_sinks.value << endl;
3737
}
3838
);
39-
40-
reaction("reaction_2").
41-
triggers(&snk[0].rsp).
42-
effects().
43-
function(
44-
[&](Output<int>& rsp) {
45-
cout << "(" << get_elapsed_logical_time() << ", " << get_microstep() << "), physical_time: " << get_elapsed_physical_time() << " " <<
46-
"Response\n" << "Bank:" << bank_index << " value:" << *rsp.get() << endl;
47-
}
48-
);
4939
}

examples/sdk-SrcSink/main.cc

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,40 @@ using namespace std;
88
using namespace sdk;
99

1010
int main(int argc, char **argv) {
11-
unsigned workers = 1;
11+
cxxopts::Options options("sdk-SrcSink", "Multiport source connecting to banked sink reactors");
12+
13+
unsigned workers = std::thread::hardware_concurrency();
1214
bool fast{false};
1315
reactor::Duration timeout = reactor::Duration::max();
16+
bool visualize{false};
17+
18+
// the timeout variable needs to be tested beyond fitting the Duration-type
19+
options
20+
.set_width(120)
21+
.add_options()
22+
("w,workers", "the number of worker threads used by the scheduler", cxxopts::value<unsigned>(workers)->default_value(std::to_string(workers)), "'unsigned'")
23+
("o,timeout", "Time after which the execution is aborted.", cxxopts::value<reactor::Duration>(timeout)->default_value(time_to_string(timeout)), "'FLOAT UNIT'")
24+
("f,fast", "Allow logical time to run faster than physical time.", cxxopts::value<bool>(fast)->default_value("false"))
25+
("v,visualize", "Generate graph.dot file of the topology.", cxxopts::value<bool>(visualize)->default_value("false"))
26+
("help", "Print help");
27+
28+
cxxopts::ParseResult result{};
29+
bool parse_error{false};
30+
try {
31+
result = options.parse(argc, argv);
32+
} catch (const cxxopts::OptionException& e) {
33+
reactor::log::Error() << e.what();
34+
parse_error = true;
35+
}
1436

15-
bool visualize = false;
16-
17-
if (argc > 1) {
18-
string v_str = argv[1];
19-
visualize = (v_str == "true") ? true : false;
37+
// if parameter --help was used or there was a parse error, print help
38+
if (parse_error || result.count("help"))
39+
{
40+
std::cout << options.help({""});
41+
return parse_error ? -1 : 0;
2042
}
2143

22-
std::cout << "parameters - workers:" << workers << " fast:" << (fast ? "True" : "False") << " timeout:" << timeout << " visualize:" << visualize << std::endl;
44+
std::cout << "parameters - workers:" << workers << " fast:" << (fast ? "True" : "False") << " timeout:" << timeout << " visualize:" << (visualize ? "True" : "False") << std::endl;
2345

2446
Environment sim {&cfg_parameters, workers, fast, timeout, visualize};
2547
auto main = new MainReactor("Main", &sim);

examples/sdk-deadlines/main.cc

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,40 @@ using namespace std;
88
using namespace sdk;
99

1010
int main(int argc, char **argv) {
11-
unsigned workers = 1;
11+
cxxopts::Options options("sdk-deadlines", "Multiport source connecting to banked sink reactors");
12+
13+
unsigned workers = std::thread::hardware_concurrency();
1214
bool fast{false};
1315
reactor::Duration timeout = reactor::Duration::max();
16+
bool visualize{false};
17+
18+
// the timeout variable needs to be tested beyond fitting the Duration-type
19+
options
20+
.set_width(120)
21+
.add_options()
22+
("w,workers", "the number of worker threads used by the scheduler", cxxopts::value<unsigned>(workers)->default_value(std::to_string(workers)), "'unsigned'")
23+
("o,timeout", "Time after which the execution is aborted.", cxxopts::value<reactor::Duration>(timeout)->default_value(time_to_string(timeout)), "'FLOAT UNIT'")
24+
("f,fast", "Allow logical time to run faster than physical time.", cxxopts::value<bool>(fast)->default_value("false"))
25+
("v,visualize", "Generate graph.dot file of the topology.", cxxopts::value<bool>(visualize)->default_value("false"))
26+
("help", "Print help");
27+
28+
cxxopts::ParseResult result{};
29+
bool parse_error{false};
30+
try {
31+
result = options.parse(argc, argv);
32+
} catch (const cxxopts::OptionException& e) {
33+
reactor::log::Error() << e.what();
34+
parse_error = true;
35+
}
1436

15-
bool visualize = false;
16-
17-
if (argc > 1) {
18-
string v_str = argv[1];
19-
visualize = (v_str == "true") ? true : false;
37+
// if parameter --help was used or there was a parse error, print help
38+
if (parse_error || result.count("help"))
39+
{
40+
std::cout << options.help({""});
41+
return parse_error ? -1 : 0;
2042
}
2143

22-
std::cout << "parameters - workers:" << workers << " fast:" << (fast ? "True" : "False") << " timeout:" << timeout << " visualize:" << visualize << std::endl;
44+
std::cout << "parameters - workers:" << workers << " fast:" << (fast ? "True" : "False") << " timeout:" << timeout << " visualize:" << (visualize ? "True" : "False") << std::endl;
2345

2446
Environment sim {&cfg_parameters, workers, fast, timeout, visualize};
2547
auto main = new MainReactor("Main", &sim);

0 commit comments

Comments
 (0)