码迷,mamicode.com
首页 > 其他好文 > 详细

Intel MPI 5.1.3安装配置详解

时间:2016-10-05 01:20:02      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:mpi

写在之前:

MPI简述:

MPI的全称是Message Passing Interface即标准消息传递界面,可以用于并行计算。MPI有多种实现版本,如MPICH CHIMP以及OPENMPI。这里我们采用MPICH版本。

MPI是一个库,而不是一门语言。许多人认为,MPI就是一种并行语言,这是不准确的。但是,按照并行语言的分类,可以把FORTRAN+MPI或C+MPI看作是一种在原来串行语言基础之上扩展后得到的,并行语言MPI库可以被FORTRAN77/C/Fortran90/C++调用,从语法上说,它遵守所有对库函数/过程的调用规则,和一般的函数/过程没有什么区别。

高性能并行计算计算机技术由于具有巨大的数值计算和数据处理能力,在国内外受到高度重视,他在科学研究、工程技术以及军事等方面的应用,已经取得巨大的成就。并行计算就是通过把一个大的计算问题分解成许多彼此独立且有相关的子问题,然后把他们散列到各个节点机上并行执行从而最终解决问题的一种方法。

安装环境:

网络拓扑图:

技术分享

其中InfiniBand网络用于MPI并行计算集群的数据通信,普通千兆以太网用于服务器管理、存储共享等。


服务器清单

用途

主机名

IP Private

Management

IP Application

InfiniBand

OS Version

Intel MPI

Version



存储节点

stor

10.10.10.253


RHEL 6.8  x64

5.1.3.181



管理节点

master

10.10.10.10

10.10.11.10

RHEL 6.8  x64

5.1.3.181



计算节点1

compute01

10.10.10.1

10.10.11.1

RHEL 6.8  x64

5.1.3.181



计算节点2

compute02

10.10.10.2

10.10.11.2

RHEL 6.8  x64

5.1.3.181



计算节点3

compute03

10.10.10.3

10.10.11.3

RHEL 6.8  x64

5.1.3.181



计算节点4

compute04

10.10.10.4

10.10.11.4

RHEL 6.8  x64

5.1.3.181



计算节点5

compute05

10.10.10.5

10.10.11.5

RHEL 6.8  x64

5.1.3.181



计算节点6

compute06

10.10.10.6

10.10.11.6

RHEL 6.8  x64

5.1.3.181



计算节点7

compute07

10.10.10.7

10.10.11.7

RHEL 6.8  x64

5.1.3.181



计算节点8

compute08

10.10.10.8

10.10.11.8

RHEL 6.8  x64

5.1.3.181



 

一、安装操作系统

计算节点、管理节点的操作系统为RHEL 6.8 x64,安装方式:Minual+Network File System Client+Development所有开发工具+Chinese Support

存储节点由于接有显示器,操作系统为RHEL 6.8 x64,安装方式:Desktop+NFS File Server+Development所有开发工具+Chinese Support  Minual+NFS File Server+Development所有开发工具+Chinese Support

1、系统安装完成后,配置网络、安装IB卡驱动及配置IB网络,保证ssh服务正常启动,再依次关闭防火墙、关闭SELinux

所有服务器的/etc/hosts文件配置如下

10.10.10.1      compute01eth0
10.10.10.2      compute02eth0
10.10.10.3      compute03eth0
10.10.10.4      compute04eth0
10.10.10.5      compute05eth0
10.10.10.6      compute06eth0
10.10.10.7      compute07eth0
10.10.10.8      compute08eth0
10.10.10.10    mastereth0
10.10.10.253    stor
 
10.10.11.1      compute01
10.10.11.2      compute02
10.10.11.3      compute03
10.10.11.4      compute04
10.10.11.5      compute05
10.10.11.6      compute06
10.10.11.7      compute07
10.10.11.8      compute08
10.10.11.10   
  master


网络配置信息请参照/etc/hosts文件进行配置,以太网网关10.10.10.254IB网络无网关。

##关闭防火墙
chkconfig iptables off
chkconfig|grep iptables

##关闭SELinux
more /etc/selinux/config
vi /etc/selinux/config
SELINUX=disabled
##保存后reboot生效

 

2、服务器重启完成后,配置ntp服务

其中NTP Server端为stor节点,管理节点和计算节点通过crontab来同步时间

[root@stor ~]#
  more /etc/ntp.conf
restrict default
  kod nomodify notrap nopeer noquery
restrict -6
  default kod nomodify notrap nopeer noquery
restrict
  127.0.0.1 
restrict -6 ::1
restrict
  10.10.0.0 mask 255.255.0.0 nomodify  //该网段可以进行校时
server
  time.windows.com prefer                 
  //prefer 该服务器优先
fudge   127.127.1.0 stratum 10  
driftfile
  /var/lib/ntp/drift
keys /etc/ntp/keys
 
[root@master ~]#
  crontab -l
00 8 * * * /usr/sbin/ntpdate 10.10.10.253 
  ##每天8点向10.10.10.253同步时间

 

3创建普通用户

##所有节点都创建,torque任务调度软件需用普通账户执行

[root@stor
  ~]# groupadd -g 500 test
[root@stor
  ~]# useradd -u 500 -g 500 -d /home/test -m test
[root@stor
  ~]# passwd test


 

4、配置yum

可以利用安装ISO文件配置为yum

A、上传安装ISO文件到服务器,并挂载

[root@stor ~]# mount  -o loop /root/rhel-server-6.8-x86_64-dvd.iso /mnt

 

B、编写yum配置文件

[root@mpitest ~]#  more /etc/yum.repos.d/rhel-source.repo

[rhel-source]

name=Red Hat  Enterprise Linux $releasever - $basearch - Source

baseurl=file:///mnt

enabled=1

gpgcheck=0

 

C、刷新yum缓存

[root@stor ~]# yum clean all  ##清空现有yum缓存

[root@stor ~]# yum makecache  ##配置yum缓存

 

其他节点也可参照此配置。

还可以通过NFSrhel-server-6.8-x86_64-dvd.iso的安装文件共享,再参照此配置。

 

 

二、设置通过主机名无密码登录

1、通过主机名访问

为每个节点分配IP地址,IP地址最好连续分配,配置/etc/hosts文件,实现IP地址和机器的对应解析。

可以在所有机器上使用同样的/etc/hosts 文件,它包含如下形式的内容:

10.10.10.1      compute01eth0

10.10.10.2      compute02eth0

10.10.10.3      compute03eth0

10.10.10.4      compute04eth0

10.10.10.5      compute05eth0

10.10.10.6      compute06eth0

10.10.10.7      compute07eth0

10.10.10.8      compute08eth0

10.10.10.10    mastereth0

10.10.10.253    stor

 

10.10.11.1      compute01

10.10.11.2      compute02

10.10.11.3      compute03

10.10.11.4      compute04

10.10.11.5      compute05

10.10.11.6      compute06

10.10.11.7      compute07

10.10.11.8      compute08

10.10.11.10     master

2、计算节点与管理节点之间的无密码访问

 

A、所有计算节点compute0[1-8]master分别执行

mkdir -p ~/.ssh
chmod 755 ~/.ssh
/usr/bin/ssh-keygen -t rsa

##会生成两个文件

id-rsa     #私钥

id-rsa.pub   #公钥

 

B、复制keymaster

          ###########拷贝方法1,二选一

以下命令只在一个节点上执行,此例为master

ssh compute0[1-8] cat ~/.ssh/id_rsa.pub >>
  ~/.ssh/authorized_keys
ssh compute0[1-8] cat ~/.ssh/id_dsa.pub >>
  ~/.ssh/authorized_keys

 

          ###########拷贝方法2,二选一

所有计算节点compute0[1-8]master分别执行

cat ~/.ssh/id_rsa.pub >>
  ~/.ssh/authorized_keys
cat ~/.ssh/id_dsa.pub >>
  ~/.ssh/authorized_keys

以下命令只在一个节点上执行,此例为master

ssh compute0[1-8] cat ~/.ssh/authorized_keys
  >> ~/.ssh/authorized_keys

 

C、将key下发到各compute节点

master上将所有节点的authorized_keys下发到所有节点

scp ~/.ssh/authorized_keys
  compute0[1-8]:~/.ssh/authorized_keys

 

D、测试

以下命令在所有节点上执行,不做任何操作就能反馈命令结果,即为测试通过。

ssh compute0[1-8] hostname
ssh master hostname


##备注:第2操作需在root账户和test账户下都执行,因为mpitorque安装会通过root超级账户、 mpitorque软件配置与使用要通过test普通账户。

RHEL 6.6后的版本中,普通账户的ssh无密码认证需要通过ssh-copy-id命令来拷贝密钥。

同理,root账户的也可以通过这种方式,效率比上一种方式更高。

依次在master和计算节点上运行

Master:

# ssh-keygen -r rsa
# ssh-copy-id -i  ~/.ssh/id_rsa.pub master 
  ##将master的公钥拷贝到master上
# ssh-copy-id -i  ~/.ssh/id_rsa.pub node    
  ##将master的公钥拷贝到node上


 

Node:

# ssh-keygen -r rsa
# ssh-copy-id -i  ~/.ssh/id_rsa.pub master 
  ##将node的公钥拷贝到master上
# ssh-copy-id -i  ~/.ssh/id_rsa.pub node  
  ##将node的公钥拷贝到node上


 

三、NFS文件系统的配置

通过NFS方式,执行文件只需要上传一次到存储服务器,其他节点就可以访问。

方法示例如下:(NFS存储服务器IP 10.10.10.253,配置需在root用户下完成)

1、服务器端配置方法(下面的配置只在存储节点进行)

NFS服务器端配置 

/etc/exports 文件配置

在文件/etc/exports 中增加以下几行:

/data 10.10.10.1(rw,sync,no_root_squash)

/data 10.10.10.2(rw,sync,no_root_squash)

/data 10.10.10.3(rw,sync,no_root_squash)

/data 10.10.10.4(rw,sync,no_root_squash)

/data 10.10.10.5(rw,sync,no_root_squash)

/data 10.10.10.6(rw,sync,no_root_squash)

/data 10.10.10.7(rw,sync,no_root_squash)

/data 10.10.10.8(rw,sync,no_root_squash)

/data 10.10.10.10(rw,sync,no_root_squash)

这几行文字表明NFS 服务器向IP 地址为10.10.10.【1-8,10的9个节点共享其/data目录,并使这些节点具有可读写权限、继承root账户权限、且保证数据唯一性。

 

接着执行如下命令,启动端口映射:

# /etc/rc.d/init.d/rpcbind start   (注:在最新内核中NFS守护进程改为rpcbind,如是旧内核启动NFS守护进程的命令是 service portmap start

最后执行如下命令启动NFS 服务,此时NFS 会激活守护进程,然后就开始监听 Client 端的请求:

# /etc/rc.d/init.d/nfs start   ##启动nfs服务,也可以执行完以下两个命令后,重新启动Linux 服务器,系统自动启动NFS 服务。

[root@mpitest ~]# chkconfig rpcbind on    ##NFS守护进程设置为随系统自动启动

[root@mpitest ~]# chkconfig nfs on   ##nfs服务设置为随系统自动启动

 

2、客户端配置方法(需要在所有子节点做同样的配置)

建立与服务器相同的共享目录用于共享服务器文件:

mkdir /data

挂载共享目录:

mount -t nfs 10.10.10.253:/data /data

这一命令将 NFS 服务器10.10.10.253上的共享目录/data挂载到本地/data目录下

 

我们也可在所有子节点的/etc/fstab 文件中输入以下的代码,使文件系统在启动时实现自动挂载NFS

10.10.10.253:/data /data nfs defaults 0 0

至此我们已可以实现对 NFS 共享目录的本地访问,所有子节点的/data目录都共享了NFS 服务器的同名文件夹的内容,我们可以像访问本地文件一样访问共享文件。

用户存放并行程序的文件夹都可以实现NFS 共享,从而避免了每次向各节点发送程序副本。

 

四、安装其他组件(在Intel mpi 5.1.3版本中已经集成了这部分,可不安装

Intel C++ Compiler,即icc 

#tar xvzf l_ccompxe_2013.1.117.tgz

# cd composer_xe_2013.1.117

#./install.sh

 

设置环境变量:

#vi /etc/profile

添加一行source /opt/intel/composer_xe_2013.1.117/bin/iccvars.sh intel64

 

测试环境变量设置:

#which icc

如果能看到/opt/intel/composer_xe_2013.1.117/bin/intel64/icc,那么就安装设置成功了。

 

安装Intel_Fortran编译器

###Intel mpi 5.1.3版本中已经集成了这部分,可不安装

#tar fxvz l_fcompxe_2013.1.117.tgz

# cd l_fcompxe_2013.1.117

#./install.sh

 

设置环境变量:

#vi /etc/profile

添加一行source /opt/intel/composer_xe_2013.1.117/bin/compilervars.sh intel64

 

测试环境变量设置:

#which ifort

如果能看到/opt/intel/composer_xe_2013.1.117/bin/intel64/ifort ,那么就安装设置成功了。

 

五、安装Intel MPI

将软件上传到存储节点的/data目录,这样子其他节点可直接使用。

1、软件安装

安装前一定要将Fortran编译器安装好,c++放到最后没有影响,其它版本MPI就需要先将前2个软件安装好,设置好环境变量,最后在安装MPI程序。

  ###root账户在每个计算节点和管理节点执行安装过程

#tar xzvf l_mpi_p_5.1.3.181.tgz

#cd l_mpi_p_5.1.3.181

#./install.sh

技术分享

提示安装一共分为6个步骤,敲击Enter键继续安装过程,q键退出安装过程

技术分享

 

技术分享

第二步:显示软件授权信息,通过空格键翻页显示,到最底下输入accept接受授权许可并继续下一步安装操作,或者decline退回到上一安装界面。

技术分享

第三步:激活软件。根据Intel的授权协议,Runtime版本的MPI属于免费,Developer版本的MPI属于收费项目。

技术分享

               此处我们安装的属于Runtime版本,选择2“评估使用此软件或者稍后激活”,

技术分享

回车下一步安装操作

技术分享

第四步:选择软件安装方式,可通过集群安装或者单节点安装,此处输入1并回车

技术分享

第四步:确认安装方式,根据安装界面提示的软件安装目录、软件安装组件、软件安装容量需求、软件安装目标等信息,选择安装方式。包括1默认的安装方式还是2自定义的,此处选择1并回车。

提示/opt/intel目录已经存在,yes确认回车,开始安装过程。

技术分享

第五步:软件安装过程。显示安装过程,安装完成后,Enter回车继续

技术分享

第六步:安装完成,敲击Enter退出安装界面。

 

2、基础配置

设置环境变量:每个节点都要配置

#vi /etc/profile

添加

source /opt/intel/compilers_and_libraries/linux/bin/compilervars.sh intel64

source /opt/intel/impi/5.1.3.181/bin64/mpivars.sh

注意:以上的环境变量设置好后建议重启,或者重新登录当前会话使环境变量生效

 

测试环境变量设置 每个节点都要检查

which mpd
which mpicc
which mpiexec
which mpirun

如果能看到所有命令的路径,说明软件安装和环境变量设置成功。

 

创建/etc/mpd.conf文件:每个节点都要添加

内容为secretword=myword MPD_SECRETWORD=mywordmyword为自定义字符。

##root用户配置

# vi /etc/mpd.conf

或者通过echo命令

#echo "secretword=myword" >    /etc/mpd.conf


设置文件读取权限为只有自己能读写:

chmod 600 /etc/mpd.conf

##root用户在家目录创建内容相同的.mpd.conf##注意在mpd前有一点“.”。

# more  /home/test/.mpd.conf

secretword=myword

设置文件读取权限为只有自己能读写:

chmod 600 /etc/mpd.conf

 

创建主机名称文件mpd.hosts每个节点都要添加

文件内容如下:

HOSTNAME:ProcessNumber(主机名:数字(可以指定节点开启的进程数或CPU个数)例如dell:2)或者【如果该机器有两个CPU,就将它的名字加入两次】

##root用户配置,more /root/mpd.hosts

master:8

compute01:12

compute02:12

compute03:12

compute04:12

compute05:12

compute06:12

compute07:12

compute08:12

##root用户在家目录创建内容相同的/home/test/mpd.hosts

master:8

compute01:12

compute02:12

compute03:12

compute04:12

compute05:12

compute06:12

compute07:12

compute08:12

 

六、测试使用Intel MPI

MPI采用mpd服务来对进程进行管理,使用mpiexecmpirun运行mpi程序。


启动单机上的mpd服务

# mpd &

 

查看mpd服务

# mpdtrace  查看主机名

# mpdtrace -l  查看主机名和端口号

 

关闭mpd进程管理

#mpdallexit  杀死所有的mpd守护进程

#mpdexit 杀死指定节点mpd守护进程

 

mpd测试命令

mpdcheck用来检查mpi安装和运行时的故障和异常。 

mpdcheck -pc

mpdcheck -l

mpdringtest测试一个mpd回环的传输时间。 

 

编译mpi文件

#mpicc -o Hello hellow.c   //编译hellow.c文件,-o Hello 指定输出文件的名称为Hello)

#mpicc cpi.c           //默认输出文件名a.out   ###不加o参数,则默认输出文件名为a.out

icpi.c\ hellow.c\cpi.c这三个测试c语言可在mpich的下载文件中获得

在mpich-3.0.4/examples目录下,mpich下载地址

http://www.mpich.org/downloads/

 

测试mpi程序

#mpdrun -np 4 ./a.out   //-n-np启动的进程数

或者

mpirun -np 4 /.out  //-n或-np启动的进程数,n与np的参数意义一样

[root@mpitest ~]# mpdrun -np 4 ./a.out 

Hello world: rank 0 of 4 running on mpitest

Hello world: rank 1 of 4 running on mpitest

Hello world: rank 2 of 4 running on mpitest

Hello world: rank 3 of 4 running on mpitest

[root@mpitest ~]# mpirun -n 4 /root/a.out 

Hello world: rank 0 of 4 running on mpitest

Hello world: rank 1 of 4 running on mpitest

Hello world: rank 2 of 4 running on mpitest

Hello world: rank 3 of 4 running on mpitest

 

[root@mpitest ~]# mpirun -n 4 /root/cpi 

Process 2 of 4 is on mpitest

Process 0 of 4 is on mpitest

Process 1 of 4 is on mpitest

Process 3 of 4 is on mpitest

pi is approximately 3.1415926544231239, Error is 0.0000000008333307

wall clock time = 0.001607

[root@mpitest ~]# 

#mpiexec [-h or -help or --help]   //查看帮助文件

#mpdhelp  显示所有mpd命令帮助

 

启动集群上的mpd服务

# mpdboot -n process-num -f mpd.hosts  ###启动 process-num个进程,mpd.hosts是前面创建的文件/root/mpd.hosts。

#mpdroot -n <节点个数> -f mpd.hosts 这一命令将同时在mpd.hosts文件中指定的节点上启动mpd管理器

例如:mpdboot -n 4 -f /root/mpd.hosts

 

mpi默认是使用ssh来登陆集群里的其他机器,也可以使用rsh来登陆集群里的其他机器来启动mpd服务。

只要使用-rsh选项就可以指定用sshrsh

#mpdboot --rsh=rsh -n process-num -f hostfile

#mpdboot --rsh=ssh -n process-num -f hostfile

 

使用MPIEXEC|MPIRUN来执行多节点mpi任务:

#mpiexec -np 4 ./a.out    //a.out所有节点在相同的路径下,需都有a.out文件

mpiexec -machinefile filename -np 4 ./a.out  ##通过filename来指定计算节点参与计算。

[root@master ~]# mpirun -machinefile maname -np 10 /data/cpi

Process 1 of 10 is on compute02

Process 8 of 10 is on compute01

Process 2 of 10 is on compute03

Process 3 of 10 is on compute04

Process 9 of 10 is on compute02

Process 0 of 10 is on compute01

Process 5 of 10 is on compute06

Process 6 of 10 is on compute07

Process 7 of 10 is on compute08

Process 4 of 10 is on compute05

pi is approximately 3.1415926544231261, Error is 0.0000000008333330

wall clock time = 0.011969

 

 

单机测试 

./icpi

Enter the number of intervals: (0 quits) 1000000000 

pi is approximately 3.1415926535921401, Error is 0.0000000000023470 

wall clock time = 46.571311 

Enter the number of intervals: (0 quits) 10000 

pi is approximately 3.1415926544231341, Error is 0.0000000008333410 

wall clock time = 0.000542 

Enter the number of intervals: (0 quits) 0 

 

 

集群测试

mpdboot -n 2 -f mpd.hosts

mpiexec -n 2 /root/icpi

Enter the number of intervals: (0 quits) 1000000000

pi is approximately 3.1415926535899761, Error is 0.0000000000001830

wall clock time = 15.530082

Enter the number of intervals: (0 quits) 10000

pi is approximately 3.1415926544231323, Error is 0.0000000008333392

wall clock time = 0.006318

Enter the number of intervals: (0 quits) 0

mpdallexit

 

由上述测试的结果可以看出使用单机单进程运行,intervals设为1000000000,耗时46.571311秒,而用两台机器双进程则只有15.530082秒,明显快很多,并行运算还是

很有效果的。

不过,如果我们把intervals改为10000,单机运行只用了0.000542秒,而两台机器却花了0.006318秒,这是因为并行运算过程中,参与运算的机器需要通过网络传递一些消息,如果计算量不大的话,花在了这上面的时间影响会比较明显,因而反不如单机版的来得快

 


可参考文档见附件

Intel MPI 5.1.3安装配置详解

标签:mpi

原文地址:http://rabbitjian.blog.51cto.com/864581/1858682

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!