进到一个树莓派节点,在~/目录下,一行一行执行:
mkdir openmpi
cd src/ && tar -zxvf openmpi-2.1.1.tar.gz
cd openmpi-2.1.1/ && ./configure --prefix=/home/pi/openmpi
make -j4
make install
在~/.bashrc文件中添加环境变量:
vi ~/.bashrc
MPI_HOME=/home/pi/openmpi
export PATH=${MPI_HOME}/bin:$PATH
export LD_LIBRARY_PATH=${MPI_HOME}/lib:$LD_LIBRARY_PATH
export MANPATH=${MPI_HOME}/share/man:$MANPATH
使生效
source ~/.bashrc
因为之前尝试使用脚本写,可能由于编码格式不匹配导致/etc/profile文件中通过脚本写进来的这4行,树莓派系统无法识别,所以就注释掉:(如果有的话,)
sudo vi /etc/profile
加注释变成这样
#MPI_HOME=/home/pi/openmpi
#export PATH=${MPI_HOME}/bin:$PATH
#export LD_LIBRARY_PATH=${MPI_HOME}/lib:$LD_LIBRARY_PATH
#export MANPATH=${MPI_HOME}/share/man:$MANPATH
使生效:
source /etc/profile
测试是否安装成功:
cd ~/src/openmpi-2.1.1/examples/
make
mpirun -np 4 hello_c
如果出现如下,就是成功了:
Hello, world, I am 1 of 4, (Open MPI v2.1.1, package: Open MPI pi@pi005 Distribution, ident: 2.1.1, repo rev: v2.1.0-100-ga2fdb5b, May 10, 2017, 116)
Hello, world, I am 2 of 4, (Open MPI v2.1.1, package: Open MPI pi@pi005 Distribution, ident: 2.1.1, repo rev: v2.1.0-100-ga2fdb5b, May 10, 2017, 116)
Hello, world, I am 3 of 4, (Open MPI v2.1.1, package: Open MPI pi@pi005 Distribution, ident: 2.1.1, repo rev: v2.1.0-100-ga2fdb5b, May 10, 2017, 116)
Hello, world, I am 0 of 4, (Open MPI v2.1.1, package: Open MPI pi@pi005 Distribution, ident: 2.1.1, repo rev: v2.1.0-100-ga2fdb5b, May 10, 2017, 116)