Function template that evaluates several functions in parallel.

// Defined in header <oneapi/tbb/parallel_invoke.h>

namespace oneapi {
    namespace tbb {

        template<typename... Functions>
        void parallel_invoke(Functions&&... fs);

    } // namespace tbb
} // namespace oneapi


  • All members of Functions parameter pack must meet Function Objects requirements described in the [function.objects] section of the ISO C++ standard.

  • Last member of Functions parameter pack may be a task_group_context& type.

Evaluates each member passed to parallel_invoke possibly in parallel. Return values are ignored.

The algorithm can accept a task_group_context object so that the algorithm’s tasks are executed in this context. By default, the algorithm is executed in a bound context of its own.


The following example evaluates f(), g(), h(), and bar(1) in parallel.

#include "oneapi/tbb/parallel_invoke.h"

extern void f();
extern void bar(int);

class MyFunctor {
    int arg;
    MyFunctor(int a) : arg(a) {}
    void operator()() const { bar(arg); }

void RunFunctionsInParallel() {
    MyFunctor g(2);
    MyFunctor h(3);

    oneapi::tbb::parallel_invoke(f, g, h, []{bar(1);});