wiki:YM_Course_2009/Lab8

Version 8 (modified by jazz, 15 years ago) (diff)

--

實作八: MPICH 實作練習

實作八 - 課程投影片

◢ <實作七> | <回課程大綱> ▲ | <實作九> ◣

  • 使用你的帳號登入: ym
    login as: ym24
    ym24@bio.classcloud.org's password: ******
    ym24@bio001:~$ ssh-keygen -t rsa
    
  • 產生 SSH 認證金鑰
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/ym24/.ssh/id_rsa):  <<< 請按 Enter
    Created directory '/home/ym24/.ssh'.
    Enter passphrase (empty for no passphrase):            <<< 請按 Enter
    Enter same passphrase again:                     <<< 請按 Enter
    Your identification has been saved in /home/ym24/.ssh/id_rsa.
    Your public key has been saved in /home/ym24/.ssh/id_rsa.pub.
    The key fingerprint is:
    2a:6c:05:f8:24:38:db:79:b9:4f:0c:74:da:c5:16:05 ym24@bio001
    
  • 進行金鑰交換
    ym24@bio001:~$ cp .ssh/id_rsa.pub .ssh/authorized_keys
    
  • 設定 MPD 設定檔跟 MPI 的執行檔路徑
    ym24@bio001:~$ echo "MPD_SECRETWORD=${user}$$" > ~/.mpd.conf
    ym24@bio001:~$ chmod 600 .mpd.conf
    ym24@bio001:~$ for ((i=2;i<=12;i++)); do echo "192.168.129.$i" >> mpd.hosts; done
    ym24@bio001:~$ export PATH=$PATH:/opt/mpich2/bin
    ym24@bio001:~$ which mpdboot
    /opt/mpich2/bin/mpdboot
    
  • 設定 dsh (distributed shell)*, 我們可以使用 dsh 指令逐台執行.
    ym24@bio001:~$ mkdir -p .dsh/
    ym24@bio001:~$ cp mpd.hosts .dsh/machines.list
    ym24@bio001:~$ dsh -a hostname
    
  • 用使用者的身分執行 mpd
    ym24@bio001:~$ mpdboot -n 7
    
  • 用 mpdtrace 檢查 mpd 執行狀態
    ym24@bio001:~$ mpdtrace 
    bio002
    bio006
    bio012
    bio011
    bio005
    bio004
    bio003
    bio010
    bio009
    bio008
    bio007
    
  • 用 mpdringtest 做 mpd 訊息傳遞效能測試
    ym24@bio002:~$ mpdringtest 1000
    time for 1000 loops = 1.07995414734 seconds
    
  • 用 mpiexec 執行 cpi 範例程式
    ym24@bio001:~$ mpiexec -n 3 /opt/mpich2/share/mpich2/examples/cpi
    Process 0 of 1 is on bio001
    pi is approximately 3.1415926544231341, Error is 0.0000000008333410
    wall clock time = 0.000295
    Process 0 of 1 is on bio001
    pi is approximately 3.1415926544231341, Error is 0.0000000008333410
    wall clock time = 0.000287
    Process 0 of 1 is on bio001
    pi is approximately 3.1415926544231341, Error is 0.0000000008333410
    wall clock time = 0.000277
    
  • 貼上 test1.c
    ym24@bio001:~$ cat << EOF > test1.c
    #include <stdio.h>
    #include <mpi.h>
    main (int argc, char **argv)
    {
      int rank, size, len;
      char name[MPI_MAX_PROCESSOR_NAME];
      MPI_Init(&argc, &argv);
      int myid, numprocs;
    
      /* 取得 node 總數 */
      MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
      /* 取得本身 node id / rank */
      MPI_Comm_rank(MPI_COMM_WORLD,&myid);
      /* 取得本身 host name */
      MPI_Get_processor_name(name, &len);
      printf("This is machine %d of %d name = %s\n", myid, numprocs, name);
    
      MPI_Finalize();
    }
    EOF