MPI 超立方体广播错误
我有一个超立方体的一对多广播方法,使用 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()
我哪里出错了?
I've got a one to all broadcast method for a hypercube, written using 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);
}
}
}
Upon calling it from 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;
}
compiling and executing on 8 nodes, I receive a series of errors reporting that processes 1, 3, 5, 7 were stopped before the point of receiving any data:
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()
Where do I go wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明,错误出现在
我没有考虑操作员优先级的行中。正确且有效的编写方式是
首先评估按位
&
。It turns out that the error was in the line
where I haven't accounted for operator priority. The correct and functioning way of writing it is
where the bitwise
&
gets evaluated first.当在 < code>MPI_Finalize 被调用。在调用
MPI_Finalize
之前,测试所有 MPI 调用是否已完成。It is a common error when a MPI communication is requested after a
MPI_Finalize
is called. Before callingMPI_Finalize
make test if all MPI calls are done.