Threading Building Blocks Book Code Samples
Threading Building Blocks APIs | Code Snippets, Examples, & Samples (click to see descriptions) |
Algorithm Snippets Algorithm Packaged Examples: Source Code Packages Algorithm Documentation Examples: Getting Started Guide
Tutorial
Reference Manual | parallel_for:
parallel_reduce:
parallel_scan:
parallel_while:
pipeline:
parallel_sort:
task:
|
Container Snippets Container Packaged Examples: Source Code Packages Container Documentation Examples: Tutorial
Reference Manual
| concurrent_hash_map:
concurrent_vector:
concurrent_queue:
|
Other Snippets Other Packaged Examples: Source Code Packages Other Documentation Examples: Tutorial
Reference Manual | Memory Allocator:
Task Scheduler:
Various:
|
Threading Building Blocks APIs
Algorithms:
parallel_for:
- Online: Conway's Game of Life (Automata): This application is a mix of native C++ and C++/CLI. Native C++ based computation intensive part of the game uses TBB parallel_for.
- Online: Multitude of Threading: This C++ sample application computes prime numbers. It demonstrates different means of threading with OpenMP*, Windows Threads and Threading Building Blocks.
- Source Code Package: sub_string_finder: A simple example that uses the parallel_for template in a substring matching program. For each position in a string, the program displays the length of the largest matching substring elsewhere in the string. The program also displays the location of a largest match for each position. Consider the string "babba" as an example. Starting at position 0, "ba" is the largest substring with a match elsewhere in the string (position 3).
- Source Code Package: seismic: Parallel seismic simulation that demonstrates use of parallel_for and affinity_partitioner.
- Source Code Package: tacheon: Parallel raytracer / renderer that demonstrates the use of parallel_for. This example is a 2-D raytracer/renderer that visually shows different parallel scheduling methods and their resulting speedup. The code was parallelized by speculating that each pixel could be rendered in parallel. The resulting parallel code was then checked for correctness by using Intel® Thread Checker, which pointed out where synchronization was needed. Minimal synchronization was then inserted into the parallel code. The resulting parallel code exhibits good speedup. This example includes software developed by John E. Stone. See here for copyright information.
- Getting Started Guide: Using parallel_for: Describes the sub_string_finder example available in the source code packages.
- Tutorial: parallel_for: Describes the basics of the parallel_for algorithm including discussions on grainsize, bandwidth, and the partitioner preview feature.
- Reference Manual: parallel_for Template Function: Contains a more in depth example than the tutorial along with standard reference material including syntax, header, and body requirements.
parallel_reduce:
- Online: ---
- Source Code Package: convex_hull: Parallel version of convex hull algorithm (quick hull).
- Source Code Package: primes: Parallel version of the Sieve of Eratosthenes.
- Tutorial: parallel_reduce: Describes the basics of the parallel_reduce algorithm including both a simple and advanced example and a discussion on different types of iteration spaces.
- Reference Manual: parallel_reduce Template Function: Contains a simple example along with standard reference material including syntax, header, and body requirements.
parallel_scan:
- Online: ---
- Source Code Package: --
- Tutorial: ---
- Reference Manual: parallel_scan Template Function: Contains a simple example along with standard reference material including syntax, header, and body requirements.
parallel_while:
- Online: ---
- Source Code Package: parallel_preorder: Example that uses parallel_while to do parallel preorder traversal of a sparse graph. Each vertex in the graph is called a "cell". Each cell has a value. The value is a matrix. Some of the cells have operators that compute the cell's value, using other cell's values as input. A cell that uses the value of cell x is called a successor of x.
- Tutorial: parallel_while: Describes the basics of the parallel_while algorithm including a simple example.
- Reference Manual: parallel_while Template Class: Contains a simple example along with standard reference material including syntax, header, and body requirements.
pipeline:
- Online: PackRat: This C++ application uses Threading Building Blocks pipeline to create a multi-threaded file compression utility.
- Source Code Package: text_filter: Text filter that demonstrates class pipeline. The Tutorial explains this example in detail.
- Tutorial: pipeline: Describes the basics of the pipeline algorithm including a simple example and discussions of pipeline throughput and non-linear pipelines.
- Reference Manual: pipeline Template Class: Contains a simple example along with a decsription of the filter class and standard reference material including syntax, header, and body requirements.
parallel_sort:
- Online: ---
- Source Code Package: ---
- Tutorial: ---
- Reference Manual: parallel_sort Template Class: Contains a simple example along with standard reference material including syntax, header, and body requirements.
task:
- Online: ---
- Source Code Package: tree_sum: This directory contains a simple example that sums values in a tree. The example exhibits some speedup, but not a lot, because it quickly saturates the system bus on a multiprocessor. For good speedup, there needs to be more computation cycles per memory reference. The point of the example is to teach how to use the raw task interface, so the computation is deliberately trivial. The performance of this example is better when objects are allocated by the Threading Building Blocks scalable_allocator instead of the default "operator new". The reason is that the scalable_allocator typically packs small objects more tightly than the default "operator new", resulting in a smaller memory footprint, and thus more efficient use of cache and virtual memory. In addition, the scalable_allocator performs better for multi-threaded allocations.
- Tutorial: ---
- Reference Manual: task Template Class: Contains a simple example along with standard reference material including syntax, header, and body requirements.
Containers:
concurrent_hash_map:
- Online: ---
- Source Code Package: count_strings: Example program that demonstrates template class concurrent_hash_map.
- Tutorial: concurrent_hash_map: Describes the basics of the concurrent_hash_map container including a simple example and a discussion on HashCompare.
- Reference Manual: concurrent_hash_map Template Class: Contains a simple example along with standard reference material including syntax, header, and body requirements. Also includes detailed descriptions of whole table operations, concurrent access and concurrent operations, parallel iteration, capacity, and iterators.
concurrent_vector:
- Online: ---
- Source Code Package: convex_hull: Parallel version of convex hull algorithm (quick hull).
- Tutorial: concurrent_vector: Describes the basics of the concurrent_vector container including a simple example and a discussion on concurrency safety.
- Reference Manual: concurrent_vector Template Class: Contains a simple example along with standard reference material including syntax, header, and body requirements. Also includes detailed descriptions of whole vector operations, concurrent operations, parallel iteration, capacity, and iterators.
concurrent_queue:
- Online: ---
- Source Code Package: ---
- Tutorial: concurrent_queue: Describes the basics of the concurrent_queue container including a simple example and a discussions on when not to use a queue.
- Reference Manual: concurrent_queue Template Class: Contains a simple example along with standard reference material including syntax, header, and body requirements and a brief discussion on iterators.
Other:
Memory Allocator:
- Online: ---
- Source Code Package: ---
- Tutorial: Memory Allocation: Describes the basics of the memory allocator including discussions on scalability, false sharing, and which dynamic libraries to use.
- Reference Manual: Memory Allocation: Contains the allocator concept description along with standard reference material including syntax, header, and body requirements.
Task Scheduler:
- Online: Destroy the Castle: To reach the next level of scalability in game architecture we built a template which allows game developers to understand and measure threading efficiency. We applied the template to the demo game, Destroy the Castle, using Threading Building Blocks task scheduler interface to demonstrate how any game developer can take advantage of multi-core processors with the help of TBB.
- Source Code Package: ---
- Tutorial: The Task Scheduler: Describes the basics of the task scheduler including an explanation of the fibonacci example in the source code packages, how the task scheduling works, and several useful task techniques.
- Reference Manual: Task Scheduling: Contains a description of the task scheduling algorithm along with standard reference material including syntax, header, and body requirements. Also includes several references for the task Template Class and related functions.
Various:
- Online: TBB Book Examples: The O'Reilly book, Intel® Threading Building Blocks: Outfitting C++ for Multi-core Processor Parallelism by James Reinders consists of a rich collection of examples ranging from simple to moderately complex and from obvious uses to more esoteric uses to meet specific needs.
- Web: Community Code Examples: Winning code entries from the recent Coding with TBB contest.
- Source Code Package: fibonacci: This directory contains an example that computes Fibonacci numbers in several different ways. The purpose of the example is to exercise every include file and class in Threading Building Blocks. Most of the computations are deliberately silly and not expected to show any speedup on multiprocessors.
- Tutorial: ---
- Reference Manual: ---
The original source for this example is
Copyright (c) 1994, 1995, 1996, 1997 John E. Stone All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by John E. Stone
- The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


