Force onetbb to not parallelize

Viewed 37

I am writing some tests for an appliation I am developing. This application uses TBB and OpenMP for some loops which do some floating point operations.

However, for the tests I want this loops to run sequentially, to be able to compare if two executions give the same result.

I know with OpenMP you can do set_omp_num_threads(1), but I have no idea how to disable parallelism in TBB. How is this done?

1 Answers

You can use

tbb::global_control global_limit(tbb::global_control::max_allowed_parallelism, 1);

as described here and here. Note that you need to keep the global_limit variable in scope as long as you want to enforce a single thread.

Related