安装与测试
系统:Ubuntu14.04 LTS
安装OpenMPI
Ctrl+Alt+T 打开终端,输入命令直接安装
:~$ sudo apt-get install libopenmpi-dev openmpi-bin openmpi-doc
测试是否安装成功
代码
//HelloMpi.c
#include <stdio.h>
#include <mpi.h>
int main(int argc, char *argv[])
{
int myrank, nprocs;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
printf("hello from processror %d of %d\n", myrank, nprocs);
MPI_Finalize();
return 0;
}
编译
:~/Mine/code/testMPI$ mpicc HelloMpi.c -o HelloMpi
执行
:mpiexec -n 4 HelloMpi
输出结果
hello from processror 2 of 4
hello from processror 3 of 4
hello from processror 0 of 4