使用蒙特卡洛和 MPI_Reduce 计算 pi
我正在开发一个项目,我们需要使用 MPI 并行化这个问题。所以基本的想法是每个进程都会得到自己份额的点,进行测试(这些点是否在圆圈内)然后调用MPI_Reduce。然后根将得到约简结果并给出最终答案。
我困惑的是要减少什么。每个进程是否应该计算 pi,用 pi 调用reduce,而根只取减少的 pi 值的平均值?或者每个进程调用是否应该减少命中数(圆内的成功点),然后根使用此结果计算 pi?希望这一点是清楚的。谢谢。
I am working on a project where we need to parallelize this problem using MPI. So the basic idea is each process will get its share of points, do the test (whether the points are in the circle) then call MPI_Reduce. The root then will get the reduced result and present the final answer.
What I am confused about is what to reduce. Should each process calculate pi, call reduce with the pi and the root just take the average of the reduced pi value ? or Should each process call reduce with the number of hits(successful points inside the circle) and then the root calculates the pi using this result? Hope this was clear. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我肯定会做后者:让每个进程返回命中数,并让 root 函数使用这些结果计算 pi。通过这种方式,您可以执行与串行计算相同的过程。
I would definitely do the latter: have each process return the number of hits and have the root function calculate pi using these results. In this manner, you doing the same process as you would if calculating this serially.