c# – 嵌套Parallel.For()循环速度和性能

我有一个嵌套for循环.
我已经用Parallel.For()替换了第一个For,并且计算速度增加了.

我的问题是用Parallel.For()替换第二个(里面一个).会增加速度吗?还是没有区别?还是会慢一些?

编辑:

由于内核不是无限制的(通常有2到8个内核),内部循环并行运行.所以,如果我用一个Parallel.For()来改变里面的内容,它又会并行运行.但我不知道它如何改变性能和速度.

最佳答案
“Patterns of parallel programming”年的“Patterns of parallel programming”年的“反模式”部分,从“细粒度,粗粒度”小节,

The answer is that the best balance is found through performance
testing. If the overheads of parallelization are minimal as compared
to the work being done, parallelize as much as possible: in this case,
that would mean parallelizing both loops. If the overheads of
parallelizing the inner loop would degrade performance on most
systems, think twice before doing so, as it’ll likely be best only to
parallelize the outer loop.

看一下这个小节,它是独立于并行光线跟踪应用程序的详细示例.并且它的建议,平坦化的循环,以更好的并行度可能也对你有帮助.

转载注明原文:c# – 嵌套Parallel.For()循环速度和性能 - 代码日志