MPICH的安装和测试

转自: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等;


至此,完成安装。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值