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) |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
<oneapi/tbb/task_arena.h><oneapi/tbb/info.h> |
|
|
|
<oneapi/tbb/task_group.h><oneapi/tbb/task_arena.h> |
|
|
|
<oneapi/tbb/task_group.h><oneapi/tbb/task_arena.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
}