Skip to content

Commit

Permalink
Add code samples
Browse files Browse the repository at this point in the history
Signed-off-by: Isaev, Ilya <[email protected]>
  • Loading branch information
isaevil committed Dec 2, 2024
1 parent 5989d23 commit e5abf20
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions rfcs/proposed/parallel_block_for_task_arena/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,48 @@ the last public reference is removed from the arena (i.e., task_arena is destroy
is joined for an implicit arena). This ensures correctness is
preserved (threads will not be retained forever).
### Examples
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);
ta.execute([]() {
// Parallel computation
});
// Different parallel runtime is used
// so it is preffered that worker threads won't be retained
// in the arena at this point.
#pragma omp parallel for
for (int i = 0; i < work_size; ++i) {
// Computation
}
}
void parallel_phase_example() {
tbb::this_task_arena::start_parallel_phase();
tbb::parallel_for(0, work_size, [] (int idx) {
// User defined body
});
// Some serial computation
tbb::parallel_for(0, work_size, [] (int idx) {
// User defined body
});
tbb::this_task_arena::end_parallel_phase(/*with_fast_leave=*/true);
// Different parallel runtime (for example, OpenMP) is used
// so it is preffered that worker threads won't be retained
// in the arena at this point.
#pragma omp parallel for
for (int i = 0; i < work_size; ++i) {
// Computation
}
}
```

## Considerations

The alternative approaches were also considered.<br>
Expand Down

0 comments on commit e5abf20

Please sign in to comment.