1. System environment: ubuntu16.04.2
2. Preparations
In order to avoid errors during installation, first update apt-get, install the three compilers gcc/g++ and gfortran
sudo apt-get update
sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install gfortran
3. Download and install MPICH2
- Download address: http://www.mpich.org/downloads/
- unzip files:
tar zxvf mpich-3.2.tar.gz
- Go to the unzipped folder:
cd mpich-3.2
- Set the installation directory:
./configure -prefix=/home/username/mpich
Note: The installation path is filled in after the prefix. If it is the home folder, don’t forget to add your own user name. There is no auto-completion here. one time - Compile:
make
- Installation:
make install
(Compilation and installation can also be combined into one step, make && make install) - Configure the environment: Here is a supplement to the knowledge of configuring environment variables: http://blog.csdn.net/baidu_34045013/article/details/78237825
For convenience, we set environment variables for all users of this machine (for other needs, please refer to the above link) , open /etc/environment
sudo gedit /etc/environment
and add your own path to the end of PATH, be careful not to forget the colon ":", the added PATH is as follows
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin :/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/mpich/bin"
save and exit, enter in the terminalsource /etc/environment
and then enter $PATH to find that it has been updated, the environment variable configuration success - Test: terminal input
which mpicc
which mpiexec
If these two executable paths are displayed, the installation is successful
Fourth, run the test program
Enter the examples folder in the mpich source file directory, first compile the cpi.c file, and generate the cpi executable file (if cpi already exists in the directory, this step can be omitted)
mpicc cpi.c -o cpi
execute cpi
mpiexec ./cpi