[[PageOutline]] = Introduction = MPI ( Message Passing Interface) ,一個用於平行計算的平臺。[[BR]] [http://www-unix.mcs.anl.gov/mpi/mpich1/docs.html MPICH Documents][[BR]] [http://www.mpi-forum.org/ MPI Documents][[BR]] [https://computing.llnl.gov/tutorials/parallel_comp/ LLNL參考資料] = Classifying of parallel computers = * SISD(Single-Instruction Single-Data) 如普通的單核心 PC ,只有單一指令與資料,ex: a = 1 + 1。 * SIMD(Single-Instruction Multiple-Data) 同一組指令,多組資料,ex: a = b + 1, b 是一組陣列,則同一時間就可以計算完成。而不需要算完 b[1] + 1,再算 b[1] + 1…再算 b[n] + 1。 * MISD(ultiple-Instruction Single-Data) 多組指令,單一組資料,ex: a = (2 + 3) + (2 - 3) + (2 * 3) + (2 / 3),則四臺機器各執行 2 跟 3 的操作指令 「=」、「-」、「*」及「/」中的一種,用的資料是 2 跟 3。 * MIMD(Multiple-Instruction Multiple-Data) 多組指令,多組資料,ex: a = (b + c) + (d - e) + (f * g),如果有三臺機器可分別執行(b + c) 、 (d - e) 及 (f * g),則三個運算可同時進行。 = Design = 指令及資料量切割的越小越有助於平行運算,但切割過小將會使傳輸次數及傳輸量增大,而且每次傳輸所需要的時間遠大於每次的計算,因此在設計程式為了得最高效能,須考慮到計算量、計算進度、傳輸量及傳輸速度。 = Communication = * Point to point communication 主要用在 one to one ,特定指定機器與機器間的傳送,傳送與接收的次數要相同,同一筆資料可以分多次傳送,但是每次傳送皆需花費時間,要考慮網路速度及機器處理能力。 * Command * [wiki:mpich/MPI_Send MPI_Send] * [wiki:mpich/MPI_Recv MPI_Recv] * Demo * [wiki:mpich/point_to_point/demo1 demo1] * [wiki:mpich/point_to_point/demo2 demo2] * [wiki:mpich/point_to_point/demo3 demo3] * Note * tag 的用意在於區別同一個發送端發送多筆同一種類型的資料給同一個接收者。[[BR]] 以下圖為例, node 0 發送了兩個資料類型相同的 x 及 y ,而 node 0 則無法判別它收到的是來自 node 0 的 x 還是 y 。 [[Image(mpi-fig-1.png)]][[BR]][[BR]] 這時我們就需要使用到 tag1 及 tag2 來區別。[[BR]] [[Image(mpi-fig-2.png)]][[BR]] * Collective communication * Command * [wiki:mpich/MPI_Reduce MPI_Reduce] * MPI_Scatter、MPI_Gather、MPI_Allgather、、MPI_Allreduce、 MPI_Barrier * Demo * [wiki:mpich/collective_communication/demo1 demo1] = How to execute = * [wiki:MPICH2_Install Install MPICH2] * Start mpd: {{{ mpdboot -n 4 -f machine_file }}} -n how many mpds to start[[BR]] -f hostsfile[[BR]] * list all nodes {{{ mpdtrace [-l] }}} -l show full hostnames and listreing ports and ifhn[[BR]] {{{ node101 node103 node102 hd05 }}} * executing {{{ mpiexec -n 12 ./mpi/a.out }}} -n number of processes to start 執行時,每個 node 上必須有一份執行檔才不會出現以下錯誤 {{{ problem with execution of a.out on hd05: [Errno 2] No such file or directory }}} * causing all mpds to exit {{{ mpdallexit }}} = API = == Constants == * [wiki:mpich/constants#Cdatatypes Data types (C datatypes)] * [wiki:mpich/constants#Communicators Communicators] == MPI_Wtime == 取得系統時間: {{{ MPI_Init(); MPI_Comm_size (MPI_COMM_WORLD, &nproc); MPI_Comm_rank (MPI_COMM_WORLD, &myid); MPI_Barrier (MPI_COMM_WORLD); time1=MPI_Wtime() . . . time2=MPI_Wtime() – time1; printf (“myid, clock time= %f\t%f\n”, myid,time2); MPI_Finalize(); Return 0; }}} = DEMO_1 = {{{ #include #include int nproc, myid; main (argc, argv) int argc; char **argv; { MPI_Init(&argc, &argv); MPI_Comm_size (MPI_COMM_WORLD, &nproc); MPI_Comm_rank (MPI_COMM_WORLD, &myid); ……… MPI_Finalize(); return 0; }}} #include mpich 的 head file。[[BR]] nproc 此次運算中,參與的 cpu 的總數。[[BR]] myid 此次運算中,目前本身是第幾顆 cpu。[[BR]] MPI_Init(&argc, &argv) 初始化使用 mpi 的環境。[[BR]] MPI_Comm_size(MPI_COMM_WORLD, &nproc) 回傳此次運算中,參與的 cpu 總數。[[BR]] MPI_Comm_rank (MPI_COMM_WORLD, &myid) 回傳目前自己是第幾個 cpu。[[BR]] MPI_Finalize() 結束平行運算 = Bench mark = * https://wiki.rocksclusters.org/wiki/index.php/Intel_MPI_Benchmark * [http://www.spec.org/mpi2007/results/ Standard Performance Evaluation Corporation - SPEC MPI Results 2007]