现在的位置: 首页 > 综合 > 正文

MPICH3环境配置

2013年01月14日 ⁄ 综合 ⁄ 共 1947字 ⁄ 字号 评论关闭

    最新版的mpich简化了运行方式,不再提供mpd开头的命令,只需要一个mpiexec即可启动mpi运行环境,方便了mpi编程。源代码下载地址:http://www.mpich.org/downloads/。不过和之前的版本一样,在运行mpi程序时,首先要配置好系统环境。

1.       安装mpich3

从上述网址下载源代码后,解压,然后configure,最后make和make install。命令如下:

  • root@nami:~# tar zxvf mpich-3.0.4.tar.gz
  • root@nami:~# cd mpich-3.0.4/
  • root@nami:~/mpich-3.0.4# ./configure --prefix=/usr/local/mpich
  • root@nami:~/mpich-3.0.4# make
  • root@nami:~/mpich-3.0.4# make install

2.       配置环境变量

主要是修改path,为path添加mpi的bin目录:

  • root@nami:~# vim .bashrc
  • 在.bashrc文件的末尾添加:export PATH=/usr/local/mpich/bin:$PATH
  • root@nami:~# source .bashrc
  • root@nami:~# echo $PATH,查看PATH变量是否发生变化;
  • root@nami:~# ls /usr/local/mpich/bin,查看bin下的可执行程序;
  • root@nami:~# which mpiexec,查看命令是否是我们安装目录下的命令

3.       配置多服务器间无密码访问

  • 在每台服务器上都执行ssh-keygen -t rsa生成密钥对: #ssh-keygen -t rsa,所有提示都按回车跳过。这时会在根目录下生成一个目录.ssh。里面有两个文件:id_rsa和id_rsa.pub。分别表示私钥和公钥。
  • 将每台服务器上的公钥,即id_rsa.pub分别复制到其他的服务器:#ssh-copy-id –i ~/.ssh/id_rsa.pub root@192.168.5.***。 以上命令,可以自动将公钥添加到名为authorized_keys的文件中,在每台服务器都执行完以上步骤后就可以实现多台服务器相互无密码登陆了。
  • 可以通过修改/etc/hosts文件将IP与host名对应,例如可添加如下行:

192.168.5.123    node1

192.168.5.124    node2

192.168.5.125    node3

到hosts的末尾。node*在实际情况中要替换成服务器的主机名,可通过hostname获得主机名。

  • 通过ssh命令访问不同的服务器,如果不需要密码则说明服务器之间可以无密码访问:#ssh   node1。

4.       添加machinefile文件

该步骤是在各个服务器上指明要访问的其他服务器,在不同的服务器上内容一样。例如node1下的该文件内容为:

root@node1:~# cat machinefile

node1

node2

node3

5.       运行测试程序

root@nami:~# mpiexec -n 6 -machinefile ~/machinefile ~/ mpich-3.0.4/examples/cpi

       通过运行该命令测试是否正确安装mpich3。注意一点可执行程序在不同服务器上的位置要一样,否则会报错。上述命令的结果是:

Process 2 of 6 is on node1

Process 5 of 6 is on node1

Process 0 of 6 is on node2

Process 3 of 6 is on node2

Process 1 of 6 is on node3

Process 4 of 6 is on node3

pi is approximately 3.1415926544231243, Error is 0.0000000008333312

wall clock time = 0.001908

       更多的命令参数可参看官网文档:http://www.mpich.org/static/downloads/3.0.4/mpich-3.0.4-userguide.pdf

       按照上述步骤绝大多数情况下可以正确安装mpich3,有一点需要注意,在所有的服务器上运行的mpi版本必须一致,否则也会出错。有时有些问题是由于防火墙导致的,在运行mpi程序时,我们可以关掉防火墙:

  • 关闭防火墙

                    #service iptables stop

  • 查看防火墙状态

                  #service iptables status

       但总而言之,mpich3运行过程中出现的问题要比mpich2少很多,也方便很多。

抱歉!评论已关闭.