投影片 1

Similar documents
第7章-并行计算.ppt

Microsoft PowerPoint - Tongji_MPI编程初步

大綱介紹 MPI 標準介紹 MPI 的主要目標 Compiler & Run 平行程式 MPICH 程式基本架構 點對點通訊 函數介紹 集體通訊 函數介紹

PowerPoint 演示文稿

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

模板

消息传递并行编程环境MPI.doc

Department of Science and Engineering Computing School of Mathematics School Peking University October 9, 2007

Microsoft PowerPoint - KN002.ppt

PowerPoint 演示文稿

MPI实验.doc

CC213

C++ 程式設計

Trilinos 简介 Trilinos 简介 卢朓 Trilinos 简介 卢朓 Trilinos 简介 Trilinos 简介 Trilinos 的安装和使用 Trilinos 简介 Trilinos 简介 Trilinos 的安装和使用 Trilinos 简介 Trilinos Epetra

to AztecOO Department of Science and Engineering Computing School of Mathematics School Peking University October 9, 2007

PowerPoint 演示文稿

untitled

C/C++语言 - C/C++数据

Parallel Programming with MPI

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

Department of Science and Engineering Computing School of Mathematics School Peking University August 14, 2007

C 1

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

C/C++ 语言 - 循环

Linux Linux Linux

C6_ppt.PDF

第3章.doc

CC213

mpi

mpic_2002

mvc

Parallel Programming with MPI

mannal

Microsoft PowerPoint - ds-1.ppt [兼容模式]

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

Slide 1

untitled

Microsoft Word - FPKLSC_21.docx

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

, 即 使 是 在 昏 暗 的 灯 光 下, 她 仍 然 可 以 那 么 耀 眼 我 没 有 地 方 去, 你 会 带 着 我 么 杜 晗 像 是 在 嘲 笑 一 般, 嘴 角 的 一 抹 冷 笑 有 着 不 适 合 这 个 年 龄 的 冷 酷 和 无 情, 看 着 江 华 的 眼 神 毫 无 温

epub 33-8

untitled


Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

Microsoft PowerPoint - CH 04 Techniques of Circuit Analysis

Java

CC213

PowerPoint Presentation

提纲 1 2 OS Examples for 3

c_cpp

Microsoft PowerPoint - multicore curriculum of sspku.ppt

第11章 可调内核参数

3.1 num = 3 ch = 'C' 2

PowerPoint 簡報

<4D F736F F D20AC4FBDBDA4FBB67DA96CAABA2DA743A67EAFC5AAA95FA7B9BD5A5F2E646F63>

ex

团 学 要 闻 我 校 召 开 共 青 团 五 届 九 次 全 委 ( 扩 大 ) 会 议 3 月 17 日, 我 校 共 青 团 五 届 九 次 全 委 ( 扩 大 ) 会 议 在 行 政 办 公 楼 五 楼 会 议 室 举 行, 校 团 委 委 员 各 院 ( 系 ) 团 委 书 记 校 学 生

C

C/C++语言 - 分支结构

目录 第一章 MPI 简介 消息传递编程的相关概念 分布式内存 消息传输 进程 消息传递库 发送 / 接收 同步 / 异步 阻塞

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

untitled

ebook14-4

A Preliminary Implementation of Linux Kernel Virus and Process Hiding

Microsoft PowerPoint - VCAD.ppt []

untitled

在挑选合适的 SDK 的时候需要注意, 标准 windows 平台应用选择 FBX SDK VS2015,windows 应用商店和全平台通用的不用考虑 windows 全平台通用的应用是 windows10 新推出的功能, 可以打通 windows phone windows s

4.2 ================================================================================= WFMC Task Task 4 5

IP505SM_manual_cn.doc

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

第一章 概论

Microsoft Word - ACL chapter02-5ed.docx

了 波 涛 和 号 声 袁 读 者 很 容 易 就 进 入 广 州 城 的 水 上 旅 途 袁 进 入 一 座 野 水 上 名 城 冶 的 传 说 中 去 遥 于 是 袁 一 座 名 城 往 事 充 满 了 漂 流 感 袁 旋 律 自 水 上 而 来 袁 我 们 就 这 样 来 到 了 往 事 的

壹、摘 要



Microsoft Word - 实用案例.doc

投影片 1

Microsoft PowerPoint - CEM-07-Parallel.pptx

<4D F736F F D20482E323634B5F8B054BD73BD58A4A7A5ADA6E6A4C6ACE3A8732E646F63>

lan03_yen

PowerPoint 演示文稿

1 学习目标了解并掌握 MPI 的各种非阻塞通信形式及其作用, 并能运用 MPI 的非阻塞通信语句编写高级的并行程序 2 重点和难点非阻塞通信的语义特点, 如何运用非阻塞通信的特点来实现特定的功能和性能 3 学习方法所有的阻塞调用形式都有其相应的非阻塞调用形式, 此外非阻塞调用还有其特殊的接口形式


1 2 9

MANUAL CHARLS SMS INTERVIEWER MODE

Open topic Bellman-Ford算法与负环

Excel VBA Excel Visual Basic for Application

PowerPoint Presentation

Bus Hound 5

untitled

ebook35-21

致遠管理學院法規提案單

instructions.PDF

07-1.indd

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

FY.DOC

Chapter #

c pm

NOWOER.OM m/n m/=n m/n m%=n m%n m%=n m%n m/=n 4. enum string x1, x2, x3=10, x4, x5, x; 函数外部问 x 等于什么? 随机值 5. unsigned char *p1; unsigned long *p

Transcription:

平行運算簡介 / 實例操作企鵝也會的 MPICH 研究員 : 鄧偉華 wade@nchc.org.tw

什麼是平行計算 傳統 : 單一程序 單一 CPU

什麼是平行計算 ( 續 ) 平行計算 程序切割 多 CPUs

為什麼要平行計算 簡省時間 解決大型問題 即時性 使用更多來自網路上的資源 使用大量 便宜 PCs 取代超級電腦 記憶體不足

平行計算種類 Flynn's taxonomy 多處理器架構 單一資料 Single Data 多資料 Multiple Data 單一程序 Single Instruction SISD SIMD 多程序 Multiple Instruction MISD MIMD

Single Instruction, Single Data (SISD) 非平行計算 單一程序 單一資料 ex : a = 1 + 1 1 1 a = 1 + 1

Single Instruction, Multiple Data(SIMD) 平行計算單一程序多資料 ex : a = b + 1, a, b 是二組陣列, 則同一時間就可以計算完成 而不需要算完 a[0] = b[0] + 1, 再算 a[1] = b[1] + 1 再算 a[n] = b[n] + 1 b[0] 1 b[1] 1 b[n] 1 a = b + 1

Single Instruction, Multiple Data(MISD) 平行計算多程序單一資料 a = (2 + 3) + (2-3) + (2 * 3) + (2 / 3) 2 3 2 + 3 2-3 2 * 3 2 / 3 + a

Multiple Instruction, Multiple Data(MIMD) 平行計算多程序多資料 a = (b + c) + (d - e) + (f * g), a, b, c, d, e, f, g 為陣列如果有三臺機器可分別執行 (b + c) (d - e) 及 (f * g), 則三個運算可同時進行 b[1] c[1] d[1] e[1] f[1] g[1] b[n] c[n] d[n] e[n] f[n] g[n] b + c d - e + a f * g

如何執行 MPICH 平行程式 啟動 MPD mpdboot -n 4 -f machine_file -n how many mpds to start -f hostsfile 列出所有 nodes mpdtrace 執行 mpiexec -n 12./mpi/a.out 結束 MPD mpdallexit

MPICH 設計注意事項 MPICH 屬於 SIMD 架構 指令及資料量切割 優 : 有助於平行運算 缺 : 增加傳輸次數及傳輸量

如何使用載入 / 啟動 MPICH #include <stdio.h> #include <mpi.h> 啟動該程式在多個 CPU 上的平行計算工作 main (int argc, char **argv) { 得知參與平行計算的 CPU 個數 (nproc) MPI_Init(&argc, &argv); MPI_Comm_size (MPI_COMM_WORLD, &numprocs); MPI_Comm_rank (MPI_COMM_WORLD, &myid);...... 得知我是第幾個 CPU (myid) from 0 MPI_Finalize(); return 0; } 結束平行計算工作 12

HELLO MPICH 目標 : 每個 node 將自己的 id 印出, 並且將所有的參與活動的 node 總數也印出, 顯示出自己的主機名稱

HELLO MPICH #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(); } }

結果

Point to point communication node-00 node-01

Point to point communication node-01 node-00 node-02 node-03 node-04

Point to point communication node-01 node-00 node-02 node-03 node-04

MPI_Send MPI_Send ((void *)&data, icount, DATA_TYPE, idest, itag, MPI_COMM_WORLD) data 要送出去的資料起點, 可以是純量 (scalar) 或陣列 (array) 資料 icount 要送出去的資料數量, 當 icount 的值大於一時, data 必須是陣列 DATA_TYPE 要送出去的資料類別, MPI 內定的資料類別 idest 是收受資料的 CPU id itag 要送出去的資料標籤 MPI_COMM_WORLD 通信域

MPI_Recv MPI_Recv( void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status ) buf 要接收的資料起點, 可以是純量 (scalar) 或陣列 (array) 資料 icount 要接收的資料數量, 當 icount 的值大於一時, data 必須是陣列 DATA_TYPE 要接收的資料類別, MPI 內定的資料類別 source 是收受資料的 CPU id itag 要接收的資料標籤 MPI_COMM_WORLD 通信域

範例 目標 : 每個 node 將自己的 id 資訊送給下一個 node node-01 00 node-02 01 node-01 02

#include <mpi.h> #include <stdio.h> main(int argc,char **argv) { int n, myrank, numprocs; MPI_Status status; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myrank); /* node 0 will send the first message */ if(myrank == 0) { n = myrank; MPI_Send(&n, 1, MPI_INT, 1, 99, MPI_COMM_WORLD); printf("[ndde %d] %d >> [Node %d]\n\n", myrank, n, myrank+1); } /* node 1 to node n-2 will send message to the next node */ if(myrank>0 && myrank<numprocs-1) { MPI_Recv(&n, 1, MPI_INT, myrank-1, 99, MPI_COMM_WORLD, &status); printf("[node %d] << %d [Node %d]\n", myrank, n, status.mpi_source); n = myrank; MPI_Send(&n, 1, MPI_INT, myrank+1, 99, MPI_COMM_WORLD); printf("[ndde %d] %d >> [Node %d]\n\n", myrank, n, myrank+1); } /* the final node n-1 will not send any message but receive*/ if(myrank==numprocs-1) { MPI_Recv(&n, 1, MPI_INT, myrank-1, 99, MPI_COMM_WORLD, &status); printf("[node %d] << %d [Node %d]\n", myrank, n, status.mpi_source); } MPI_Finalize(); }

動手作 每個 node 將訊息傳送給 node 0, 由, node 0 統一印出 node-01 node-00 node-02 node-03 node-04

提示 main(int argc, char **argv){ /* Node 0 will do the following */ if(myrank == 0) { /* receive messages from other nodes */ MPI_Recv(); } /* other Nodes will do the following */ if(myrank!= 0) { /* send node's rank to Node 0 */ MPI_Send(message, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD); }

結果

再動手作 讓 node 0 可以接受來自任何 node 的訊息, 每個 node 將訊息標上不同 tag (0, 1, 2...) 後傳給 node 0 node-04 node-00 node-01

提示 MPI_ANY_SOURCE 接收來自任何 node 訊息 MPI_ANY_TAG 接收任何 tag

結果

Collective communication node-01 node-00 node-02 node-03 node-04

Collective communication node-01 node-00 + node-02 node-03 node-04

MPI_Reduce MPI_Reduce ( void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm ) sendbuf address of send buffer (choice) count number of elements in send buffer (integer) datatype data type of elements of send buffer (handle) op reduce operation (handle) root rank of root process (integer) comm communicator (handle)

計算 1 + 2 + 3 +... + 100 #include <stdio.h> #include <mpi.h> main (int argc, char **argv) { int rank, size, i; int myid, numprocs; int mytotal = 0; int Total = 0; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); for(i = 1; i <= 100; i++) { if((i % numprocs) == myid) { mytotal += i; } MPI_Reduce(&myTotal, &Total, 1, MPI_INT, MPI_SUM, 0,MPI_COMM_WORLD); } if(myid==0) { printf("total = %d\n", Total); } MPI_Finalize(); }

結果

動手作 計算 Fibonacci number 從第 1 項加至第 n 項總合 Fibonacci number f(n) = f(n - 1) + f(n - 2) f(0) = 1, f(1) = 1 1, 1, 2, 3, 5, 8,...

參考 http://www-unix.mcs.anl.gov/mpi/mpich1/docs http://www-unix.mcs.anl.gov/mpi/www/www3/ http://www.mpi-forum.org/ https://trac.nchc.org.tw/grid/wiki/mpich