# tbb::serial::parallel_for()

## Header

#define TBB_PREVIEW_SERIAL_SUBSET 1

#include "tbb/ parallel_for.h"

## Motivation

Sometimes it is useful, for example while debugging, to execute certain `parallel_for()` invocations serially while having other invocations of `parallel_for()`executed in parallel.

## Description

The `tbb::serial::parallel_for` function implements the `tbb::parallel_for` API using a serial implementation underneath. Users who want sequential execution of a certain `parallel_for()` invocation will need to define the `TBB_PREVIEW_SERIAL_SUBSET` macro before parallel_for.h and prefix the selected `parallel_for()` with `tbb::serial::`. Internally, the serial implementation uses the same principle of recursive decomposition, but instead of spawning tasks, it does recursion "for real", i.e. the body function calls itself twice with two halves of its original range.

## Example

    #define TBB_PREVIEW_SERIAL_SUBSET 1
    #include <tbb/parallel_for.h>
    #include <tbb/parallel_for.h>
    #include <tbb/parallel_for.h>
    Foo()
    {
      // . . .
      tbb::serial::parallel_for( . . . );
      tbb::parallel_for( . . . );
      // . . .
    }

Parent topic: Serial subset