使用MPI_Gather会导致无法附加到引导队列错误

Using MPI_Gather leads to failed to attach to a bootstrap queue error

本文关键字:错误 队列 MPI Gather 使用      更新时间:2023-10-16

我需要编写代码,将矩阵列从每个进程发送到根进程。

我有以下代码:

int task8(int argc, char* argv[])
{
int rank, size;
double matrix[100][150];
double result_matrix[100][150];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
// generate matrix
srand((int)(MPI_Wtime() * 1e4));
for (int i = 0; i < 100; ++i)
{
for (int j = 0; j < 150; ++j)
{
matrix[i][j] = rand();
}
}
if (rank != 0)
{
// for (int i = rank; i < 100; i += size)
// {
//  MPI_Gather(&matrix[i], 150, MPI_DOUBLE, &matrix[i], 150, MPI_DOUBLE, 0, MPI_COMM_WORLD);
// }
// for (int i = 0; i <= size; i++)
// {
//  MPI_Gather(&matrix[i], 150, MPI_DOUBLE, &result_matrix[i], 150, MPI_DOUBLE, 0, MPI_COMM_WORLD);
// }
MPI_Gather(matrix[rank], 150, MPI_DOUBLE, result_matrix[rank], 150, MPI_DOUBLE, 0, MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}

但我不明白为什么突出显示的示例不起作用 - 它会产生错误:

C:UsersDima>mpiexec -n 4 D:codeparallellabs_examProject1DebugProject1.exe
job aborted:
[ranks] message
[0-1] terminated
[2] fatal error
Fatal error in MPI_Gather: Other MPI error, error stack:
MPI_Gather(sbuf=0x00212AB0, scount=150, MPI_DOUBLE, rbuf=0x001F55E8, rcount=150, MPI_DOUBLE, root=0, MPI_COMM_WORLD) failed
failed to attach to a bootstrap queue - 11660:216
[3] terminated
---- error analysis -----
[2] on DESKTOP-5SK57UV
mpi has detected a fatal error and aborted D:codeparallellabs_examProject1DebugProject1.exe
---- error analysis -----

我尝试从 mpi 文档中运行简单的示例,这些示例使用了MPI_gather函数并且它们工作正常。

MPI_Gather()是一个集体操作,因此必须在通信器的所有级别上调用(使用兼容的参数(。

在程序中,秩0不会调用MPI_Gather()因此程序将死锁或中止。