gpt4 book ai didi

c++ - 使用 MPI 集体通信发送结构

转载 作者:行者123 更新时间:2023-11-30 17:07:49 33 4
gpt4 key购买 nike

我正在 C 上开发 MPI。我有一个自定义结构,我想使用 MPI 集体通信(收集、分散、广播)将其序列化并发送到其他节点

结构体如下

typedef struct {
double x[2]; /* Old and new X-axis coordinates */
double y[2]; /* Old and new Y-axis coordinates */
double xf; /* force along X-axis */
double yf; /* force along Y-axis */
double xv; /* velocity along X-axis */
double yv; /* velocity along Y-axis */
double mass; /* Mass of the body */
double radius; /* width (derived from mass) */
} bodyType;

我尝试了解 MPI 上自定义结构的序列化,但无法真正理解该过程。如果有人可以帮助我,那就太好了

谢谢

最佳答案

您的结构只是十个连续的 double 。因此,您无需告知 MPI 您的类型,因为它可以被视为数组。如果您有一个包含 7 个结构体的数组,只需告诉 MPI 您有一个包含 70 个 double 的数组。您应该告诉编译器“打包”您的结构(例如 GCC 或 Clang 中的 __attribute__((__packed__))),以便它没有填充。

关于c++ - 使用 MPI 集体通信发送结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33970824/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com