转自:http://www.cnblogs.com/hiuser/p/3764638.htmlb
参照:http://www.cnblogs.com/liyanwei/archive/2010/04/26/1721142.html
1. 下载MPICH源码mpich-3.1.tar.gz(从http://www.mpich.org/官网下载)
2. 略
3. 略
4. 解压mpich-3.1.tar.gz,生成目录mpich-3.1:tar –zxvf MPICH-3.1.tar.gz
5. 进入目录mpich-3.1;
6. 配置:./config –prefix=/home/mpi/mpich-3.1 (/home/<用户名>/mpich是配置安装目录)
7. 编译:make
8. 安装:make install
9. 打开~/.bash_profile文件;命令:vim ~/.bash_profile(对于Ubuntu修改~/.bashrc),在文件最后添加以下三行:
export MPI_ROOT=/home/<用户名>/mpich
export PATH=$MPI_ROOT/bin:$PATH
export MANPATH=$MPI_ROOT/man:$MANPATH
10. 测试环境变量设置;命令which mpicc 显示mpicc所在刚才安装的目录的bin目录下:
which mpicc
/home/<用户名>/mpich/bin/mpicc
which mpirun
/home/<用户名>/mpich/bin/mpirun
11. 测试MPI程序,在刚才解压的mpich-3.1目录下有个examples目录,在exapmle目录下cpi.c文件,此程序是并行计算pi值;
首先,编译cpi.c文件,生成cpi可执行文件(若目录已经有了cpi则此步骤可省略):
mpicc cpi.c –o cpi
然后,执行cpi:
mpirun -n <number> . /cpi //<number> 是要启动的进程数,例如8;
执行结果如下:
root@localhost exapmles# mpirun –n 8 ./cpi
Process 1 of 8 is on localhost
Process 3 of 8 is on localhost
Process 4 of 8 is on localhost
Process 5 of 8 is on localhost
Process 0 of 8 is on localhost
Process 2 of 8 is on localhost
Process 6 of 8 is on localhost
Process 7 of 8 is on localhost
Pi is approximately 3.1415926544231265,Error is 0.00000000008333334
Wall clock time =0.000161
localhost是主机名,8是启动了8个进程,1是本进程号是1等;
至此,完成安装。