MCPcopy Create free account
hub / github.com/DmitriBogdanov/UTL / main

Function main

examples/module_parallel/parallel_for_loop.cpp:7–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5double f(double x) { return std::exp(std::sin(x)); }
6
7int 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}

Callers

nothing calls this directly

Calls 3

fFunction · 0.85
set_thread_countFunction · 0.50
blocking_loopFunction · 0.50

Tested by

no test coverage detected