User Guide

Contents

Annotations and
Intel® Threading Building Blocks (Intel® TBB)
Code

This topic explains the steps needed to implement parallelism proposed by the
Intel Advisor
annotations by adding
Intel® Threading Building Blocks (Intel® TBB)
parallel framework code.
This is the recommended order of tasks for replacing the annotations with
Intel TBB
code:
  1. Add appropriate synchronization of shared resources, using LOCK annotations as a guide.
  2. Test to verify you did not break anything, before adding the possibility of non-deterministic behavior with parallel tasks.
  3. Add code to create
    Intel TBB
    tasks or loops, using the SITE/TASK annotations as a guide.
  4. Test with one thread, to verify that your program still works correctly.
  5. Test with more than one thread to see that the multithreading works as expected.
The
Intel TBB
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
Intel TBB
Reference manual.
The table below shows the serial, annotated program code in the left column and the equivalent
Intel TBB
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
Intel TBB
// Locking ANNOTATE_LOCK_ACQUIRE(); Body(); ANNOTATE_LOCK_RELEASE():
// Locking can use various mutex types provided // by Intel TBB. For example: #include <tbb/tbb.h> ... tbb::mutex g_Mutex; ... { tbb::mutex::scoped_lock lock(g_Mutex); Body(); }
// Do-All Counted loops, one task ANNOTATE_SITE_BEGIN(site); For (I = 0; I < N; ++) { ANNOTATE_ITERATION_TASK(task); {statement;} } ANNOTATE_SITE_END();
// Do-All Counted loops, using lambda // expressions #include <tbb/tbb.h> ... tbb::parallel_for(0,N,[&](int I) { statement; });
// Create Multiple Tasks ANNOTATE_SITE_BEGIN(site); ANNOTATE_TASK_BEGIN(task1); statement-or-task1; ANNOTATE_TASK_END(); ANNOTATE_TASK_BEGIN(task2); statement-or-task2; ANNOTATE_TASK_END(); ANNOTATE_SITE_END();
// Create Multiple tasks, using lambda // expressions #include <tbb/tbb.h> ... tbb::parallel_invoke( [&]{statement-or-task1;}, [&]{statement-or-task2;} );
For information about common parallel programming patterns and how to implement them in
Intel TBB
, see the
Intel TBB
help topic Design Patterns.

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserverd for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804