User Guide
Table Of Contents
Before You Begin
After installing oneTBB, you need to set the environment variables:
1. Go to the oneTBB installation directory (<install_dir>). By default, <install_dir> is the following:
• On Linux* OS:
• For superusers (root): /opt/intel/oneapi
• For ordinary users (non-root): $HOME/intel/oneapi
• On Windows* OS:
• <Program Files>\Intel\oneAPI
2. Set the environment variables, using the script in <install_dir>, by running
• On Linux* OS:
vars.{sh|csh} in <install_dir>/tbb/latest/env
• On Windows* OS:
vars.bat in <install_dir>/tbb/latest/env
Example
Below you can find a typical example for a oneTBB algorithm. The sample calculates a sum of all integer
numbers from 1 to 100.
int sum = oneapi::tbb::parallel_reduce(oneapi::tbb::blocked_range<int>(1,101), 0,
[](oneapi::tbb::blocked_range<int> const& r, int init) -> int {
for (int v = r.begin(); v != r.end(); v++ ) {
init += v;
}
return init;
},
[](int lhs, int rhs) -> int {
return lhs + rhs;
}
);
oneAPI Threading Building Blocks (oneTBB) and pkg-config tool
The pkg-config tool is used to simplify the compilation line by retrieving information about packages from
special metadata files. It helps avoid large hard-coded paths and makes compilation more portable.
Compile a program using pkg-config
To compile a test program test.cpp with oneTBB on Linux* OS and macOS*, provide the full path to search
for include files and libraries, or provide a simple line like this:
g++ -o test test.cpp $(pkg-config --libs --cflags tbb)
Where:
--cflags provides oneTBB library include path:
$ pkg-config --cflags tbb``
-I<path-to>/tbb/latest/lib/pkgconfig/../..//include
--libs provides the Intel(R) oneTBB library name and the search path to find it:
$ pkg-config –libs tbb
-L<path to>tbb/latest/lib/pkgconfig/../..//lib/intel64/gcc4.8 -ltbb
1 Get Started with Intel
®
oneAPI Threading Building Blocks (oneTBB)
4