第7章-并行计算.ppt

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

C 1

并行算法实践

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

C++ 程式設計

FY.DOC

mvc

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

06?????k?g


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

CC213

untitled

untitled

PowerPoint Presentation

《嵌入式系统设计》教学大纲

untitled

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

第3章.doc


ebook14-4

2 2 3 DLight CPU I/O DLight Oracle Solaris (DTrace) C/C++ Solaris DLight DTrace DLight DLight DLight C C++ Fortran CPU I/O DLight AM

第一章 概论

C/C++ 语言 - 循环

科学计算的语言-FORTRAN95

Microsoft PowerPoint - os_4.ppt


<4D F736F F D B0EABB79A4E5B8D5C344BBBCB065AAA9>


康體藝術

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

Microsoft PowerPoint - multicore curriculum of sspku.ppt

投影片 1

Parallel Programming with MPI

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

PowerPoint 演示文稿

Microsoft PowerPoint - Tongji_MPI编程初步

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

Microsoft PowerPoint - VCAD.ppt []

3.1 num = 3 ch = 'C' 2

邻居啊 第二天 对门却悄无声息了 莫非昨夜的吵闹 仅是个幻觉 夜幕拉下时 寒风又吱溜溜地叫个不停 老婆 睡下后 我这只夜猫子 继续兴致勃勃地跟着福尔 摩斯去探案 白天的喧嚣退去了 周围格外安静 正 是读书的好时候 突然 响起了钟摆声 哒 哒 哒 节奏匀称 不疾不徐 声响却愈来愈大 格外突兀 了 原来

<4D F736F F D BAC520CAD7B6BCCAA6B7B6B4F3D1A C4EAD7A8D2B5BCBCCAF5D6B0CEF1C6C0C6B8B9A4D7F7D2E2BCFB2E646F63>

其 他 方 面 也 可 以 采 用 同 样 的 方 式, 这 样 又 可 以 锻 炼 除 语 文 方 面 的 其 他 能 力 了 而 英 语 方 面, 我 认 为 配 合 英 语 专 业 举 办 英 语 演 讲 比 赛 就 很 不 错 这 样 开 展 一 系 列 的 创 新 活 动, 锻 炼 多 方

第 六 条 办 法 第 五 条 ( 三 ) 协 会 考 评, 考 评 指 考 核 评 价 第 七 条 办 法 第 六 条 职 业 操 守 包 括 的 内 容 : 个 人 诚 信 不 做 假 账 不 偷 漏 税 不 贪 污 盗 窃 等 第 八 条 企 业 财 务 管 理 人 才 评 价 实 行 五 星

他 随 身 带 有 二 三 十 张 古 方, 白 天 卖 药, 夜 晚 将 药 材 精 细 研 末, 按 方 配 制 对 于 病 人 服 药 后 反 应, 特 别 留 心 发 现 问 题, 就 近 向 老 医 生 老 药 贩 虚 心 求 教, 千 方 百 提 高 药 效 同 时 对 于 春 夏 秋

6寸PDF生成工具

Microsoft Word - 送報伕2.doc

申论写作套路万能模板

Microsoft Word - 三方协议书与接收函的相关说明学生版.doc

untitled

PowerPoint 演示文稿

壹:教育文化公益慈善機關或團體免納所得稅適用標準

CC213

<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344>

Oracle Solaris Studio makefile C C++ Fortran IDE Solaris Linux C/C++/Fortran IDE "Project Properties" IDE makefile 1.

PowerPoint Presentation

達文西密碼

ebook

Microsoft PowerPoint - plan06.ppt

S 可编程控制器

壹、摘 要

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

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

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

PowerPoint 演示文稿

C语言的应用.PDF

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

chap07.key

C

台 中 市 北 屯 區 東 山 里 橫 坑 9 林 志 明 巷 89-5 菜 豆 菜 大 漿 果 菜 豆 菜 大 漿 果 小 漿 果 核 果 柑 桔 無 陳 錦 生 新 竹 市 香 山 區

菩提道次第廣論

繁 華 國 小 101 學 年 母 親 節 感 恩 惜 福 - 跳 蚤 市 場 暨 科 學 闖 關 遊 戲 親 子 活 動 實 施 計 畫 一 依 據 : 本 校 101 學 年 度 校 務 計 畫 及 行 事 曆 二 目 的 : 1. 培 養 學 生 感 恩 惜 物 知 福 惜 福 的 節 儉 觀

Transcription:

EFEP90 10CDMP3 CD t 0 t 0 To pull a bigger wagon, it is easier to add more oxen than to grow a gigantic ox 10t 0 t 0 n p Ts Tp if E(n, p) < 1 p, then T (n) < T (n, p) s p S(n,p) = p

: f(x)=sin(cos(x)) : f(x)=sin(cos(x)) 0: sin(cos(x 1 )) f(x) v99 v100 0: v1=cos(x1) v2=cos(x2).. =cos(x99) =cos(x100) Wait 1: Wait sin(v1) sin(v2).. sin(v99) sin(v100) : f(x1) f(x2).. f(x99) f(x100) 1: sin(cos(x 2 )) t JacobiAx = b Jacobi 1.x0 2. x1 xp+1 x2 xp+2 p-1 xp x2p k x1 x2 x3 xp-1 xp xp+1 xp+2 xp+3 x2p-1 x2p x2p+1 x2p+2 x2p+3 x3p-1 x3p 3. k x1 x2 x3 xp-1 xp xp+1 xp+2 xp+3 x2p-1 x2p x2p+1 x2p+2 x2p+3 x3p-1 x3p

, 0 1 2 p-2 p-1 OpenMP MPI (Message Passing Interface) C C++ Fortran MPIMessage Passing Interface MPI / MPI MPICHLAM MPI Hello! program hello implicit none integer myid,nproces,ierr call MPI_INIT(ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD,nproc,ierr) call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr) write(*,*)"hello!","total Proces is:",nproc,"my process is:", myid call MPI_FINALIZE(ierr) end program hello implicit none call MPI_INIT call MPI_COMM_SIZE FORTRAN90 MPI MPI MPI MPI Fortran90 Fortran77include mpif.h MPI_INIT(ierr) call MPI_COMM_RANK call MPI_FINALIZE end MPI MPIMPI

MPI_COMM_SIZE(MPI_COMM_WORLD,nproc,ierr) MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr) communicator MPI (MPI_COMM_WORLD) communicator MPI (MPI_COMM_WORLD) MPI_FINALIZE(ierr) MPI program programname [] call MPI_INIT(ierr)!MPI call MPI_COMM_SIZE(MPI_COMM_WORLD,nproces,ierr) call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr) [(MPIMPI)] call MPI_FINALIZE(ierr)!MPI [(MPI)] end program program main call MPI_INIT(ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD,nproc,ierr) call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr) data=1234 If (myid == 0) then data=4321 call MPI_SEND(data,1,MPI_INTEGER,1,0,MPI_COMM_WORLD,ierr) else if (myid == 1) then write(*,*)"before recv: Myid=",myid,"DATA=", data call MPI_RECV(data,1,MPI_INTEGER,0,0,MPI_COMM_WORLD, & statuss,ierr) write(*,*)"after recv: Myid=", myid, "DATA=", data end if call MPI_FINALIZE(ierr) end

communicator communicator program main implicit none integer myid,nprocs,ierr integer data call MPI_INIT(ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD,nprocs,ierr) call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr) call MPI_ALLREDUCE(myid,data,1,MPI_INTEGER,& MPI_SUM,MPI_COMM_WORLD,ierr) write(*,*)"myid=",myid,"data=",data call MPI_FINALIZE(ierr) end MPI_ALLREDUCE(myid,data,1,MPI_INTEGER,MPI_SUM,& MPI_COMM_WORLD,ierr) communicator MPI_SUM MPI_MIN MPI_MAX

13 14 15 16 13 14 15 16 1 2 3 4 1 2 3 4 Process 0 Process 1 Commnode(i, j) j i-1 Commnode(2, 4) dt PEFEP90 Commnode Node Force Process 0 Process 1 Node Force(t) Node Force(t) Node Force(t+dt) Node Force(t+dt) F1 MPI_ALLREDUCE F2 Process 0 Process 1 Process 0 Process 1 F=F1+F2 F=F1+F2 Update Node Force F Update Node Force F Next Next

1 2 2 Process 0 Process 1 Process 0 Process 1 dt1 dt2 MPI_ALLREDUCE Min(dt1,dt2) dt dt Next Next 3 4 R = 100mm, H = 300mm200mm/s 2 CPU 4 core = 8 processors OpenMP FortranCC++ http://www.openmp.org/ Processor Processor Processor Processor Memory Fork/join parallelism Master thread Time Other thread Fork Join Fork Join C/C++OpenMP #include <omp.h> main () { int var1, var2, var3; #pragma omp parallel private(var1, var2) shared(var3) { OMP_NUM_THREADS int omp_get_num_procs(void) void omp_set_num_threads(int t) int t; t = omp_get_num_procs(); Omp_set_num_threads(t);

#pragma omp parallel for #pragma omp parallel for for (i=first; i<size; i+=prime) marked[i]=1; private shared private clause #pragma omp parallel for private(j) for (i = 0; i < n; i++) for (j = 0; j < n; j++) a[i][j] = min(a[i][j], a[i][k]+tmp[j]); critical pragma double area, pi, x; int i,n; area = 0.0; #pragma omp parallel for private(x) for (i=0; i<=n; i++) { x = (i+0.5)/n; #pragma omp critical area += 4.0/(1+x*x); value of area 11.667 pi = area/n; Protect a block of code that should be executed by a single thread at a time 11.667 15.432 15.230 Thread A +3.765 Thread B +3.563 reduction double area, pi, x; int i,n; area = 0.0; #pragma omp parallel for for (i=0; i<=n; i++) { x = (i+0.5)/n; #pragma omp critical area += 4.0/(1+x*x); pi = area/n; private(x) reduction(+:area) Threads n = 100,000 Execution time of program (sec) critical pragma reduction clause 1 0.0780 0.0273 2 0.1510 0.0146 3 0.3400 0.0105 4 0.3608 0.0086 5 0.4710 0.0076 parallel pragma #include <omp.h> int main(int argc, char* argv[]) { int nthreads, tid; int nprocs; char buf[32]; #pragma omp parallel private(nthreads, tid) { /* Obtain and print thread id */ tid = omp_get_thread_num(); printf("hello World from OMP thread %d\n", tid); /* Only master thread does this */ if (tid==0) { nthreads = omp_get_num_threads(); printf("number of threads %d\n", nthreads); return 0;