Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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
MPI生成和合并问题_Mpi_Openmpi - Fatal编程技术网

MPI生成和合并问题

MPI生成和合并问题,mpi,openmpi,Mpi,Openmpi,我正在尝试开始在MPI中创建动态进程。我有一个父代码(main.c)试图生成新的worker/子进程(worker.c),并将两者合并到一个内部通信程序中。父代码(main.c)为 在拆分和合并之后,我希望输出为 size of intra comm world = 14 size of child comm world = 2 size of parent comm world = 12 child size of parent comm world = 12 child size of ch

我正在尝试开始在MPI中创建动态进程。我有一个父代码(main.c)试图生成新的worker/子进程(worker.c),并将两者合并到一个内部通信程序中。父代码(main.c)为

在拆分和合并之后,我希望输出为

size of intra comm world = 14
size of child comm world = 2
size of parent comm world = 12
child size of parent comm world = 12
child size of child comm world = 2
child size of intra comm world = 14
但是我得到了以下不正确的输出

   size of intra comm world = 3
    size of child comm world = 1
    size of parent comm world = 12
    child size of parent comm world = 2
    child size of child comm world = 2
    child size of intra comm world = 3
我不明白哪里出了错,请有人告诉我哪里出了错

谢谢,
Kris

您的代码存在一些问题,我将尝试在这里列出:

  • 在主控部分中,仅处理0个调用
    MPI\u Comm\u spawn()
    。这本身并不是一个错误(特别是因为您使用
    MPI\u COMM\u SELF
    作为父级通信器),但实际上它将所有其他进程排除在后续合并之外
  • 在主部件和辅助部件中,使用
    MPI\u Comm\u size()
    来获取远程通讯器的大小,而不是
    MPI\u Comm\u remote\u size()
    。因此,您将只获得inter-communicator内部的本地通信器的大小,而不是远程通信器的大小
  • 在主代码中,只有进程0调用
    MPI\u finalize()
    (更不用说缺少
    main()
    MPI\u Init()
以下是一些代码的固定版本:

master.c

#包括
#包括
int main(int argc,char*argv[]){
MPI_Init(&argc,&argv);
整数秩;
MPI通信等级(MPI通信世界和等级);
MPI_通信子通信;
int num_进程到产卵=2;
MPI_Comm_spawn(“./工作者”,MPI_ARGV_NULL,
num\u进程\u到\u繁殖,MPI\u信息\u空,
0,MPI_通信世界,
&子系统(通信、MPI错误代码、忽略);
MPI_通信内部通信;
MPI内部通信合并(子通信、0和内部通信);
如果(秩==0){
int tmp_尺寸;
MPI通信大小(内部通信和tmp通信大小);
printf(“通信内部世界的大小=%d\n”,tmp\U大小);
MPI_通信_远程_大小(子通信和tmp_大小);
printf(“子通信世界的大小=%d\n”,tmp\U大小);
MPI_通信大小(MPI_通信世界和tmp_大小);
printf(“父通信世界的大小=%d\n”,tmp\U大小);
}
MPI_Finalize();
返回0;
}
worker.c

#包括
#包括
int main(int argc,char*argv[]){
MPI_Init(&argc,&argv);
int-myrank;
MPI_Comm_rank(MPI_Comm_WORLD和myrank);
MPI_Comm parentcomm;
MPI_Comm_get_parent(&parentcomm);
MPI_通信内部通信;
MPI_内部通信合并(父通信、1和内部通信);
如果(myrank==0){
int tmp_尺寸;
MPI_通信_远程_大小(父通信和tmp_大小);
printf(“父通信世界的子大小=%d\n”,tmp\U大小);
MPI_通信大小(MPI_通信世界和tmp_大小);
printf(“子通信世界的子大小=%d\n”,tmp\U大小);
MPI通信大小(内部通信和tmp通信大小);
printf(“通信内部世界的子大小=%d\n”,tmp_大小);
}
MPI_Finalize();
返回0;
}
在我的笔记本电脑上显示:

~>mpirun-n 12./master
父通信世界的子大小=12
子通信世界的子大小=2
通信内部世界的子大小=14
通信内部世界的大小=14
子通信世界的大小=2
父通信世界的大小=12

谢谢Gilles。我意识到这是一个远程组大小的问题;
mpirun -np 12 main.c
size of intra comm world = 14
size of child comm world = 2
size of parent comm world = 12
child size of parent comm world = 12
child size of child comm world = 2
child size of intra comm world = 14
   size of intra comm world = 3
    size of child comm world = 1
    size of parent comm world = 12
    child size of parent comm world = 2
    child size of child comm world = 2
    child size of intra comm world = 3