【发布时间】:2018-02-06 08:05:48
【问题描述】:
我正在编写一个 MPI 程序,我需要在其中收集从每个进程到根进程的数组。我正在使用MPI_Gatherv(因为数组可以具有可变长度)函数来执行此操作,但是,我不断收到PMPI_Gatherv(455): Negative count 异常。下面是执行 MPI_Gatherv 调用的代码 sn-p。由于代码太大,我没有发布完整的代码,但如果需要,我可以添加所需的代码部分。
double *errs;
int *rcounts, *displ;
printf("P:%d calling gather with count %d\n", p->rank, f->slice_size);
if (p->rank == 0) {
errs = (double*) malloc (sizeof(double) * NGRID);
rcounts = (int*) malloc (sizeof(int) * p->total);
displ = (int*) malloc (sizeof(int) * p->total);
}
MPI_Gatherv(f->err, f->slice_size, MPI_DOUBLE,
(void*) errs, rcounts, displ,
MPI_DOUBLE, 0, MPI_COMM_WORLD);
printf("P:%d done with gather\n", p->rank);
f->err 代表我要发送的数组,f->slice_size 是该数组的大小。第一个 printf 在所有 4 个进程上打印正确的值,但最后一个 printf 在除进程 0 之外的所有进程上执行。
我得到以下异常
P:0 calling gather with count 250
P:1 calling gather with count 250
P:1 done with gather
P:2 calling gather with count 250
P:2 done with gather
P:3 calling gather with count 250
P:3 done with gather
[cli_0]: aborting job:
Fatal error in PMPI_Gatherv:
Invalid count, error stack:
PMPI_Gatherv(547): MPI_Gatherv failed(sbuf=0x2588290, scount=0, MPI_DOUBLE, rbuf=0x2588a70, rcnts=0x2548750, displs=0x2546d90, MPI_DOUBLE, root=0, MPI_COMM_WORLD) failed
PMPI_Gatherv(455): Negative count, value is -1908728888
【问题讨论】:
-
rank 0 使用
count=0调用MPI_Gatherv(),但您已经打印了f->slice_size == 150,这很奇怪。另外,您没有发布如何初始化rcounts或displs,您应该首先在等级0 上打印这些值。我认为mvce 不会太大,所以请随意构建和发布一个。 -
你能看看stackoverflow.com/questions/31890523/… 吗?我希望这会对你有所帮助!