[MPI学习笔记]mpi并行实现方法

首先介绍下rsh命令功能:

rsh


NAME
rsh - remote shell

SYNOPSIS
rsh [-Kdnx] [-l username] host [command]

DESCRIPTION
Rsh executes command on host.
Rsh copies its standard input to the remote command, the standard output of the remote command to its standard output, and the standard error of the remote command to its standard error. Interrupt, quit and terminate signals are propagated to the remote command; rsh normally terminates when the remote command does. The options are as follows:

-d The -d option turns on socket debugging (using setsockopt (2)) on
the TCP sockets used for communication with the remote host.

-l By default, the remote username is the same as the local username
The -l option allows the remote name to be specified.

-n The -n option redirects input from the special device /dev/null
(see the BUGS section of this manual page).

If no command is specified, you will be logged in on the remote host
using rlogin(1).

FILES
/etc/hosts

通过执行mpirun命令和do.sh脚本分析mpirun与rsh命令关系:
Script:do.sh

1 #! /bin/bash
2 cat hosts$1 | sed '/#/d' >idotemp
3 for i in `cat idotemp`
4 do
5 rsh $i $2
6 done
7 rm -f idotemp

其中hoststemp文件内容为:

data
node100
node101
node102
node104


执行编译命令

1 mpif77 -O2 -o 02 02_mpi.f

(1)执行rsh命令

1 rsh temp ./02

得到输出结果:
 

 Hello! My rank is   0.  My hostname is "data.gucas.ac.cn"
Hello! My rank is 0. My hostname is "node100.gucas.ac.cn"
Hello! My rank is 0. My hostname is "node101.gucas.ac.cn"
Hello! My rank is 0. My hostname is "node102.gucas.ac.cn"
Hello! My rank is 0. My hostname is "node104.gucas.ac.cn"

(2)或执行mpirun命令

1 mpirun -np 5 -machinefile hoststemp 02

得到输出结果:
 

 Hello! My rank is   2.  My hostname is "node101.gucas.ac.cn"
Hello! My rank is 3. My hostname is "node102.gucas.ac.cn"
Hello! My rank is 1. My hostname is "node100.gucas.ac.cn"
Hello! My rank is 4. My hostname is "node104.gucas.ac.cn"
Hello! My rank is 0. My hostname is "data.gucas.ac.cn"


通过对以上命令输出结果分析发现其中my rank不同,而my hostname相同。
(1)my hostname相同说明mpirun通过rsh在各个节点上并行执行命令,这点可以从mpirun脚本中得到验证

1 which mpirun
2 vi /opt/mpichintel/bin/mpirun

mpirun脚本中有一行:

RSHCOMMAND="/usr/bin/rsh"


(2)而my rank不同,说明mpirun相对于rsh还有另外一个功能:对进程rank赋值。

 

总结:

(1)mpi程序编译执行一般流程是:

1 mpif77 -O2 -o 02 02_mpi.f    

     ===> 编译mpi程序,将mpi.f头文件加载到程序中,形成可执行并行程序。

1 mpirun -np 5 -machinefile hoststemp 02     

    ===> 通过mpirun脚本建立并行环境,分配节点/进程rank,通过rsh/ssh

              在各个节点上加载程序并并行执行。根据指定不同进程rank号执行

              不同并行子任务。并通过rsh/ssh将结果输出到执行节点。

(2)重要概念:mpif77、mpif90、mpirun都是shell脚本文件。

 

参考资料:根据张怀老师讲课内容整理所得。

posted on 2012-03-11 21:36  Parallel Life  阅读(5335)  评论(0编辑  收藏  举报

导航

友荐云推荐