1、安装包下载
2、OpenMPI手动编译配置安装
- 解压
~/installPackage$ tar -zxvf openmpi-4.0.4.tar.gz
- 编译安装
$ cd /home/qulei/installPackage/openmpi-4.0.4/
$ ./configure --prefix=$HOME/opt/openMpi
$ make all
$ sudo make install
- 配置环境变量
$ cd
$ vim .bashrc
export PATH=$PATH:/home/qulei/opt/openMpi/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/qulei/opt/openMpi/lib
4.查看版本
$ mpiexec --version
mpiexec (OpenRTE) 2.1.1
Report bugs to http://www.open-mpi.org/community/help/
$ mpirun --version
mpirun (Open MPI) 2.1.1
Report bugs to http://www.open-mpi.org/community/help/
3、测试
建立一个hello.c文件进行环境测试。具体测试可以参考:MPI Hello World
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// Print off a hello world message
printf("Hello world from processor %s, rank %d out of %d processors\n",
processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}
用 mpicc hello.c -o test编译文件:
code$ mpicc hello.c -o hello
执行:
code$ mpirun -np 2 ./hello
Hello world from processor qulei-System-Product-Name, rank 0 out of 2 processors
Hello world from processor qulei-System-Product-Name, rank 1 out of 2 processors
以上 -np 2 表示用两个线程执行程序