Skip to content

Commit

Permalink
exposed workload factor as a command-line option
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Läufer <[email protected]>
  • Loading branch information
klaeufer committed Oct 6, 2023
1 parent cacac6f commit fae90b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 1 addition & 5 deletions integration/f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

// {{UnoAPI:f-implementation:begin}}
double f(const double x) {
auto result = 1.0;
for (auto n = 0; n < 1000; n++) {
result *= cos(x) * cos(x) + sin(x) * sin(x);
}
return result;
return cos(x) * cos(x) + sin(x) * sin(x);
}
// {{UnoAPI:f-implementation:end}}
20 changes: 17 additions & 3 deletions integration/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int main(const int argc, const char * const argv[]) {
bool run_cpuonly{false};
uint x_precision{1};
uint y_precision{1};
uint workload_factor{1};
std::string perf_output;
ts_vector timestamps;
std::string device_name;
Expand All @@ -45,6 +46,7 @@ int main(const int argc, const char * const argv[]) {
app.add_flag("-v,--show-function-values", show_function_values);
app.add_flag("-s,--sequential", run_sequentially);
app.add_flag("-c,--cpu-only", run_cpuonly);
app.add_option("-w,--workload-factor", workload_factor, "unit workload multiplier factor")->check(CLI::PositiveNumber.description(" >= 1"));
app.add_option("-x,--x-format-precision", x_precision, "decimal precision for x values")->check(CLI::PositiveNumber.description(" >= 1"));
app.add_option("-y,--y-format-precision", y_precision, "decimal precision for y (function) values")->check(CLI::PositiveNumber.description(" >= 1"));
app.add_option("-p,--perfdata-output-file", perf_output, "output file for performance data");
Expand Down Expand Up @@ -76,9 +78,17 @@ int main(const int argc, const char * const argv[]) {
spdlog::info("starting sequential integration");

// populate vector with function values and add trapezoid area to result
values[0] = f(x_min);
values[0] = 0;
for (auto k = 0; k < workload_factor; k++) {
values[0] += f(x_min);
}
values[0] /= workload_factor;
for (auto i{0UL}; i < number_of_trapezoids; i++) {
values[i + 1] = f(x_min + i * dx);
values[i + 1] = 0;
for (auto k = 0; k < workload_factor; k++) {
values[i + 1] += f(x_min + i * dx);
}
values[i + 1] /= workload_factor;
result += trapezoid(values[i], values[i + 1], half_dx);
}

Expand Down Expand Up @@ -122,7 +132,11 @@ int main(const int argc, const char * const argv[]) {
q.submit([&](auto & h) {
const sycl::accessor v{v_buf, h};
h.parallel_for(size, [=](const auto & index) {
v[index] = f(x_min + index * dx);
v[index] = 0;
for (auto k = 0; k < workload_factor; k++) {
v[index] += f(x_min + index * dx);
}
v[index] /= workload_factor;
});
}); // end of command group
// {{UnoAPI:main-parallel-submit-parallel-for:end}}
Expand Down

0 comments on commit fae90b0

Please sign in to comment.