Linux【8】-软件管理-9-软件安装8-在centos上安装MPI
二、安装
2.1 MPI(centos7.2)
查看MPI可安装的版本,我是直接全部安装
yum list mpich*
安装:
yum install -y mpich*
可以查看到设置的路径
which mpicc
如果找不到,就需要添加环境变量
添加环境变量
vim ~/.bashrc
#在文件中添加,具体路径要根据系统和具体环境,以下是我的情况:
export PATH=$PATH:/usr/lib64/mpich/bin/
然后使其生效
source .bashrc
yum 默认mpich安装路径是在/usr/lib64。如果在不到,就需要find / -name “mpicc” 查找安装路径
2.2 MPICH安装
1.获得MPI源码;
mpich-3.1.tar.gz(从http://www.mpich.org/官网下载)
2.在目录/home下创建目录mpi/mpich-3.1/src
3.将mpich-3.1.tar.gz拷贝到
/home/mpi/mpich-3.1/src下;
4.解压mpich-3.1.tar.gz,生成目录mpich-3.1;命令
tar –zxvf MPICH-3.1.tar.gz
5.进入目录mpich-3.1;
6.配置:
./configure –prefix=/home/mpi/mpich-3.1 (/home/mpi/mpich-3.1是配置安装目录)
7.编译:
make
8.安装:
make install
9.打开~/.bash_profile文件;命令:vim ~/.bash_profile
在文件最后添加以下三行:
export MPI_ROOT=/home/mpi/mpich-3.1
export PATH=$MPI_ROOT/bin:$PATH
export MANPATH=$MPI_ROOT/man:$MANPATH
10.测试环境变量设置;命令which mpicc 显示mpicc所在刚才安装的目录的bin目录下;例如:
[root@localhost mpich-3.1]# which mpicc
/home/mpi/mpich-3.1/bin/mpicc
[root@localhost mpich-3.1]# which mpirun
/home/mpi/mpich-3.1/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等;
到此完成安装;
二、测试
mpi代码示例(hello.c):
#include <mpi.h>
#include <stdio.h>
#include <math.h>
int main(int argc,char** argv)
{
int myid,numproces;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Comm_size(MPI_COMM_WORLD,&numproces);
MPI_Get_processor_name(processor_name,&namelen);
fprintf(stdout,"hello world! Process %d of %d on %s\n",
myid,numproces,processor_name);
MPI_Finalize();
return 0;
}
编译:
mpicc -o hello hello.c
运行:
mpirun -np 4 ./hello
输出:
hello world! Process 0 of 4 on node25
hello world! Process 1 of 4 on node25
hello world! Process 3 of 4 on node25
hello world! Process 2 of 4 on node25
三、报错
mpi报错
/data/software/amber/amber18//bin/pmemd.MPI: error while loading shared libraries: libmpifort.so.12: cannot open shared object file: No such file or directory
/data/software/amber/amber18//bin/pmemd.MPI: error while loading shared libraries: libmpifort.so.12: cannot open shared object file: No such file or directory
/data/software/amber/amber18//bin/pmemd.MPI: error while loading shared libraries: libmpifort.so.12: cannot open shared objec
天呐,直接重新安装就好。。
参考资料
这里是一个广告位,,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn