溫馨提示×

Ubuntu上openmpi編譯程序指南

小樊
123
2024-07-25 20:20:12
欄目: 智能運維

在Ubuntu操作系統上使用openmpi編譯程序可以按照以下步驟進行:

  1. 安裝openmpi:
sudo apt-get update
sudo apt-get install openmpi-bin openmpi-common libopenmpi-dev
  1. 編寫MPI程序:

創建一個簡單的MPI程序,比如hello.c:

#include <mpi.h>
#include <stdio.h>

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;
}
  1. 編譯MPI程序:

使用mpicc命令來編譯MPI程序:

mpicc hello.c -o hello
  1. 運行MPI程序:

使用mpirun命令來運行MPI程序:

mpirun -np 4 ./hello

這將在4個進程中執行hello程序,并輸出每個進程的輸出。

通過這些簡單的步驟,您就可以在Ubuntu上使用openmpi編譯和運行MPI程序。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女