如何获得任务并行库使用的最大并行度

如何获得任务并行库使用的最大并行度

本文介绍了如何获得任务并行库使用的最大并行度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Parallel.invoke.如果我分配20个并行任务,那么只有8个可以同时运行.我的CPU是 http://ark.intel.com/products/47925 ,报告的数量是线程是8.我假设可以并行运行的任务数与cpu线程数有关.我不想创建比线程数更多的任务.我怎么知道C#中的线程数?我尝试查询ParallelOptions.MaxDegreeOfParallelism,我得到的只是-1.

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.

推荐答案

并行任务基本上是可以共享的线程.由于活动线程的数量受可用逻辑处理器内核数量的限制,因此很好的猜测是仅获取程序可用的逻辑内核数量.

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

这篇关于如何获得任务并行库使用的最大并行度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:14