1,下载MPICH : http://www.mpich.org/downloads/
2,解压文件,并进入目录运行命令:
(1)tar zxvf mpich-3.2.tar.gz
(2)cd mpich-3.2
(3)./configure --prefix=/home/renzhen/mpich ( = 后面是文件安装路径)
(4) make && make install
3,配置环境变量:
在PATH 上添加 /home/renzhen/mpich/bin 路径
可以通过向文件 /etc/profile 最后添加一行 export PATH=/home/renzhen/mpich/bin:$PATH
然后记得source /etc/profile
4,配置多服务器间无密码访问
步骤1: 用 ssh-key-gen 在本地主机上创建公钥和密钥
renzhen@yrscentos$ ssh-keygen -t rsa 所有提示都按回车跳过
步骤2: 用 ssh-copy-id 把公钥复制到远程主机上
renzhen@yrscentos$ ssh-copy-id -i ~/.ssh/id_rsa.pub renzhen@192.168.0.3
步骤3: 直接登录远程主机
renzhen@yrscentos$ ssh renzhen@192.168.0.3
以 ssh hostname 方式登陆,node*在实际情况中要替换成服务器的主机名,可通过hostname获得主机名:
向 /etc/hosts 里添加: 192.168.0.3 (ip) : hostname (计算机名)
测试:
renzhen@yrscentos$ ssh hostname
注意:各太服务器的用户名要相同,不然不能通过ssh hostname 登陆,看到其他博客说道可以通过配置 .ssh/config 文件,可以使不同用户名可以 ssh hostname 登陆,但是我没有配好。大家也可以试试,成功的话别忘了告诉俺一声。
5, 添加servers文件
在mpich 下新建servers 文件,并添加 hostname:线程数,包含所有的主机名。
例如:
renzhen-pc:2
yrscentos:2
......................
6, 运行测试程序
(1)单点运行
renzhen@yrscentos$ mpirun -np 4 ~/mpich-3.2/examples/cpi
(2) 多点并行
renzhen@yrscentos$ mpiexec -n 4 -f ~/mpich/servers ~/mpich-3.2/examples/cpi
7,可能出现的错误:
利用mpich 进行多点并行运算时,出现以下错误:
➜ bin ./mpiexec -n 4 -f ~/mpich/servers ~/mpich-3.2/examples/cpi
Process 3 of 4 is on yrscentos
Process 2 of 4 is on yrscentos
Process 0 of 4 is on renzhen-pc
Process 1 of 4 is on renzhen-pc
Fatal error in PMPI_Reduce: Unknown error class, error stack:
PMPI_Reduce(1258)...............: MPI_Reduce(sbuf=0x7fff2a4c16e0, rbuf=0x7fff2a4c16e8, count=1, MPI_DOUBLE, MPI_SUM, root=0, MPI_COMM_WORLD) failed
MPIR_Reduce_impl(1070)..........:
MPIR_Reduce_intra(823)..........:
MPIR_Reduce_impl(1070)..........:
MPIR_Reduce_intra(878)..........:
MPIR_Reduce_binomial(186).......:
MPIDI_CH3U_Recvq_FDU_or_AEP(629): Communication error with rank 2
MPIR_Reduce_intra(843)..........:
MPIR_Reduce_impl(1070)..........:
MPIR_Reduce_intra(878)..........:
MPIR_Reduce_binomial(248).......: Failure during collective
或:
[renzhen@yrscentos 桌面]$ mpiexec -n 4 -f ~/mpich/servers ~/mpich-3.2/examples/cpi
[proxy:0:0@renzhen-pc] HYDU_sock_connect (utils/sock/sock.c:172): unable to connect from "renzhen-pc" to "yrscentos" (No route to host)
[proxy:0:0@renzhen-pc] main (pm/pmiserv/pmip.c:189): unable to connect to server yrscentos at port 58753 (check for firewalls!
出现这两种情况可能是因为防火墙的问题。第一种情况是登陆的主节点正常,而从节点的防火墙没关闭。在ssh能免密码登陆的情况下,第二种情况是自己的防火墙没有关闭。