1、 点击
这个
下载,我下载的时3.2.1
2、解压:
sudo tar -zxvf mpich-3.2.1.tar.gz
3、cd到文件夹下运行
./configure -prefix=
/home/mpi/mpich 配置目录可以自己选
4、然后分别分析make 和sudo make install
5、运行
sudo gedit ~/.zshrc 我的是,如果时bash终端的话,就讲zshrc改成bashrc
6、添加下面这三行:
export MPI_ROOT=/home/mpi/mpich
export PATH=$MPI_ROOT/bin:$PATH
export MANPATH=$MPI_ROOT/man:$MANPATH
然后就可以下个mpi程序测试下是否成功了。
1 #include <mpi.h>
2 #include <stdio.h>
3 int main(int argc, char**argv){
4 //openMPI的初始化函数
5 MPI_Init(&argc, &argv);
6 int world_size, wrank;
7 //获取容器中进程数
8 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
9 //获取当前进程标识
10 MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
11 printf("Hello world. I'm the process %d, we are %d process in total\n", wrank, world_size);
12 //openMPI的结束函数
13 MPI_Finalize();
14 return 0;
然后运行:
mpicxx test.cpp -o test
mpirun -n 4 ./test
mpicxx是编译c++代码,编译c代码是mpicc
mpirun是运行mpi程序-n 4表示创建4个进程