Optimal number of threads per core

前端 未结 13 2002
忘掉有多难
忘掉有多难 2020-11-22 14:27

Let\'s say I have a 4-core CPU, and I want to run some process in the minimum amount of time. The process is ideally parallelizable, so I can run chunks of it on an infinite

13条回答
  •  無奈伤痛
    2020-11-22 15:22

    The actual performance will depend on how much voluntary yielding each thread will do. For example, if the threads do NO I/O at all and use no system services (i.e. they're 100% cpu-bound) then 1 thread per core is the optimal. If the threads do anything that requires waiting, then you'll have to experiment to determine the optimal number of threads. 4000 threads would incur significant scheduling overhead, so that's probably not optimal either.

提交回复
热议问题