How to get maximum degree of parallelism for task

2020-03-24 04:39发布

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条回答
神经病院院长
2楼-- · 2020-03-24 05:26

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
查看更多
登录 后发表回答