版权声明:欢迎大佬指正! https://blog.csdn.net/sinat_36215255/article/details/86084381
在Ubuntu下安装mpich
1、安装mpich
在装之前,请确保以下软件都已经安装
$ gcc --version
$ g++ --version
$ python --version
如果缺少相应的软件,先安装。
安装好以后,即可进入用以下命令安装mpich
$ sudo apt-get install mpich
等待安装完成后,测试安装结果
$ which mpicc
$ which mpiexec
到这里,单机下的已经安装完毕,如果想实现真正多机运行,可按后面的步骤继续配置。
2.安装时 ubuntu出现问题:
在Ubuntu中,有时候运用sudo apt-get install 安装软件时,会出现一下的情况
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
解决方案看如下博客
https://blog.csdn.net/u011596455/article/details/60322568)
3.测试安装
$ touch hello.c
键入以下内容到hello.c
#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int npes, myrank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &npes);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
printf("From process %d out of %d, Hello World!\n", myrank, npes);
MPI_Finalize();
}
编译测试一下:
扫描二维码关注公众号,回复:
5013588 查看本文章
$ mpicc -o hello hello.c
$ mpirun -np 2 ./hello
应该会输出两次Hello,中间可能要求输入密码,如不想输入密码,取消SSH的密码步骤
$ ssh-keygen -t dsa #中间提示输入密码,直接回车,会在生成文件~/.ssh/id_dsa.pub
$ cat id_dsa.pub >> authorized_keys
$ mpirun -np 2 hello #应该没有密码输入提示了