Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deterministic processing mode to examples #830

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/options/include/traccc/options/throughput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class throughput : public interface {
/// them in the performance measurements
std::size_t cold_run_events = 10;

/// Enable or disable the randomization of event processing
bool deterministic_event_order = false;
/// Set the random event processing seed
unsigned int random_seed = 0;

/// Output log file
std::string log_file;

Expand Down
15 changes: 15 additions & 0 deletions examples/options/src/throughput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ throughput::throughput() : interface("Throughput Measurement Options") {
"cold-run-events",
po::value(&cold_run_events)->default_value(cold_run_events),
"Number of events to run 'cold'");
m_desc.add_options()("deterministic",
po::bool_switch(&deterministic_event_order)
->default_value(deterministic_event_order),
"Process events in deterministic order");
m_desc.add_options()("random-seed",
po::value(&random_seed)->default_value(random_seed),
"Seed for event randomization (0 to use time)");
m_desc.add_options()(
"log-file", po::value(&log_file),
"File where result logs will be printed (in append mode).");
Expand All @@ -46,6 +53,14 @@ std::unique_ptr<configuration_printable> throughput::as_printable() const {
"Processed events", std::to_string(processed_events)));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>("Log file", log_file));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Deterministic ordering",
deterministic_event_order ? "yes" : "no"));
dynamic_cast<configuration_category &>(*cat).add_child(
std::make_unique<configuration_kv_pair>(
"Random seed",
random_seed == 0 ? "time-based" : std::to_string(random_seed)));

return cat;
}
Expand Down
16 changes: 13 additions & 3 deletions examples/run/common/throughput_mt.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ int throughput_mt(std::string_view description, int argc, char* argv[],
tbb::task_group group;

// Seed the random number generator.
std::srand(static_cast<unsigned int>(std::time(0)));
if (throughput_opts.random_seed == 0u) {
std::srand(static_cast<unsigned int>(std::time(0)));
} else {
std::srand(throughput_opts.random_seed);
}

// Dummy count uses output of tp algorithm to ensure the compiler
// optimisations don't skip any step
Expand All @@ -215,7 +219,10 @@ int throughput_mt(std::string_view description, int argc, char* argv[],

// Choose which event to process.
const std::size_t event =
static_cast<std::size_t>(std::rand()) % input_opts.events;
(throughput_opts.deterministic_event_order
? i
: static_cast<std::size_t>(std::rand())) %
input_opts.events;

// Launch the processing of the event.
arena.execute([&, event]() {
Expand Down Expand Up @@ -253,7 +260,10 @@ int throughput_mt(std::string_view description, int argc, char* argv[],

// Choose which event to process.
const std::size_t event =
static_cast<std::size_t>(std::rand()) % input_opts.events;
(throughput_opts.deterministic_event_order
? i
: static_cast<std::size_t>(std::rand())) %
input_opts.events;

// Launch the processing of the event.
arena.execute([&, event]() {
Expand Down
16 changes: 13 additions & 3 deletions examples/run/common/throughput_st.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ int throughput_st(std::string_view description, int argc, char* argv[],
(detector_opts.use_detray_detector ? &detector : nullptr));

// Seed the random number generator.
std::srand(static_cast<unsigned int>(std::time(0)));
if (throughput_opts.random_seed == 0) {
std::srand(static_cast<unsigned int>(std::time(0)));
} else {
std::srand(throughput_opts.random_seed);
}

// Dummy count uses output of tp algorithm to ensure the compiler
// optimisations don't skip any step
Expand All @@ -154,7 +158,10 @@ int throughput_st(std::string_view description, int argc, char* argv[],

// Choose which event to process.
const std::size_t event =
static_cast<std::size_t>(std::rand()) % input_opts.events;
(throughput_opts.deterministic_event_order
? i
: static_cast<std::size_t>(std::rand())) %
input_opts.events;

// Process one event.
rec_track_params += (*alg)(input[event]).size();
Expand Down Expand Up @@ -182,7 +189,10 @@ int throughput_st(std::string_view description, int argc, char* argv[],

// Choose which event to process.
const std::size_t event =
static_cast<std::size_t>(std::rand()) % input_opts.events;
(throughput_opts.deterministic_event_order
? i
: static_cast<std::size_t>(std::rand())) %
input_opts.events;

// Process one event.
rec_track_params += (*alg)(input[event]).size();
Expand Down
Loading