User Guide

Contents

Parallelize Data -
Intel® Threading Building Blocks (Intel® TBB)
Counted Loops

When tasks are loop iterations, and the iterations are over a range of values that are known before the loop starts, the loop is easily expressed in
Intel® Threading Building Blocks (Intel® TBB)
.
Consider the following serial code and the need to add parallelism to this loop:
    ANNOTATE_SITE_BEGIN(sitename);         for (int i = lo; i < hi; ++i) {             ANNOTATE__ITERATION_TASK(taskname);                 statement;         }     ANNOTATE_SITE_END();
Here is the serial example converted to use
Intel® Threading Building Blocks (Intel® TBB)
, after you remove the
Intel Advisor
annotations:
#include <tbb/tbb.h> ... tbb::parallel_for( lo, hi, [&](int i) {statement;} );
The first two parameters are the loop bounds. As is typical in C++ (especially STL) programming, the lower bound is inclusive and the upper bound is exclusive. The third parameter is the loop body, wrapped in a lambda expression. The loop body will be called in parallel by threads created by
Intel TBB
. As described before in Create the Tasks, Using C++ structs Instead of Lambda Expressions, the lambda expressions can be replaced with instances of explicitly defined class objects.

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 reserved 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