我是MPI并行编程的初学者。我写了一小段代码来绘制Mandelbrot fracta。这个想法是,第一个从设备将计算前半部分,将其粘贴在一个指针中,并将其发送给正在等待接收指针的主节点。第二个节点发生同样的事情。最后,主节点应该有2个不同的变量结果,并将它们写入一个文件中。MPI程序在MPI_Recv中冻结
......
if((itertab=malloc((sizeof(int)*sizebuffre))) == NULL) {
printf("ERREUR , errno : %d (%s) .\n",errno,strerror(errno));
return EXIT_FAILURE;
}
int rank, size,start,end;
MPI_Init (&argc, &argv); /* starts MPI */
MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */
MPI_Status st;
/*allocation du tableau de pixel*/
if (rank==1) {
xpixel = 0;
end = (nbpixelx/MACHINE_NUM);
Calcule(xpixel,end);
printf("rank 1 start : %d, end : %d\n",xpixel,end);
MPI_Send(&itertab,sizebuffre,MPI_INT,0,5,MPI_COMM_WORLD);
free(itertab);
printf("work done : i am rank 1 \n");
}
if (rank==2) {
xpixel = (nbpixelx/MACHINE_NUM);
end = nbpixelx;
Calcule(xpixel,end);
printf("rank 2 start : %d, end : %d\n",xpixel,end);
MPI_Send(&itertab,sizebuffre,MPI_INT,0,6,MPI_COMM_WORLD);
printf("work done : i am rank 2 \n");
free(itertab);
}
if (rank==0) {
if((itertabA=malloc((sizeof(int)*sizebuffre))) == NULL) {
printf("ERREUR d'allocation de itertabA, errno : %d (%s) .\n",errno,strerror(errno));
return EXIT_FAILURE;
}
if((itertabB=malloc((sizeof(int)*sizebuffre))) == NULL) {
printf("ERREUR d'allocation de itertabB, errno : %d (%s) .\n",errno,strerror(errno));
return EXIT_FAILURE;
}
printf("test before reciving result from first slave\n");
MPI_Recv(itertabA,sizebuffre,MPI_INT,1,5,MPI_COMM_WORLD,&st);
printf("result recived rank 1 \n");
MPI_Recv(itertabB,sizebuffre,MPI_INT,2,6,MPI_COMM_WORLD,&st);
printf("result recived rank 2 \n");
}
MPI_Finalize();
return EXIT_SUCCESS;
}
的问题是,我的代码在主设备接收从第一从结果行冻结,但我不知道为什么?
我试图调试结果。我添加了一些printf来查看它冻结的位置。这是结果:
test before reciving result from first slave
test in calcule function
trairment xpixel 0
trairment xpixel 1
trairment xpixel 2
...snip...
trairment xpixel 399
test after the end off calculating loop
rank 1 start : 0, end : 400
^C
欢迎来到StackOverflow!总的来说,你的问题并不差(特别是对于非母语初学者),但是在你的问题中,我已经改进了一些可以用来改进未来问题的东西。查看编辑内容,以便下次学习。 – 2015-04-07 14:48:10