使用 MPI 广播对象
有没有办法广播一个对象,或者我是否必须以其他方式广播它包含的所有值?
Is there a way to broadcast an object or will I have to bcast all of the values it contains some other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将假设 C++ 语言是唯一具有对象并在标准中定义 MPI 接口的语言。如果我错了,就说吧。对于其他语言基本原理是这样的。
基本上,如果您可以对对象执行 memcpy 或将其存储到文件中(
write
)并从文件中读取它(read
),则可以对对象执行 MPI_Bcast内存,存储对象的地方。为了能够做到这一点,您的对象应该
如果您的对象更复杂,则应在发送之前将其序列化(编组)到某个缓冲区,并在接收后对其进行反序列化(解组)。您可以使用 增强序列化 - 但即使这样变体不是通用的(对象如何组织为可序列化存在限制)
PS boost 序列化集成到
Boost.MPI
I'll assume C++ language as only language having objects and defined MPI interface in standard. If I wrong, just say. For other languages basic principle is like this.
Basically, if you can do a memcpy of the object or store it into file (
write
) and read it from the file (read
), you can do an MPI_Bcast of the memory, in which object is stored.To be able of doing this, your object should
If your object is more complex, it should be serialized (marshalled) to some buffer before sending and deserialized (unmarshalled) after receive. You can use boost serialization - but even this variant is not universal (there are limits on how object can be organized to be serializable)
PS boost serialization is integrated into
Boost.MPI