歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 單機Ubuntu下MPICH的安裝與使用

單機Ubuntu下MPICH的安裝與使用

日期:2017/2/28 16:42:33   编辑:Linux教程

第一步 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 #應該沒有密碼輸入提示了

Copyright © Linux教程網 All Rights Reserved