MPI linux Ubuntu cluster 集群

在局域网内安装mpi,并进行并行计算。MPICH3。

下载源码:

wget http://www.mpich.org/static/downloads/3.3.1/mpich-3.3.1.tar.gz

tar -xzf mpich-3.3.1.tar.gz

cd mpich-3.3.1

mkdir build

cd build

../configure --disable-fortran

make 

sudo make install

 

修改主机名后需要重启。

sudo vim /etc/hostname

修改为 master 或 client0,client1等

sudo vim /etc/hosts

增加 192.*.*.* master

也就是增加master的IP地址。

或者增加client的IP地址, 注意master机器的hosts也要更新这些ip

sudo adduser mpiuser

 #设置密码 其余回车

sudo apt­-get install openssh-server

################给mpiuser 增加sudo权限

sudo chmod u+w /etc/sudoers

sudo -i

vim /etc/sudoers

增加一行 mpiuser ALL=(ALL:ALL) ALL

sudo chmod u-w /etc/sudoers

################给mpiuser 增加sudo权限

su - mpiuser 

#我们都在每个机器的mpiuser 用户中做实验,安装源码可以在主用户下,

mpi用ssh进行通信,为了ssh通信免密我们需要用以下步骤生成秘钥文件,并发送到对方服务器,当然其他的机器也要互相做同样的动作。

ssh-keygen -t rsa

 # 生成rsa秘钥

ssh-copy-id -i ~/.ssh/id_rsa.pub master 

# 发送秘钥给master 输入yes 和 master机器的密码

sudo apt-get install nfs-kernel-server -y 

# 安装网络文件服务器,因为mpi运行的程序必须是一致,而且需要快速更新。

mkdir cloud

sudo mount -t nfs master:/home/mpiuser/cloud ~/cloud

test1#####################################

mpirun -np 4 -hosts client,client1 ./cpi

Process 3 of 4 is on client1
Process 0 of 4 is on client
Process 1 of 4 is on client1
Process 2 of 4 is on client
pi is approximately 3.1415926544231243, Error is 0.0000000008333312
wall clock time = 0.001272

 

另外一个test

master 与 client 建立TCP链接 ,首先在master上run server程序。源码在

https://github.com/qiaosiyi/ssserver/blob/master/tcptestserver.c

编译之,

mpicc tcptestserver.c -o tcptestserver

tcptestclient ,同理。

 在master上运行:

################master###############################

$ mpirun -np 1 ./tcptestserver

$ portname: tag#0$description#master$port#36221$ifname#192.168.187.160$

################master###############################

再在client上运行:

################client###############################

$ mpirun -np 1 ./tcptestclient 'tag#0$description#master$port#36221$ifname#192.168.187.160$'

$ Trying connect to tag#0$description#master$port#36221$ifname#192.168.187.160$

################client###############################

 在master上运行:

################master###############################

$ client connected

$ msg: 42

################master###############################

 =====

qsy

31 Jul 2019

 

 

posted @ 2019-07-31 10:07  熊猫滚滚  阅读(554)  评论(0编辑  收藏  举报