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 表示用兩個線程執行程序