close Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": /usr/lib/python2.7/dist-packages/libsvn/_core.so: failed to map segment from shared object: Cannot allocate memory). Look in the Trac log for more information.

Changes between Initial Version and Version 1 of mpich/2008-07-20_YM_MPI_Course


Ignore:
Timestamp:
Jul 20, 2008, 5:35:00 PM (16 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • mpich/2008-07-20_YM_MPI_Course

    v1 v1  
     1 * 使用你的帳號登入: ym**
     2{{{
     3login as: ym000
     4ym000@140.129.162.12's password: ******
     5ym000@bio001:~$ ssh-keygen -t rsa
     6}}}
     7 * 產生 SSH 認證金鑰
     8{{{
     9Generating public/private rsa key pair.
     10Enter file in which to save the key (/home/ym000/.ssh/id_rsa):
     11Created directory '/home/ym000/.ssh'.
     12Enter passphrase (empty for no passphrase):
     13Enter same passphrase again:
     14Your identification has been saved in /home/ym000/.ssh/id_rsa.
     15Your public key has been saved in /home/ym000/.ssh/id_rsa.pub.
     16The key fingerprint is:
     172a:6c:05:f8:24:38:db:79:b9:4f:0c:74:da:c5:16:05 ym000@bio001
     18}}}
     19 * 進行金鑰交換
     20{{{
     21ym000@bio001:~$ cp .ssh/id_rsa.pub .ssh/authorized_keys
     22}}}
     23   * [備註] '''因為是 DRBL 環境, 因此每一台都已經有 .ssh/authorized_keys''', 如果不是 DRBL 環境, 你必須要自己手動把 .ssh/id_rsa.pub 拷貝到每一台 Compute Node 的 .ssh/authorized_keys
     24{{{
     25ym000@bio001:~$ for ((i=2;i<=7;i++)); do scp .ssh/id_rsa.pub ym000@192.168.192.$i:.ssh/authorized_keys ; done
     26}}}
     27 * 設定 MPD 設定檔跟 MPI 的執行檔路徑
     28{{{
     29ym000@bio001:~$ echo "MPD_SECRETWORD=${user}$$" > ~/.mpd.conf
     30ym000@bio001:~$ chmod 600 .mpd.conf
     31ym000@bio001:~$ for ((i=2;i<=7;i++)); do echo "192.168.129.$i" >> mpd.hosts; done
     32ym000@bio001:~$ export PATH=$PATH:/opt/mpich2/bin
     33ym000@bio001:~$ which mpdboot
     34/opt/mpich2/bin/mpdboot
     35}}}
     36 * 設定 dsh (distributed shell)[http://packages.debian.org/stable/net/dsh *], 我們可以使用 dsh 指令逐台執行.
     37{{{
     38ym000@bio001:~$ mkdir -p .dsh/
     39ym000@bio001:~$ cp mpd.hosts .dsh/machines.list
     40ym000@bio001:~$ dsh -a hostname
     41bio001002
     42bio001003
     43The authenticity of host '192.168.129.4 (192.168.129.4)' can't be established.
     44RSA key fingerprint is f0:4b:6f:52:3c:0b:f4:8b:1c:a0:33:4a:e2:15:e0:5a.
     45Are you sure you want to continue connecting (yes/no)? yes
     46Warning: Permanently added '192.168.129.4' (RSA) to the list of known hosts.
     47bio001004
     48The authenticity of host '192.168.129.5 (192.168.129.5)' can't be established.
     49RSA key fingerprint is 09:9b:25:5e:9c:a8:9a:dd:35:ee:f0:54:6a:11:b7:90.
     50Are you sure you want to continue connecting (yes/no)? yes
     51Warning: Permanently added '192.168.129.5' (RSA) to the list of known hosts.
     52bio001005
     53The authenticity of host '192.168.129.6 (192.168.129.6)' can't be established.
     54RSA key fingerprint is 40:10:50:38:2c:f0:0b:f7:11:85:a3:41:d9:fb:ac:7d.
     55Are you sure you want to continue connecting (yes/no)? yes
     56Warning: Permanently added '192.168.129.6' (RSA) to the list of known hosts.
     57bio001006
     58The authenticity of host '192.168.129.7 (192.168.129.7)' can't be established.
     59RSA key fingerprint is 07:95:b7:f8:a5:9c:c7:21:84:d0:5b:f4:5f:db:0b:a6.
     60Are you sure you want to continue connecting (yes/no)? yes
     61Warning: Permanently added '192.168.129.7' (RSA) to the list of known hosts.
     62bio001007
     63ym000@bio001:~$ dsh -a hostname
     64bio001002
     65bio001003
     66bio001004
     67bio001005
     68bio001006
     69bio001007
     70}}}
     71 * 用使用者的身分執行 mpd
     72{{{
     73ym000@bio001:~$ mpdboot -n 7
     74}}}
     75 * 用 mpdtrace 檢查 mpd 執行狀態
     76{{{
     77ym000@bio001:~$ mpdtrace
     78bio001
     79bio001005
     80bio001004
     81bio001003
     82bio001002
     83bio001007
     84bio001006
     85}}}
     86 * 用 mpdringtest 做 mpd 訊息傳遞效能測試
     87{{{
     88ym000@bio001:~$ mpdringtest 1000
     89time for 1000 loops = 0.648007154465 seconds
     90}}}
     91 * 用 mpiexec 執行 cpi 範例程式
     92{{{
     93ym000@bio001:~$ mpiexec -n 3 /opt/mpich2/share/mpich2/examples/cpi
     94Process 0 of 1 is on bio001
     95pi is approximately 3.1415926544231341, Error is 0.0000000008333410
     96wall clock time = 0.000284
     97Process 0 of 1 is on bio001
     98pi is approximately 3.1415926544231341, Error is 0.0000000008333410
     99wall clock time = 0.000295
     100Process 0 of 1 is on bio001
     101pi is approximately 3.1415926544231341, Error is 0.0000000008333410
     102wall clock time = 0.000294
     103}}}
     104 * 貼上 test1.c
     105{{{
     106ym000@bio001:~$ cat << EOF > test1.c
     107> #include <stdio.h>
     108> #include <mpi.h>
     109> main (int argc, char **argv)
     110> {
     111>   int rank, size, len;
     112>   char name[MPI_MAX_PROCESSOR_NAME];
     113>   MPI_Init(&argc, &argv);
     114>   int myid, numprocs;
     115>
     116>   /* 取得 node 總數 */
     117>   MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
     118>   /* 取得本身 node id / rank */
     119>   MPI_Comm_rank(MPI_COMM_WORLD,&myid);
     120  MPI_Get_processor_name(name, &len);
     121>   /* 取得本身 host name */
     122>   MPI_Get_processor_name(name, &len);
     123>   printf("This is machine %d of %d name = %s\n", myid, numprocs, name);
     124>
     125>   MPI_Finalize();
     126> }
     127> EOF
     128}}}
     129 * 用 mpicc 編譯 test1.c
     130{{{
     131ym000@bio001:~$ mpicc -o test1 test1.c
     132}}}
     133 * 用 mpiexec 執行 test1 程式
     134{{{
     135ym000@bio001:~$ mpiexec -n 1 ./test1
     136This is machine 0 of 1 name = bio001
     137ym000@bio001:~$ mpiexec -n 12 ./test1
     138This is machine 0 of 12 name = bio001
     139This is machine 1 of 12 name = bio001004
     140This is machine 2 of 12 name = bio001005
     141This is machine 3 of 12 name = bio001003
     142This is machine 4 of 12 name = bio001002
     143This is machine 5 of 12 name = bio001007
     144This is machine 6 of 12 name = bio001006
     145This is machine 7 of 12 name = bio001
     146This is machine 8 of 12 name = bio001004
     147This is machine 11 of 12 name = bio001002
     148This is machine 9 of 12 name = bio001005
     149This is machine 10 of 12 name = bio001003
     150}}}
     151 * here is test1.c
     152{{{
     153#include <stdio.h>
     154#include <mpi.h>
     155main (int argc, char **argv)
     156{
     157  int rank, size, len;
     158  char name[MPI_MAX_PROCESSOR_NAME];
     159  MPI_Init(&argc, &argv);
     160  int myid, numprocs;
     161
     162  /* 取得 node 總數 */
     163  MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
     164  /* 取得本身 node id / rank */
     165  MPI_Comm_rank(MPI_COMM_WORLD,&myid);
     166  /* 取得本身 host name */
     167  MPI_Get_processor_name(name, &len);
     168  printf("This is machine %d of %d name = %s\n", myid, numprocs, name);
     169
     170  MPI_Finalize();
     171}
     172}}}
     173 * here is test2.c
     174{{{
     175#include <mpi.h>
     176#include <stdio.h>
     177main(int argc,char **argv) {
     178  int n, myrank, numprocs;
     179  MPI_Status status;
     180  MPI_Init(&argc,&argv);
     181  MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
     182  MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
     183
     184  /* node 0 will send the first message */
     185  if(myrank == 0) {
     186    n = myrank;
     187    MPI_Send(&n, 1, MPI_INT, 1, 99, MPI_COMM_WORLD);
     188    printf("[Ndde %d]「%d」 >> [Node %d]\n\n", myrank, n, myrank+1);
     189  }
     190
     191  /* node 1 to node n-2 will send message to the next node */
     192  if(myrank>0 && myrank<numprocs-1) {
     193    MPI_Recv(&n, 1, MPI_INT, myrank-1, 99, MPI_COMM_WORLD, &status);
     194    printf("[Node %d] << 「%d」[Node %d]\n", myrank, n, status.MPI_SOURCE);
     195    n = myrank; MPI_Send(&n, 1, MPI_INT, myrank+1, 99, MPI_COMM_WORLD);
     196    printf("[Ndde %d]「%d」 >> [Node %d]\n\n", myrank, n, myrank+1);
     197  }
     198
     199 /* the final node n-1 will not send any message but receive*/
     200  if(myrank==numprocs-1) {
     201    MPI_Recv(&n, 1, MPI_INT, myrank-1, 99, MPI_COMM_WORLD, &status);
     202    printf("[Node %d] << 「%d」[Node %d]\n", myrank, n, status.MPI_SOURCE);
     203    }
     204
     205  MPI_Finalize();
     206}
     207}}}
     208 * here is test3.c
     209{{{
     210/* Program:
     211 *   每個 node 將訊息傳送給 node 0,由,node 0 統一印出
     212 * History:
     213 *   2008-06-12 BETA
     214 *   2008-06-17 更改顯示方式,並增加註解
     215 */
     216
     217#include <stdio.h>
     218#include <mpi.h>
     219#include <string.h>
     220
     221main(int argc, char **argv)
     222{
     223  int myrank, i, numprocs;
     224  char message[20];
     225  MPI_Status status;
     226  MPI_Init(&argc, &argv);
     227  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
     228  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
     229
     230  /* Node 0 will do the following */
     231  if(myrank == 0)
     232  {
     233    /* receive messages from other nodes */
     234    for(i = 1; i < numprocs; i++)
     235    {
     236      MPI_Recv(message, 20, MPI_CHAR, i, 99, MPI_COMM_WORLD, &status);
     237      printf("[Node 0] << 「%s」[Node %d] \n", message, status.MPI_SOURCE);
     238    }
     239  }
     240
     241  /* other Nodes will do the following */
     242  if(myrank != 0)
     243  {
     244    /* send node's rank to Node 0 */
     245    sprintf(message, "[%d]", myrank);
     246    MPI_Send(message, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD);
     247    printf("[Node %d]「%s」 >> [Node 0]\n", myrank, message);
     248  }
     249  MPI_Finalize();
     250}
     251}}}
     252 * here is test4
     253{{{
     254/* Program:
     255 *   讓 node 0 可以接受來自任何 node 的訊息,每個 node 將訊息標上不同 tag 後傳給 node 0
     256 * History:
     257 *   2008-06-24 BETA
     258 */
     259
     260#include <stdio.h>
     261#include <mpi.h>
     262
     263main (int argc, char **argv)
     264{
     265  int numprocs, myrank, i=0, buf;
     266  MPI_Status status;
     267  MPI_Init(&argc, &argv);
     268  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
     269  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
     270
     271  /* 除了 Node 0 以外的所有 node 都要送 5 個訊息給 node 0 , 將 i 當成 tag 送出 */
     272  if (myrank > 0)
     273  {
     274    for(i = 0; i < 5; i++)
     275    {
     276      buf = myrank * 100 + i;
     277      MPI_Send(&buf, 1, MPI_INT, 0, i, MPI_COMM_WORLD);
     278    }
     279  }
     280  if (myrank == 0)
     281  {
     282    for (i = 0; i < 5*(numprocs-1); i++)
     283    {
     284
     285      /* MPI_ANY_SOURCE 接收來自任何 node , MPI_ANY_TAG 接收來自任何 tag */
     286      MPI_Recv(&buf, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
     287      printf("[Node %d][Tag %d] => %d\n", status.MPI_SOURCE, status.MPI_TAG, buf);
     288    }
     289  }
     290  MPI_Finalize();
     291}
     292}}}