1. Download the installation package from the official website , for example: mpich-4.0.3.tar.gz
2. Create an mpich folder in the ubuntu environment
mkdir mpich
3. Use xftp to upload the downloaded compressed package to mpich
4. Unzip the compressed package in the folder
tar -zxvf mpich-4.0.3.tar.gz
5. Go to the decompressed directory
cd mpich-4.0.3/
6. Execute ./configure, select the path, the following is my own installation path
./configure frefix==/home/liping/mpich
7. When executing make, "make: *** No targets specified and no makefile found. Stop." appears
Solution: Execute the following command
sudo apt-get install fort77
sudo apt-get install gfortran
Then execute ./configure again, there will be no error when executing make, and the compilation of make will take a long time
make
make install
8. Configure environment variables
#执行改命令
sudo gedit ~/.bashrc
#进入后配置如下环境变量
export MPI_ROOT=/home/liping/MPI/mpich-4.0.3/mpich-install
export PATH=$MPI_ROOT/bin:$PATH
export MANPATH=$MPI_ROOT/man:$MANPATH
9. Compile environment variables
source ~/.bashrc
Install under Windows
Go to the download page , download two files for installation, and then create a new project in Visual studio 2022, right click on the project and select properties
The first one is the include in the installed mpisdk, and the second is the lib in the mpisdk
Then enter a piece of code to test
#include<stdio.h>
#include<mpi.h>
int main(int argc, char* argv[])
{
int myid, numprocs, namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Get_processor_name(processor_name, &namelen);
if (myid == 0) printf("number of processes: %d\n", numprocs);
printf("%s: Hello world from process %d \n", processor_name, myid);
MPI_Finalize();
return 0;
}
Compile and generate a dedug file after compiling. After entering with the Win+r command, enter the debug directory of the project and enter mpiexec -n 10 project name.exe
E:\visualstudio\source\repos\MPI\x64\Debug>mpiexec -n 10 MPI.exe
result