Intel® oneAPI Threading Building Blocks Developer Guide and API Reference
Feature-test Macros
Description
oneTBB defines a set of preprocessor macros corresponding to the features provided by the library. They are intended for detecting the presence of these features.
Each of these macros is defined in the header <oneapi/tbb/version.h> and in the feature headers specified in the table below.
For preview features, the feature test macro is only defined if the feature is enabled by defining its preview macro. You cannot use a feature test macro to guard setting of the feature preview macro. For example:
// Wrong
#include <oneapi/tbb/version.h>
#if TBB_HAS_FEATURE_X
#define TBB_PREVIEW_FEATURE_X 1 // Never reached
#include <oneapi/tbb/feature_header.h>
#endif
// Correct
#define TBB_PREVIEW_FEATURE_X 1
#include <oneapi/tbb/version.h>
#if TBB_HAS_FEATURE_X
#include <oneapi/tbb/feature_header.h>
#endif
Each macro value follows the pattern YYYYMM, where YYYY is a year, and MM is a month when the corresponding feature was introduced or updated. These values can be increased if the capabilities of given features are extended. The table below contains only the most recent values.
Feature |
Macro Name |
Value |
Header(s) |
|---|---|---|---|
TBB_HAS_FLOW_GRAPH_RESOURCE_LIMITING |
202603 |
<oneapi/tbb/flow_graph.h> |
|
TBB_HAS_PARALLEL_PHASE |
202603 |
<oneapi/tbb/task_arena.h> |
|
TBB_HAS_TASK_ARENA_CORE_TYPE_SELECTOR |
202603 |
<oneapi/tbb/task_arena.h> |
|
TBB_HAS_TASK_GROUP_DEPENDENCIES |
202603 |
<oneapi/tbb/task_group.h> |
|
TBB_HAS_TASK_GROUP_WAIT_FOR_SINGLE_TASK |
202603 |
<oneapi/tbb/task_group.h> |
Example
The following example uses a feature-test macro to conditionally enable parallel_phase hints when supported by the library:
#define TBB_PREVIEW_PARALLEL_PHASE 1
#include <oneapi/tbb/version.h>
#include <oneapi/tbb/parallel_for.h>
#if TBB_HAS_PARALLEL_PHASE
#include <oneapi/tbb/task_arena.h>
#endif
int main() {
#if TBB_HAS_PARALLEL_PHASE
tbb::this_task_arena::start_parallel_phase();
#endif
tbb::parallel_for(parallel_loop1_begin, parallel_loop1_end,
parallel_loop1_body{});
tbb::parallel_for(parallel_loop2_begin, parallel_loop2_end,
parallel_loop2_body{});
#if TBB_HAS_PARALLEL_PHASE
tbb::this_task_arena::end_parallel_phase(/*with_fast_leave=*/true);
#endif
}