install on linux
https://sites.google.com/site/rangsiman1993/comp-env/program-install/install-openmpi
brief: download and build
https://edu.itp.phys.ethz.ch/hs12/programming_techniques/openmpi.pdf
The following instructions will help you installing OpenMPI on your machine. It takes about 5-10min.
Create a temporary directory for compiling OpenMPI. You can do this in a terminal by typing
mkdir $HOME/built/srcDownload openmpi-4.1.5.tar.bz2 from http://www.open-mpi.org
Move the openmpi-4.1.5.tar.bz2 to the directory just created:
mv $HOME/Downloads/openmpi-4.1.5.tar.bz2 $HOME/built/src/Change to the directory and extract the package using
cd $HOME/built/src
tar -jxf openmpi-4.1.5.tar.bz2
如果是.tar.gz的话
tar -zxvf openmpi-4.1.5.tar.gzGo into the source directory
cd openmpi-4.1.5Configure, compile and install by executing the following commands
./configure –prefix=$HOME/local/openmpi-4.1.5
make all -j && make install
This will install OpenMPI in your home directory in the $HOME/local/openmpi-4.1.5/Remove the temporary directories:
rm $HOME/built/src/openmpi-4.1.5.tar.bz2
rm -r $HOME/built/src/openmpi-4.1.5To use MPI you will have to adapt your PATH and LD_LIBRARY_PATH environment variable:
echo “export PATH=$PATH:$HOME/local/openmpi-4.1.5/bin” >> $HOME/.bashrc
echo “export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/local/openmpi-4.1.5/lib” \$HOME/.bashrc
This appends the two lines to your .bashrc file which is executed when starting a terminal session.
或者vim ~/.bashrc然后添加
export PATH=$PATH:$HOME/local/openmpi-4.1.5/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/local/openmpi-4.1.5/lib
To compile your MPI C++ programs you have to use
mpicxx
with the same arguments as you would use forg++
. To run a program PRG with N MPI processes, you would then use mpirun -np N PRG.To uninstall OpenMPI just delete the folder opt/openmpi in your home directory and remove the last two lines from the .bashrc file in your home directory.
You can find more information on http://www.open-mpi.org