gpt4 book ai didi

c - MPI 超立方体广播错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:19:23 25 4
gpt4 key购买 nike

我有一个超立方体的一对多广播方法,使用 MPI 编写:

one2allbcast(int n, int rank, void *data, int count, MPI_Datatype dtype)
{
MPI_Status status;
int mask, partner;
int mask2 = ((1 << n) - 1) ^ (1 << n-1);

for (mask = (1 << n-1); mask; mask >>= 1, mask2 >>= 1)
{
if (rank & mask2 == 0)
{
partner = rank ^ mask;
if (rank & mask)
MPI_Recv(data, count, dtype, partner, 99, MPI_COMM_WORLD, &status);
else
MPI_Send(data, count, dtype, partner, 99, MPI_COMM_WORLD);
}
}
}

从 main 调用它时:

int main( int argc, char **argv )
{
int n, rank;

MPI_Init (&argc, &argv);
MPI_Comm_size (MPI_COMM_WORLD, &n);
MPI_Comm_rank (MPI_COMM_WORLD, &rank);

one2allbcast(floor(log(n) / log (2)), rank, "message", sizeof(message), MPI_CHAR);

MPI_Finalize();

return 0;
}

在 8 个节点上编译和执行时,我收到一系列错误报告,报告进程 1、3、5、7 在接收任何数据之前已停止:

MPI_Recv: process in local group is dead (rank 1, MPI_COMM_WORLD)
Rank (1, MPI_COMM_WORLD): Call stack within LAM:
Rank (1, MPI_COMM_WORLD): - MPI_Recv()
Rank (1, MPI_COMM_WORLD): - main()
MPI_Recv: process in local group is dead (rank 3, MPI_COMM_WORLD)
Rank (3, MPI_COMM_WORLD): Call stack within LAM:
Rank (3, MPI_COMM_WORLD): - MPI_Recv()
Rank (3, MPI_COMM_WORLD): - main()
MPI_Recv: process in local group is dead (rank 5, MPI_COMM_WORLD)
Rank (5, MPI_COMM_WORLD): Call stack within LAM:
Rank (5, MPI_COMM_WORLD): - MPI_Recv()
Rank (5, MPI_COMM_WORLD): - main()
MPI_Recv: process in local group is dead (rank 7, MPI_COMM_WORLD)
Rank (7, MPI_COMM_WORLD): Call stack within LAM:
Rank (7, MPI_COMM_WORLD): - MPI_Recv()
Rank (7, MPI_COMM_WORLD): - main()

我哪里出错了?

最佳答案

原来是错误在行

if (rank & mask2 == 0)

我没有考虑运算符(operator)优先级的地方。正确有效的写法是

if ((rank & mask2) == 0)

首先计算按位 & 的位置。

关于c - MPI 超立方体广播错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2994762/

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