| 5 | double f(double x) { return std::exp(std::sin(x)); } |
| 6 | |
| 7 | int main() { |
| 8 | using namespace utl; |
| 9 | |
| 10 | std::vector<double> vals(200'000, 0.5); |
| 11 | |
| 12 | // (optional) Select the number of threads |
| 13 | parallel::set_thread_count(8); |
| 14 | |
| 15 | // Apply f() to all elements of the vector |
| 16 | parallel::blocking_loop(vals, [&](auto it) { *it = f(*it); }); |
| 17 | |
| 18 | // Apply f() to indices [0, 100) |
| 19 | parallel::blocking_loop(parallel::IndexRange{0, 100}, [&](int i) { vals[i] = f(vals[i]); }); |
| 20 | |
| 21 | // Specify computation in blocks instead of element-wise |
| 22 | parallel::blocking_loop(parallel::IndexRange{0, 100}, [&](int low, int high) { |
| 23 | for (int i = low; i < high; ++i) vals[i] = f(vals[i]); |
| 24 | }); |
| 25 | } |
nothing calls this directly
no test coverage detected