Replace Annotations with
Intel® oneAPI Threading Building Blocks (oneTBB)
Code
Intel® oneAPI Threading Building Blocks (oneTBB)
CodeThis topic explains the steps needed to implement parallelism proposed by the
Intel Advisor
annotations by adding
Intel® oneAPI Threading Building Blocks
(oneTBB
) parallel framework code.
- AddoneTBBcode to add appropriate synchronization of shared resources, using the LOCK annotations as a guide. The following topics cover theoneTBBsynchronization options:
- Add code to createoneTBBtasks, using the SITE/TASK annotations as a guide. The following topics cover theoneTBBtask creation options:
This is the recommended order of tasks for replacing the annotations with
oneTBB
code:
- Add appropriate synchronization of shared resources, using LOCK annotations as a guide.
- Test to verify you did not break anything, before adding the possibility of non-deterministic behavior with parallel tasks.
- Add code to createoneTBBtasks or loops, using the SITE/TASK annotations as a guide.
- Test with one thread, to verify that your program still works correctly.
- Test with more than one thread to see that the multithreading works as expected.
The
oneTBB
parallel framework creates worker threads automatically. In general, you should concern yourself only with the tasks, and leave it to the framework to create and destroy the worker threads.
If you do need some control over creation and destruction of worker threads, read about
task_scheduler_init
in the
oneTBB
Reference manual.
The table below shows the serial, annotated program code in the left column and the equivalent
oneTBB
parallel code in the right column for some typical code to which parallelism can be applied.
Serial Code with
Intel Advisor Annotations | Parallel Code using
oneTBB
|
---|---|
|
|
|
|
|
|
For information about common parallel programming patterns and how to implement them in
oneTBB
, see the
oneTBB
help topic Design Patterns.