TBB with fixed number of threads for one task, and default for others

喜欢而已 提交于 2019-12-05 09:16:57

Yes, there are few natural ways to limit concurrency of a certain algorithm while keep the rest as is.

  1. Create separate thread and initialize it for the limited concurrency using tbb::task_scheduler_init as you described. Since the master threads are isolated, it will not affect main and other threads. So, you can start the parallel_for from inside of that special limited thread.
  2. Use tbb::parallel_pipeline instead of parallel_for and specify the number of tokens = j in order to limit the number of concurrently processing tasks.
  3. Use tbb::task_arena (was a preview feature till TBB 4.3) to do the same as described in (1) but without additional master thread since the work can be put into isolated concurrency context (arena) using just its API

Example of (3):

tbb::task_arena limited_arena(j);
limited_arena.execute([]{ tbb::parallel_for(...); });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!