阅读量:85
在Ubuntu操作系统上使用openmpi编译程序可以按照以下步骤进行:
- 安装openmpi:
sudo apt-get update
sudo apt-get install openmpi-bin openmpi-common libopenmpi-dev
- 编写MPI程序:
创建一个简单的MPI程序,比如hello.c:
#include
#include
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("Hello from process %d\n", rank);
MPI_Finalize();
return 0;
}
- 编译MPI程序:
使用mpicc命令来编译MPI程序:
mpicc hello.c -o hello
- 运行MPI程序:
使用mpirun命令来运行MPI程序:
mpirun -np 4 ./hello
这将在4个进程中执行hello程序,并输出每个进程的输出。
通过这些简单的步骤,您就可以在Ubuntu上使用openmpi编译和运行MPI程序。