parallel_do: A New Threading Building Blocks Component

The latest Threading Building Blocks development release (tbb20_20071030oss) includes an important new feature: the parallel_do component. You can read some of the discussion that led to the development of parallel_do in the

"Making parallel_while Better?" thread in the TBB Forum. This discussion is continued in the "parallel_do: the replacement to parallel_while" thread.

Why parallel_do?

Among the points discussed in the "Making parallel_while Better?" thread is that the implementation of parallel_while() is inconsistent with the the implementation of parallel_for() and parallel_reduce(). A look at the syntax of these three functions (and also parallel_scan() illustrates this:



template<typename Range, typename Body>
void parallel_for ( const Range& range, const Body& body );


template<typename Range, typename Body>
void parallel_reduce ( const Range& range, const Body& body );


template<typename Body>
class parallel_while;


template<typename Range, typename Body>
void parallel_scan ( const Range& range, const Body& body );


We can see that the other three parallel's are implemented as functions, while parallel_while is a class.

Read the "Making parallel_while Better?" thread if you're interested in the thought process and discussion that led from the possibility of changing parallel_while to the development of an entirely new component, parallel_do.

parallel_do() syntax

The "parallel_do: the replacement to parallel_while" thread documents the syntax of the new parallel_do() component:



template<typename InputIterator, typename Body>
void parallel_do( InputIterator first, InputIterator last, Body body );


Thus, parallel_do() is implemented as a function, like parallel_for(), parallel_reduce(), and parallel_scan().

Getting parallel_do() today

parallel_do() is included in the October 30 TBB Development release. This release contains two "stray" references to a non-existent affinity.h file (see bug 108). You need to comment out the #include "affinity.h" lines in files src/tbb/task.cpp and include/tbb/parallel_for.h. Once these lines are commented out, the release should build fine.

I'll be trying out parallel_do() myself soon. When I do that, I'll post another blog and include my example application that applies parallel_do().

Try it, and join the discussion

parallel_do is a new component, and its availability is restricted at this time to a development release. This means that discussion of the component remains open. Developers who are interested in the future of parallel_do() are encouraged to try it out, and post any comments you may have to the "parallel_do: the replacement to parallel_while" thread. The new component is also being discussed on the TBB mailing lists.

Kevin Farnham

O'Reilly Media

TBB Open Source Community

For more complete information about compiler optimizations, see our Optimization Notice.