How to get maximum degree of parallelism for task parallel library usage?

痞子三分冷 提交于 2019-12-30 09:44:11

问题


I want to use Parallel.invoke. If i assign 20 parallel task, only 8 of then are run concurrently. My CPU is http://ark.intel.com/products/47925 and the reported number of threads is 8. I assume number of task can be run in parallel is related to the cpu number of threads. I dont want to create more task than the number of threads. How do i know the number of threads in c#? I tried query ParallelOptions.MaxDegreeOfParallelism and all i get is -1.


回答1:


Parallel tasks are basically threads that can be shared. Because the number of active threads is limited by the number of logical processor cores that are available, a good guess would be to just take the number of logical cores available to the program.

Environment.ProcessorCount


来源:https://stackoverflow.com/questions/21520013/how-to-get-maximum-degree-of-parallelism-for-task-parallel-library-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!