Skip to content

Commit

Permalink
Add scoped_parallel_phase code snippet
Browse files Browse the repository at this point in the history
Signed-off-by: Isaev, Ilya <[email protected]>
  • Loading branch information
isaevil committed Dec 3, 2024
1 parent 9600626 commit c448e63
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion rfcs/proposed/parallel_block_for_task_arena/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Following code snippets show how the new API can be used.
```cpp
void task_arena_leave_policy_example() {
tbb::task_arena ta(tbb::task_arena::automatic, 1, priority::normal, leave_policy::fast);
tbb::task_arena ta{tbb::task_arena::automatic, 1, priority::normal, leave_policy::fast};
ta.execute([]() {
// Parallel computation
});
Expand Down Expand Up @@ -210,6 +210,27 @@ void parallel_phase_example() {
// Computation
}
}
void scoped_parallel_phase_example() {
tbb::task_arena ta{/*arena constraints*/};
{
tbb::task_arena::scoped_parallel_phase phase{ta, /*with_fast_leave=*/true};
ta.execute([]() {
// Parallel computation
});
// Serial computation
ta.execute([]() {
// Parallel computation
});
} // End of the parallel phase
#pragma omp parallel for
for (int i = 0; i < work_size; ++i) {
// Computation
}
}
```

## Considerations
Expand Down

0 comments on commit c448e63

Please sign in to comment.