使用 MPI 广播对象

发布于 2024-12-16 18:01:40 字数 41 浏览 3 评论 0原文

有没有办法广播一个对象,或者我是否必须以其他方式广播它包含的所有值?

Is there a way to broadcast an object or will I have to bcast all of the values it contains some other way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伏妖词 2024-12-23 18:01:40

我将假设 C++ 语言是唯一具有对象并在标准中定义 MPI 接口的语言。如果我错了,就说吧。对于其他语言基本原理是这样的。

基本上,如果您可以对对象执行 memcpy 或将其存储到文件中(write)并从文件中读取它(read),则可以对对象执行 MPI_Bcast内存,存储对象的地方。

为了能够做到这一点,您的对象应该

  • 仅由 POD 类型(普通旧数据:char、int、float、double)组成,或者具有相同属性的其他对象
  • 内部没有指针,因为在发送到另一个 MPI 进程后,内存将与发送过程中的内存不同。

如果您的对象更复杂,则应在发送之前将其序列化(编组)到某个缓冲区,并在接收后对其进行反序列化(解组)。您可以使用 增强序列化 - 但即使这样变体不是通用的(对象如何组织为可序列化存在限制)

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

  • be composed with Only POD types (plain old data: char, int, float, double) or other objects with the same property
  • have no pointers inside it, because after sending to another MPI process, memory will be not the same as in sending process.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文