Skip to Main Content
Intel Threading Building Blocks
book

Intel Threading Building Blocks

by James Reinders
July 2007
Intermediate to advanced content levelIntermediate to advanced
332 pages
10h 4m
English
O'Reilly Media, Inc.
Content preview from Intel Threading Building Blocks

Advanced Topic: Other Kinds of Iteration Spaces

The examples so far have used the class blocked_range<T> to specify ranges. This class is useful in many situations, but it does not fit every one. You can define your own iteration space objects to use with Intel Threading Building Blocks. The object must specify how it can be split into subspaces by providing two methods and a splitting constructor. You can see these simple definitions in the class blocked_range<T>.

If your class is called R, the methods and constructor could be as shown in Example 3-16.

Example 3-16. Define your own iteration space object

class R {
    // True if range is empty
    bool empty() const;
    // True if range can be split into nonempty subranges
    bool is_divisible() const;
    // Split r into subranges r and *this
    R( R& r, split );
    ... 
};

The method empty must return true if the range is empty. The method is_divisible needs to return true if the range can be split into two nonempty subspaces, and such a split is worth the overhead. The splitting constructor needs to take two arguments:

  • The first of type R

  • The second of type tbb::split

The second argument is not used; it serves only to distinguish the constructor from an ordinary copy constructor.

The splitting constructor should attempt to split r into two halves of roughly the same size, update r to be the first half, and let the constructed object be the second half. The two halves should be nonempty. The parallel algorithm templates call the splitting constructor on r only ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Rezaur Rahman

Publisher Resources

ISBN: 9780596514808Errata Page