【发布时间】:2021-11-19 15:56:02
【问题描述】:
如果我有 2 个结构,
struct {
int a;
int b;
} st_a;
和
struct {
double c;
st_a d;
} st_b;
有没有办法使用 mpi_Send 发送 st_b?
【问题讨论】:
-
MPI 类型构造是递归的。所以你可以为
st_a创建一个结构或连续类型,然后为st_b创建一个结构类型。
如果我有 2 个结构,
struct {
int a;
int b;
} st_a;
和
struct {
double c;
st_a d;
} st_b;
有没有办法使用 mpi_Send 发送 st_b?
【问题讨论】:
st_a创建一个结构或连续类型,然后为st_b创建一个结构类型。
你以同样的方式发送结构。结构只是连续的字节,嵌套结构也不例外。根据文档https://www.mpich.org/static/docs/v3.3/www3/MPI_Send.html,您只需要注意大小,但这应该不是问题,因为您有多种方法可以在 C 中获得所需的 sizeof。
你也可能想看看这篇文章:
How to send nested structure using MPI_Datatype in MPI using C
【讨论】: