Reputation: 846
I'm running a tbb code on linux and I want to run my code using a portion of my CPU (2 out of 8). Is there another way except disabling cores.
Upvotes: 0
Views: 687
Reputation: 6577
TBB respects the process affinity mask (on Linux: affinity mask of the [main] thread where TBB was initialized for the first time). So that by default, it will create worker threads in the quantity that takes into account the number of bits set to 1 in the affinity mask. For example, use taskset
or numactl
for setting the affinity mask. E.g.:
numactl --physcpubind=1,2 path/application arg1 arg2
It is like disabling the cores but for a specific process only.
You can also control the number of threads in the code using old tbb::task_scheduler_init
or new tbb::global_control
API. But it will not assign affinity mask to TBB threads, it just changes the number of threads.
If you want to manually assign affinity mask to the worker threads that TBB creates, derive you own class from tbb::task_scheduler_observer
in order to define your custom actions for worker threads creation as described in this blog.
Upvotes: 1
Reputation: 799230
taskset(1)
allows you to run a command on a specific subset of cores on the system.
taskset -c 0,1 ./a.out
Upvotes: 1