PMPI_Bcast中的致命错误:无效的通信器

时间:2015-12-24 09:45:30

标签: c mpi

我尝试向一组进程广播但是在运行代码时遇到以下错误(编译显示没有错误):

Fatal error in PMPI_Bcast: Invalid communicator, error stack:
PMPI_Bcast(1525): MPI_Bcast(buf=0xbfbf1510, count=1, MPI_INT, root=0, MPI_COMM_NULL) failed
PMPI_Bcast(1466): Null communicator

这是我的代码:

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

void main (int argc, char *argv[]) {
    int rank,size,b=0;
    MPI_Comm comm_a;
    MPI_Group group_world,new_group;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    MPI_Comm_group(MPI_COMM_WORLD, &group_world);
    MPI_Group_incl(group_world, 4, members, &new_group);
    MPI_Comm_create(MPI_COMM_WORLD, new_group, &comm_a);

    MPI_Bcast(&b,1,MPI_INT,0,comm_a);

    MPI_Finalize();
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

你的代码现在没有编译,所以我想有点难以告诉你实际的代码有什么问题(假设这是试图缩小版本)。

但是,我仍然会猜测,并假设members只包含group_world的一部分过程。此外,我还猜测你对MPI_Bcast()的呼吁与你发布的一样......

如果我的假设正确,那么报告错误的原因是,对于members中未列出的流程,MPI_Comm_create()将返回MPI_COMM_NULL { {1}}。因此,当您在comm_a中使用它时,您会收到报告的错误。

要避免这种情况,请使用MPI_Bcast(),这比MPI_Comm_split()更好,或者在MPI_Comm_create()语句中调用MPI_Bcast(),并检查if不是a_comm

相关问题