HOWTO:MPICH

出自Computer Services

跳轉到: 導航, 搜尋

工作站上有安裝MPI工具, 以下是簡單的MPICH2使用範例。

步驟1到5只需要做一次。

1. 連上工作站

2. 產生SSH key pair

$ mkdir ~/.ssh/
$ cd ~/.ssh/
$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/netusers/GROUP/USERNAME/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): #直接按Enter
Enter same passphrase again: #直接按Enter
Your identification has been saved in /home/netusers/GROUP/USERNAME/.ssh/id_dsa.
Your public key has been saved in /home/netusers/GROUP/USERNAME/.ssh/id_dsa.pub.
The key fingerprint is:
91:98:8f:4e:6d:15:0b:5d:a7:f3:0b:cf:e8:9f:d8:db USERNAME@STATION
The key's randomart image is:
+--[ DSA 1024]----+
|        ..... .  |
|       o o.o o   |
|      o o o o    |
|       + o   o   |
|      o S   . .  |
|     o .     = . |
|      .     . +  |
|           . o o |
|            o.=.E|
+-----------------+

3. 設定SSH接受Public-key登入

$ cd ~/.ssh/
$ cp id_dsa.pub authorized_keys
$ chmod 600 authorized_keys

4. 建立MPI密語, 在家目錄裡建立一個 .mpd.conf 檔案, 內容為

secretword=SOME_SECRET_WORD

並將權限變更為600

$ chmod 600 .mpd.conf

5. 在家目錄裡建立一個節點清單, 叫它 mpi.hosts, 列出您想使用的節點, 例如

blade1:8
blade2:8
blade3:8
blade4:16
blade5:16

註: 後面的「:n」表示這個機臺有n個CPU core.

6. 啟動 MPD

$ mpdboot --totalnum=(節點數) --file=mpi.hosts

7. 檢驗各節點的MPD是否已啟動

$ mpdtrace -l
blade4_36464 (140.112.51.150)
blade5_42927 (140.112.51.151)
blade2_56936 (140.112.51.137)
blade3_42722 (140.112.51.149)
blade1_48063 (140.112.51.136)

注意: hostname後面的數字每次可能不一樣

8. 組建你的 MPI 程式

$ mpicc.mpich2 SOMEPROGRAM.c -o SOMEPROGRAM

9. 開始跑 MPI 程式

$ mpiexec.mpich2 -l -n (進程數) SOMEPROGRAM

您可以拿Wikipedia上MPI條目中的範例程式來測試, 會得到類似這樣的輸出:

$ mpiexec.mpich2 -l -n 5 ./a.out
0: 0: We have 5 processors
0: 0: Hello 1! Processor 1 reporting for duty
0: 
0: 0: Hello 2! Processor 2 reporting for duty
0: 
0: 0: Hello 3! Processor 3 reporting for duty
0: 
0: 0: Hello 4! Processor 4 reporting for duty
0: 


10. 結束後, 關閉MPD

$ mpdallexit
個人工具