MPI_Scatter 中的 MPI 致命错误:收到 40 个字节,但缓冲区大小为 40

问题描述 投票:0回答:1

我有 4 个处理器,我需要在所有处理器上分散一个矩阵。 矩阵的形状为 8 x 5,每个处理器应该有一个 2 x 5 的块。

代码:

using namespace std;
int main(int* argc, char** argv)
{
    int rank;
    int* batch_a = new int[2 * COLUMN_A];
    int* matrix_a = new int[LINE_A * COLUMN_A];
...
    MPI_Init(argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (rank == 0)
    {
        cout << "Parent generating data in batch " << i << endl;
        new_line(matrix_a, LINE_A * COLUMN_A);
        new_line(matrix_b, COLUMN_A * COLUMN_B);
    }
        
    cout << "Process " << rank << " is waiting for scatter" << endl;
    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Scatter(matrix_a, LINE_A * COLUMN_A, MPI_INT, batch_a, COLUMN_A * 2, MPI_INT, 0, MPI_COMM_WORLD);

虽然运行后我遇到了这个问题:

Process 3 is waiting for scatter
Parent generating data in batch 0
Process 2 is waiting for scatter
Process 1 is waiting for scatter
Process 0 is waiting for scatter
Process 2 gathered a batch of matrix a
Process 1 gathered a batch of matrix a
Process 2 is waiting for broadcast
Process 1 is waiting for broadcast

job aborted:
[ranks] message

[0] fatal error
Fatal error in MPI_Scatter: Message truncated, error stack:
MPI_Scatter(sbuf=0x000001CB79BB5010, scount=40, MPI_INT, rbuf=0x000001CB79BC4740, rcount=10, MPI_INT, root=0, MPI_COMM_WORLD) failed
Message truncated; 40 bytes received but buffer size is 40

[1-3] terminated

---- error analysis -----

[0] on DESKTOP-24TO9BK
mpi has detected a fatal error and aborted MPI_Broadcast.exe

---- error analysis -----

我的 MPI_Scatter 函数做错了什么吗?我不知道。

我尝试用 const int 替换一批矩阵 a 的硬编码行数,但没有成功。

c mpi
1个回答
0
投票

MPI_Scattersendcount参数是发送到通信器中每个进程的块的大小,因此sendcount参数的值应与batch_a的大小相同。

© www.soinside.com 2019 - 2024. All rights reserved.