MPI學習筆記——MPI環境配置

第一步 Ubuntu下安裝SSH服務器和客戶端
打開新立得,在全部裏鍵入openssh,選擇openssh-client和openssh-server標記安裝應用,或者直接執行
$ sudo apt-get install openssh-client openssh-server


第二步 安裝MPICH
打開新立得,在全部裏鍵入mpi,選擇mpi-bin、mpi-doc、libmpich1.0-dev標記安裝應用 


$ sudo apt-get install mpi-bin mpi-doc libmpich1.0-dev


第三步 測試安裝
$ touch hello.c
鍵入以下內容到hello.c
1 #include <mpi.h> 
 2 #include <stdio.h>
 3 int main(int argc, char *argv[]) 
 4 { 
 5     int npes, myrank; 
 6     MPI_Init(&argc, &argv); 
 7     MPI_Comm_size(MPI_COMM_WORLD, &npes); 
 8     MPI_Comm_rank(MPI_COMM_WORLD, &myrank); 
 9     printf("From process %d out of %d, Hello World!\n", myrank, npes); 
10    MPI_Finalize();
11 }
$ mpicc -o hello hello.c
$ mpirun -np 2 hello #應該會輸出兩次Hello,中間可能要求輸入密碼,如不想輸入密碼,看第四步


第四步 取消SSH的密碼步驟
$ ssh-keygen -t dsa #中間提示輸入密碼,直接回車,會在生成文件~/.ssh/id_dsa.pub
$ cat id_dsa.pub >> authorized_keys
$ mpirun -np 2 hello #應該沒有密碼輸入提示了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章