这是简单的MPI程序:
#include <stdio.h>
#include <mpi.h>
main(int argc, char ** argv)
{
int rank,size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if(rank==0)
{
printf("Hello world, I'm process %d of %d and I'm the boss\n",rank,size);}
else{
printf("Hello world, I'm process %d of %d\n",rank,size);
}
MPI_Finalize();
}
这是教师使用的完全相同的代码!
以下是我编译的结果:
mpicc hello.c -o hellompi
mpirun -np 8 ./hellompi
Hello world, I'm process 0 of 1 and I'm the boss
Hello world, I'm process 0 of 1 and I'm the boss
Hello world, I'm process 0 of 1 and I'm the boss
Hello world, I'm process 0 of 1 and I'm the boss
Hello world, I'm process 0 of 1 and I'm the boss
Hello world, I'm process 0 of 1 and I'm the boss
Hello world, I'm process 0 of 1 and I'm the boss
Hello world, I'm process 0 of 1 and I'm the boss
显然,正确的代码会产生:
Hello world, I'm process 0 of 7 and I'm the boss
Hello world, I'm process 1 of 7
Hello world, I'm process 2 of 7
Hello world, I'm process 3 of 7
Hello world, I'm process 4 of 7
Hello world, I'm process 5 of 7
Hello world, I'm process 6 of 7
Hello world, I'm process 7 of 7
所以显然我需要卸载OpenMPI,MPI然后只需安装正确的MPI ...... 我该怎么做?
哦,是的,这就是我跑步时得到的:
cat /proc/cpuinfo | grep processor
processor :0
processor :1
processor :2
processor :3
processor :4
processor :5
processor :6
processor :7
加上我从来没有得到任何不同,即使我在mpirun -np 2
所以我sudo apt-get remove mpi
然后它看起来像卸载但我运行
mpichversion
仍然可以获得3.0.1版本
答案 0 :(得分:0)
好的是我卸载了OpenMPI并立即运行
sudo apt-get remove openmpi-common
我首先卸载然后重新安装MPI,这没有做任何事情。