我试图从进程0发送数据处理1.当缓冲区大小小于64KB这个计划成功,但如果缓冲区变得更大挂起.以下代码应该重现此问题(应该挂起),但如果n修改为小于8000 则应该成功.
int main(int argc, char *argv[]){
int world_size, world_rank,
count;
MPI_Status status;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
if(world_size < 2){
printf("Please add another process\n");
exit(1);
}
int n = 8200;
double *d = malloc(sizeof(double)*n);
double *c = malloc(sizeof(double)*n);
printf("malloc results %p %p\n", d, c);
if(world_rank == 0){
printf("sending\n");
MPI_Send(c, n, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD);
printf("sent\n");
}
if(world_rank == 1){
printf("recv\n");
MPI_Recv(d, n, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status);
MPI_Get_count(&status, MPI_DOUBLE, &count);
printf("recved, count:%d source:%d tag:%d error:%d\n", count, status.MPI_SOURCE, status.MPI_TAG, status.MPI_ERROR);
}
MPI_Finalize();
}
Output n = 8200;
malloc results 0x1cb05f0 0x1cc0640
recv
malloc results 0x117d5f0 0x118d640
sending
Output n = 8000;
malloc results 0x183c5f0 0x184c000
recv
malloc results 0x1ea75f0 0x1eb7000
sending
sent
recved, count:8000 source:0 tag:0 error:0
Run Code Online (Sandbox Code Playgroud)
我发现这个问题和这个问题类似,但我认为存在的问题是创建死锁.我不希望这里出现类似的问题,因为每个进程只执行一次发送或接收.
编辑:添加状态检查.
EDIT2:问题似乎是我安装了OpenMPI,但在安装MKL时还安装了Intel的MPI实现.我的代码是使用OpenMPI头文件和库编译的,但是使用Intel的mpirun运行.当我确保使用OpenMPI中的mpirun可执行文件运行时,所有工作都按预期工作.
问题在于同时安装了 Intel 的 MPI 和 OpenMPI。我看到 /usr/include/mpi.h 属于 OpenMPI,但 mpicc 和 mpirun 来自 Intel 的实现:
$ which mpicc
/opt/intel/composerxe/linux/mpi/intel64/bin/mpicc
$ which mpirun
/opt/intel/composerxe/linux/mpi/intel64/bin/mpirun
Run Code Online (Sandbox Code Playgroud)
我能够通过运行解决这个问题
/usr/bin/mpicc
Run Code Online (Sandbox Code Playgroud)
和
/usr/bin/mpirun
Run Code Online (Sandbox Code Playgroud)
确保我使用了 OpenMPI。
感谢@Zulan 和@gsamaras 提出检查我的安装的建议。