自动并行化友好的编程实践
来自本文 :避免不必要的序列化算法:随机等算法 必须将种子传递给下一个生成器调用序列化的数字生成器 如果生成器的次数过多,则该算法就不必要了 无法准确预测线程内的调用。这些算法 应该替换为更多的分布式版本。
问:谁能解释一下“如果无法准确预测线程内调用生成器的次数,则不必要序列化算法。” 至于随机数 我们要传承一代人的种子。那么如何避免序列化。
From this paper: Avoid unnecessarily serializing algorithms: Algorithms such as random
number generators that must pass a seed to the next generator call serialize
the algorithm unnecessarily if the number of times the generator will be
called within a thread cannot be accurately predicted. These algorithms
should be replaced with more distributed versions, instead.
Q: Can anyone please explain "serialize the algorithm unnecessarily if the number of times the generator will be called within a thread cannot be accurately predicted." As for random number
generation we have to pass a seed. Thus how can serialization be avoided.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有一个依赖于其先前值(大部分)的 RNG,并且您这样编写它:
即使是智能编译器也无法自动并行化。然而,如果你这样写:
一个非常聪明的编译器可以让程序在usersInput-number-of-threads中运行,每个只需要运行100次迭代,而不是usersInput*100。
If you have a RNG that depends on its previous value (most) and you write it like this:
It cannot be automatically parallelized even by a smart compiler. However, if you write it like this:
A very smart compiler can make the program run in usersInput-number-of-threads, each will only have to run 100 iterations instead of usersInput*100.