jingjihui 发表于 2019-2-18 07:26:51

linux安装mpich

  为了做课设,不得不安装个mpich,找了好久方法。下面简单介绍下安装方法


[*]  yum安装,这是比较简单的安装方式
注意:先要配置好yum的网络源安装epel-release扩展源,我试了下本地的貌似没安装成功

# yum -y install mpich-3.2-devel.x86_64 mpich-3.2-devel.x86_64 mpich-3.2-doc.noarch
安装好之后是找不到命令的,需要手动配置环境变量
# find / -name "mpicc"
/usr/lib64/mpich-3.2/bin/mpicc
先搜索一下安装路径
设置环境变量:
在 /etc/profile添加一下内容:
PATH=$PATH://usr/lib64/mpich-3.2/bin/
刷新一下:
source /etc/profile
命令就可直接使用了
新建一个文件test.c
# cat test.c
#include
#include
#include
int main(int argc,char* argv[])
{
int myid, numprocs;
int namelen;
char processor_name;
MPI_Init(&argc,&argv);/* 初始化并行环境 */
MPI_Comm_rank(MPI_COMM_WORLD,&myid);/* 当前进程的ID号 */
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);/* 进程的总數 */
MPI_Get_processor_name(processor_name,&namelen);/* 当前处理器的名称 */
fprintf(stderr,"Hello World! Process %d of %d on %s\n",
myid, numprocs, processor_name);
MPI_Finalize();/* 结束并行环境 */
return 0;
}
# mpicc -o hello test.c
# mpirun -np 4 ./hello
Fatal error in MPI_Init: Other MPI error, error stack:
MPIR_Init_thread(474)..............:
MPID_Init(190).....................: channel initialization failed
MPIDI_CH3_Init(89).................:
MPID_nem_init(320).................:
MPID_nem_tcp_init(173).............:
MPID_nem_tcp_get_business_card(420):
MPID_nem_tcp_init(379).............: gethostbyname failed, c1 (errno 1)
但是这里运行还是会报错,原因在于,没有配置好域名解析:
需要配置域名解析
在/etsc/hosts中与/etc/hostname中的名字需要一致,贴出我的配置
# cat /etc/hosts
127.0.0.1   host
::1         localhost
# cat /etc/hostname
host
可以通过ssh 连接host   如果连接成功说明配置成功
接下来就可运行了
# mpirun -np 4 ./hello
Hello World! Process 0 of 4 on host
Hello World! Process 2 of 4 on host
Hello World! Process 1 of 4 on host
Hello World! Process 3 of 4 on host

2. 源码安装mpich

# wget http://www.mpich.org/static/downloads/3.2/mpich-3.2.tar.gz
--2018-05-28 18:06:45--http://www.mpich.org/static/downloads/3.2/mpich-3.2.tar.gz
正在解析主机 www.mpich.org (www.mpich.org)... 140.221.6.71
正在连接 www.mpich.org (www.mpich.org)|140.221.6.71|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:11862150 (11M)
正在保存至: “mpich-3.2.tar.gz”
100%[=====================================================>] 11,862,150   213KB/s 用时 54s   
2018-05-28 18:07:40 (215 KB/s) - 已保存 “mpich-3.2.tar.gz” )
[# tar zxf mpich-3.2.tar.gz
# ls
anaconda-ks.cfginitial-setup-ks.cfgmpich-3.2mpich-3.2.tar.gz
# cd mpich-3.2/
# ls
aclocal.m4configure   doc          Makefile.in       mpi.def      src
autogen.shconfigure.acexamples   man               README         subsys_include.m4
CHANGES   contrib       maint      mpich.def         README.envvartest
confdb      COPYRIGHT   Makefile.ammpich-doxygen.inRELEASE_NOTESwww
编译
# ./configure --prefix=/usr/local/mpich
………………..
config.status: executing default-4 commands
Configuration completed.   //中间一大串,看见这个就成功了
安装:
注意:中间如果报错,可能是缺少gcc、build-essential依赖,yum直接安装就行了
# make && make install
  安装成功后同样找不到命令,还是需要配置环境变量

# ls /usr/local/mpich/bin/*    //这是之前指定的安装目录
/usr/local/mpich/bin/hydra_nameserver/usr/local/mpich/bin/mpiexec.hydra
/usr/local/mpich/bin/hydra_persist   /usr/local/mpich/bin/mpif77
/usr/local/mpich/bin/hydra_pmi_proxy   /usr/local/mpich/bin/mpif90
/usr/local/mpich/bin/mpic++            /usr/local/mpich/bin/mpifort
/usr/local/mpich/bin/mpicc             /usr/local/mpich/bin/mpirun
/usr/local/mpich/bin/mpichversion      /usr/local/mpich/bin/mpivars
/usr/local/mpich/bin/mpicxx            /usr/local/mpich/bin/parkill
/usr/local/mpich/bin/mpiexec
  添加环境和之前一样

# tail -1 /etc/profile
PATH=$PATH:/usr/local/mpich/bin/
# source /etc/profile
  这会儿就能看到mpicc的命令了。。。成功了
  测试下:(还是利用上面那个例子)

# mpicc -o test test.c
# mpirun -np 4 ./test
Fatal error in MPI_Init: Other MPI error, error stack:
MPIR_Init_thread(474)..............:
MPID_Init(190).....................: channel initialization failed
MPIDI_CH3_Init(89).................:
MPID_nem_init(320).................:
MPID_nem_tcp_init(173).............:
MPID_nem_tcp_get_business_card(420):
MPID_nem_tcp_init(379).............: gethostbyname failed, c1 (errno 1)
  同样报错…….
但是解决方法和上面那个完全一样,都是host名字设置不一样造成的



页: [1]
查看完整版本: linux安装mpich