For applications that need to control CPU-specific settings for floating-point computations, there are two ways to propagate desired settings to tasks executed by Intel® Threading Building Blocks (Intel® TBB) task scheduler:
By default, worker threads use the floating-point settings captured during initialization of an application thread's implicit arena or explicit task_arena. These settings are applied to all parallel computations within the task_arena or started by the application thread, until that thread terminates its task scheduler instance. If the thread later re-initializes the task scheduler, new settings are captured.
For finer control over floating point behavior, a thread may capture the current settings in a task group context. It can be done at context creation if a special flag is passed to the constructor:
task_group_context ctx( task_group_context::isolated, task_group_context::default_traits | task_group_context::fp_settings );
or by a call to the method capture_fp_settings:
task_group_context ctx; ctx.capture_fp_settings();
The task group context can then be passed to most Intel TBB parallel algorithms (including flow::graph) to ensure that all tasks related to this algorithm use the specified floating-point settings. It is possible to execute parallel algorithms with different floating-point settings captured to separate contexts, even at the same time.
Floating-point settings captured to a task group context prevail over the settings captured during task scheduler initialization. Thus if a context is passed to a parallel algorithm then floating-point settings captured to the context are used. Otherwise, if floating-point settings are not captured to the context, or a context is not explicitly specified, then the settings captured during task scheduler initialization are used.
In a nested call to a parallel algorithm not using a task group context with explicitly captured floating-point settings, the settings from the outer level are used. If neither of the outer level contexts captured floating-point settings then the settings captured during task scheduler initialization are used.
It is guaranteed that: