加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 18:09:33 所属栏目:百科 来源:网络整理
导读:我有一个嵌套for循环. 我已经用Parallel.For()替换了第一个For,并且计算速度增加了. 我的问题是用Parallel.For()替换第二个(里面一个).会增加速度吗?还是没有区别?还是会慢一些? 编辑: 由于内核不是无限制的(通常有2到8个内核),内部循环并行运行.所以,如
我有一个嵌套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.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读