gpt4 book ai didi

c - MPI_Gatherv,MPI_Gatherv : Pending request (no error), 错误堆栈中的 fatal error :

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

编辑#1:

所以解决方案是:

线

MPI_Gatherv(buffer, rank, MPI_INT, buffer, receive_counts, receive_displacements, MPI_INT, 0, MPI_COMM_WORLD);

必须改为

MPI_Gatherv(buffer, receive_counts[rank], MPI_INT, buffer, receive_counts, receive_displacements, MPI_INT, 0, MPI_COMM_WORLD);

再次感谢您的帮助


原帖:

我的代码来自DeinoMPI

当我运行 mpiexec -localonly 4 skusamGatherv.exe 时,一切都ok

如果我换行

int receive_counts[4] = { 0, 1, 2, 3 };

int receive_counts[4] = { 0, 1, 2, 1 };

编译仍然可以,但是当我运行 mpiexec -localonly 4 skusamGatherv.exe 时,我会得到错误

我认为它应该工作

感谢帮助


我会得到错误:

Fatal error in MPI_Gatherv: Message truncated, error stack:
MPI_Gatherv(363)........................: MPI_Gatherv failed(sbuf=0012FF4C, scou
nt=0, MPI_INT, rbuf=0012FF2C, rcnts=0012FEF0, displs=0012FED8, MPI_INT, root=0,
MPI_COMM_WORLD) failed
MPIDI_CH3_PktHandler_EagerShortSend(351): Message from rank 3 and tag 4 truncate
d; 12 bytes received but buffer size is 4
unable to read the cmd header on the pmi context, Error = -1
.
0. [0][0][0][0][0][0] , [0][0][0][0][0][0]
Error posting readv, An existing connection was forcibly closed by the remote ho
st.(10054)
unable to read the cmd header on the pmi context, Error = -1
.
Error posting readv, An existing connection was forcibly closed by the remote ho
st.(10054)
1. [1][1][1][1][1][1] , [0][0][0][0][0][0]
unable to read the cmd header on the pmi context, Error = -1
.
Error posting readv, An existing connection was forcibly closed by the remote ho
st.(10054)
2. [2][2][2][2][2][2] , [0][0][0][0][0][0]
unable to read the cmd header on the pmi context, Error = -1
.
Error posting readv, An existing connection was forcibly closed by the remote ho
st.(10054)
3. [3][3][3][3][3][3] , [0][0][0][0][0][0]

job aborted:
rank: node: exit code[: error message]
0: jan-pc-nb: 1: Fatal error in MPI_Gatherv: Message truncated, error stack:
MPI_Gatherv(363)........................: MPI_Gatherv failed(sbuf=0012FF4C, scou
nt=0, MPI_INT, rbuf=0012FF2C, rcnts=0012FEF0, displs=0012FED8, MPI_INT, root=0,
MPI_COMM_WORLD) failed
MPIDI_CH3_PktHandler_EagerShortSend(351): Message from rank 3 and tag 4 truncate
d; 12 bytes received but buffer size is 4
1: jan-pc-nb: 1
2: jan-pc-nb: 1
3: jan-pc-nb: 1
Press any key to continue . . .

我的代码:

#include "mpi.h"
#include <stdio.h>

int main(int argc, char *argv[])
{
int buffer[6];
int rank, size, i;
int receive_counts[4] = { 0, 1, 2, 3 };
int receive_displacements[4] = { 0, 0, 1, 3 };

MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (size != 4)
{
if (rank == 0)
{
printf("Please run with 4 processes\n");fflush(stdout);
}
MPI_Finalize();
return 0;
}
for (i=0; i<rank; i++)
{
buffer[i] = rank;
}
MPI_Gatherv(buffer, rank, MPI_INT, buffer, receive_counts, receive_displacements, MPI_INT, 0, MPI_COMM_WORLD);
if (rank == 0)
{
for (i=0; i<6; i++)
{
printf("[%d]", buffer[i]);
}
printf("\n");
fflush(stdout);
}
MPI_Finalize();
return 0;
}

最佳答案

退后一步,考虑一下 MPI_Gatherv 在做什么:它是一个 MPI_Gather(在本例中为 0 级),每个处理器可以在其中发送不同数量的数据。

在您的示例中,等级 0 发送 0 个整数,等级 1 发送 1 个整数,等级 2 发送 2 个整数,等级 3 发送 3 个整数。

MPIDI_CH3_PktHandler_EagerShortSend(351): Message from rank 3 and tag 4 truncated; 12 bytes received but buffer size is 4

它隐藏在许多其他信息中,但它表示第 3 级发送了 3 个整数(12 字节),但第 0 级只有 1 个整数的空间。

查看 gatherv 的前三个参数:'buffer, rank, MPI_INT'。无论您将 receive 设置为什么,等级 3 总是会发送 3 个整数。

请注意,您可以填充缓冲区不足(例如,您可以将 receive_counts 中的最后一项设置为 100),但您告诉 MPI 库使用更小的 receive_counts[3] 只期望 1 个 int,即使你发送了 3 个。

关于c - MPI_Gatherv,MPI_Gatherv : Pending request (no error), 错误堆栈中的 fatal error :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8009786/

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