【发布时间】:2018-04-16 21:34:10
【问题描述】:
我在执行 MPI_Recv 时收到以下错误输出:
MPI_Recv(buf=0x000000D62C56FC60, count=1, MPI_INT, src=3, tag=0, MPI_COMM_WORLD, status=0x0000000000000001) failed
Message truncated; 8 bytes received but buffer size is 4
我的函数需要找到在ind 位置具有最大元素的行数。
我的函数代码如下:
int find_row(Matr matr, int ind)
{
int max = ind;
for (int i = ind + 1 + CurP; i < N; i += Pnum)
if (matr[i][ind] > matr[max][ind])
max = i;
int ans = max;
if (CurP != 0)
{
MPI_Send(&max, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
}
else
{
MPI_Barrier(MPI_COMM_WORLD);
for (int i = 1; i < Pnum; i++)
{
MPI_Recv(&max, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("max %d %Lf! Process %d;\n", max, matr[max][ind], i);
fflush(stdout);
if (matr[max][ind] > matr[ans][ind])
ans = max;
}
}
return ans;
}
Matr 是以下类型定义:typedef vector<vector<long double> >& Matr;
CurP和Pnum的初始化方式如下:
MPI_Comm_size(MPI_COMM_WORLD, &Pnum);
MPI_Comm_rank(MPI_COMM_WORLD, &CurP);
请帮我解决这个问题。谢谢!
【问题讨论】:
-
这个错误有什么奇怪的?据说它收到了 8 个字节,但只能容纳 4 个
-
奇怪,因为它适用于前两个进程,但当它们具有相同代码时,第三个进程会崩溃
-
消息状态为
src=3,因此至少有 4 个任务。请注意,您的程序可能会死锁,因为在屏障之前没有发布 recv。问题可能出在您未显示的代码中,因此请编辑您的问题并添加minimal reproducible example。
标签: mpi