Intel® oneAPI Threading Building Blocks Developer Guide and API Reference
ID
772616
Date
3/31/2025
Public
A newer version of this document is available. Customers should click here to go to the newest version.
Package Contents
Parallelizing Simple Loops
Parallelizing Complex Loops
Parallelizing Data Flow and Dependence Graphs
Work Isolation
Exceptions and Cancellation
Containers
Mutual Exclusion
Timing
Memory Allocation
The Task Scheduler
Design Patterns
Migrating from Threading Building Blocks (TBB)
Constrained APIs
Appendix A Costs of Time Slicing
Appendix B Mixing With Other Threading Packages
References
parallel_for_each Body semantics and requirements
parallel_sort ranges interface extension
TBB_malloc_replacement_log Function
Parallel Reduction for rvalues
Type-specified message keys for join_node
Scalable Memory Pools
Helper Functions for Expressing Graphs
Description
API
Example
concurrent_lru_cache
task_group extensions
The customizing mutex type for concurrent_hash_map
Waiting for Single Messages in Flow Graph
parallel_phase Interface for Task Arena
Deduction Guides for blocked_nd_range
Helper Functions for Expressing Graphs
NOTE:
To enable this feature, define the TBB_PREVIEW_FLOW_GRAPH_FEATURES macro to 1.
Helper functions are intended to make creation of the flow graphs less verbose.
Description
This feature adds make_edges, make_node_set, follows and precedes functions to oneapi::tbb::flow namespace. These functions simplify the process of building flow graphs by allowing to gather nodes into sets and connect them to other nodes in the graph.
API
Example
Consider the graph depicted below.

In the examples below, C++17 Class Template Argument Deduction is used to avoid template parameter specification where possible.
Regular API
#include <oneapi/tbb/flow_graph.h>
int main() {
using namespace oneapi::tbb::flow;
graph g;
broadcast_node<int> input(g);
function_node doubler(g, unlimited, [](const int& v) { return 2 * v; });
function_node squarer(g, unlimited, [](const int& v) { return v * v; });
function_node cuber(g, unlimited, [](const int& v) { return v * v * v; });
join_node<std::tuple<int, int, int>> join(g);
int sum = 0;
function_node summer(g, serial, [&](const std::tuple<int, int, int>& v) {
int sub_sum = std::get<0>(v) + std::get<1>(v) + std::get<2>(v);
sum += sub_sum;
return sub_sum;
});
make_edge(input, doubler);
make_edge(input, squarer);
make_edge(input, cuber);
make_edge(doubler, std::get<0>(join.input_ports()));
make_edge(squarer, std::get<1>(join.input_ports()));
make_edge(cuber, std::get<2>(join.input_ports()));
make_edge(join, summer);
for (int i = 1; i <= 10; ++i) {
input.try_put(i);
}
g.wait_for_all();
}
Preview API
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
#include <oneapi/tbb/flow_graph.h>
int main() {
using namespace oneapi::tbb::flow;
graph g;
function_node doubler(g, unlimited, [](const int& v) { return 2 * v; });
function_node squarer(g, unlimited, [](const int& v) { return v * v; });
function_node cuber(g, unlimited, [](const int& v) { return v * v * v; });
auto handlers = make_node_set(doubler, squarer, cuber);
broadcast_node input(precedes(handlers));
join_node join(follows(handlers));
int sum = 0;
function_node summer(follows(join), serial,
[&](const std::tuple<int, int, int>& v) {
int sub_sum = std::get<0>(v) + std::get<1>(v) + std::get<2>(v);
sum += sub_sum;
return sub_sum;
});
for (int i = 1; i <= 10; ++i) {
input.try_put(i);
}
g.wait_for_all();
}