Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PMPI_Bcast中的致命错误:无效的通信器_C_Mpi - Fatal编程技术网

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

PMPI_Bcast中的致命错误:无效的通信器,c,mpi,C,Mpi,我试图向一组进程广播,但在运行代码时出现以下错误(编译显示无错误): 这是我的代码: #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);

我试图向一组进程广播,但在运行代码时出现以下错误(编译显示无错误):

这是我的代码:

#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();
}
#包括
#包括
void main(int argc,char*argv[]){
int秩,大小,b=0;
MPI_Comm_a;
MPI_Group_world、new_Group;
MPI_Init(&argc,&argv);
MPI通信等级(MPI通信世界和等级);
MPI_通信大小(MPI_通信世界和大小);
MPI_Comm_group(MPI_Comm_WORLD和group_WORLD);
包括MPI集团(集团世界、4、成员和新集团);
MPI_Comm_create(MPI_Comm_WORLD、new_group和Comm_a);
MPI_Bcast(&b,1,MPI_INT,0,comm_a);
MPI_Finalize();
}

我做错了什么?

您的代码并没有像现在这样编译,所以我想很难告诉您实际的代码出了什么问题(假设这是一个简化版本的尝试)

然而,我仍然会做一个粗略的猜测,并假设
成员
只包括
group\u world
进程的一个子集。此外,我还猜您对
MPI\u Bcast()
的调用实际上是您发布的

如果我的假设是正确的,那么报告错误的原因是,对于
成员
中未列出的进程,
MPI\u Comm\u create()
将为
Comm\u a
返回
MPI\u Comm\u NULL
。因此,当您在
MPI\u Bcast()
中使用它时,您将收到报告的错误


要避免这种情况,请使用
MPI\u Comm\u split()
,这比
MPI\u Comm\u create()
要好得多,或者将调用的
MPI\u Bcast()括起来
if
语句中检查
a_comm
是否为
MPI_comm\u NULL
您的代码没有像现在这样编译,所以我想很难告诉您实际的代码出了什么问题(假设这是一个简化版本的尝试)

然而,我仍然会做一个粗略的猜测,并假设
成员
只包括
group\u world
进程的一个子集。此外,我还猜您对
MPI\u Bcast()
的调用实际上是您发布的

如果我的假设是正确的,那么报告错误的原因是,对于
成员
中未列出的进程,
MPI\u Comm\u create()
将为
Comm\u a
返回
MPI\u Comm\u NULL
。因此,当您在
MPI\u Bcast()
中使用它时,您将收到报告的错误

为了避免这种情况,可以使用
MPI\u Comm\u split()
,这比
MPI\u Comm\u create()
要好得多,或者将调用
MPI\u Bcast()
包含在
if
语句中,检查
a\u Comm
是否为
MPI\u Comm\u NULL

#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();
}