十三章共享存储系统编程.ppt
《十三章共享存储系统编程.ppt》由会员分享,可在线阅读,更多相关《十三章共享存储系统编程.ppt(50页珍藏版)》请在三一文库上搜索。
1、国家高性能计算中心(合肥),第十三章 共享存储系统编程,国家高性能计算中心(合肥),共享存储系统编程,13.1 ANSI X3H5共享存储模型 13.2 POSIX 线程模型 13.3 OpenMP模型,国家高性能计算中心(合肥),编程标准的作用,规定程序的执行模型 SPMD, SMP 等 如何表达并行性 DOACROSS, FORALL, PARALLEL,INDEPENDENT 如何表达同步 Lock, Barrier, Semaphore, Condition Variables 如何获得运行时的环境变量 threadid, num of processes,国家高性能计算中心(合肥),
2、ANSI X3H5共享存储器模型,Started in the mid-80s with the emergence of shared memory parallel computers with proprietary directive driven programming environments 更早的标准化结果PCF共享存储器并行Fortran 1993年制定的概念性编程模型 Language Binding C Fortran 77 Fortran 90,国家高性能计算中心(合肥),并行块(工作共享构造) 并行块(psections . end psections) 并行循环(p
3、do . Endo pdo) 单进程(psingle . End psingle) 可嵌套 非共享块重复执行 隐式路障(nowait),显式路障和阻挡操作 共享/私有变量 线程同步 门插销(latch):临界区 锁:test,lock,unlock 事件:wait,post,clear 序数(ordinal):顺序,国家高性能计算中心(合肥),X3H5:并行性构造,Program main !程序以顺序模式开始,此时只有一个 A !A只由基本线程执行,称为主线程 parallel !转换为并行模式,派生出多个子线程(一个组) B !B为每个组员所复制 psections !并行块开始 sect
4、ion C !一个组员执行C section D !一个组员执行D end psections !等待C和D都结束 psingle !暂时转换成顺序模式 E !已由一个组员执行 end psingle !转回并行模式 pdo i=1,6 !pdo构造开始 F(i) !组员共享F的六次迭代 end pdo no wait !无隐式路障同步 G !更多的复制代码 end parallel !转为顺序模式 H !初始化进程单独执行H . !可能有更多的并行构造 End,国家高性能计算中心(合肥),线程,隐式路障同步,P,Q,R,A,B,C,E,F(1:2),G,H,G,G,F(3:4),F(5:6)
5、,D,B,B,隐式路障同步,隐式路障同步,无隐式路障同步,隐式路障同步,国家高性能计算中心(合肥),共享存储系统编程,13.1 ANSI X3H5共享存储模型 13.2 POSIX 线程模型 13.3 OpenMP模型,国家高性能计算中心(合肥),POSIX线程模型,IEEE/ANSI标准IEEE POSIX 1003.1c-1995线程标准Unix/NT操作系统层上的,SMP Chorus, Topaz, Mach Cthreads Win32 Thread GetThreadHandle,SetThreadPriority,SuspendThread,ResumeThread TLS(线程
6、局部存储)TlsAlloc, TlsSetValue LinuxThreads:_clone and sys_clone 用户线程和内核线程(LWP)(一到一,一到多,多到多),国家高性能计算中心(合肥),What Are Threads?,General-purpose solution for managing concurrency. Multiple independent execution streams. Shared state. Preemptive scheduling. Synchronization (e.g. locks, conditions).,Shared st
7、ate (memory, files, etc.),Threads,国家高性能计算中心(合肥),线程共享相同的内存空间。 与标准 fork() 相比,线程带来的开销很小。内核无需单独复制进程的内存空间或文件描述符等等。这就节省了大量的 CPU 时间。 和进程一样,线程将利用多 CPU。如果软件是针对多处理器系统设计的,计算密集型应用。 支持内存共享无需使用繁琐的 IPC 和其它复杂的通信机制。 Linux _clone不可移植,Pthread可移植。 POSIX 线程标准不记录任何“家族”信息。无父无子。如果要等待一个线程终止,就必须将线程的 tid 传递给 pthread_join()。线程
8、库无法为您断定 tid。,国家高性能计算中心(合肥),POSIX Threads: Basics and Examples by Uday Kamath http:/www.coe.uncc.edu/abw/parallel/pthreads/pthreads.html POSIX 线程详解: 一种支持内存共享的简单和快捷的工具 by Daniel Robbins http:/ Solaris 2 pthread_create thr_create pthread_exit thr_exit pthread_kill thr_kill pthread_join thr_join pthread
9、_self thr_self,国家高性能计算中心(合肥),线程调用线程同步和互斥,POSIX Solaris 2 pthread_mutex_init mutex_init pthread_ mutex_destroy mutex_destroy pthread_ mutex_lock mutex_lock pthread_ mutex_trylock mutex_trylock pthread_ mutex_unlock mutex_unlock pthread_cond_init pthread_cond_destroy pthread_cond_wait pthread_cond_tim
10、edwait pthread_cond_signal pthread_cond_broadcast,国家高性能计算中心(合肥),Pthreads实现计算的实例 1,国家高性能计算中心(合肥),Pthreads实现计算的实例 2,国家高性能计算中心(合肥),对生产者驱动的有界缓冲区问题的Pthread条件变量解,void *producer(void *arg1) int i; for (i=1;i=SUMSIZE;i+) pthread_mutex_lock(,void *consumer(void *arg2) int i,myitem; for (;) pthread_mutex_lock
11、( ,国家高性能计算中心(合肥),共享存储系统编程,13.1 ANSI X3H5共享存储模型 13.2 POSIX 线程模型 13.3 OpenMP模型,国家高性能计算中心(合肥),The History of OpenMP What is directive/pragma? Directive-based general purpose parallel programming API with emphasis on the ability to parallelize existing serial programs Why a new standard? Whos Involved?
12、Parallelism model and basic directives Fortran77, Fortran90 C, C+,OpenMP标准,国家高性能计算中心(合肥),The History of OpenMP,A key intermediate step was X3H5 in the late 80s. An official standards effort to agree on a parallel dialect of Fortran for shared memory computers. The X3H5 effort failed. It was too big
13、and too late. OpenMP is born: In 1996 a group formed to create an industry standard set of directives for SMP programming This group called itself the OpenMP Architecture Review Board(the ARB) who takes care of OpenMP,国家高性能计算中心(合肥),The History of OpenMP(cont.),The ARB has released the following spec
14、ifications: OpenMP 1.0 for Fortran, Nov. 1997 OpenMP 1.0 for C/C+, Nov. 1998 OpenMP Fortran Interpretations, Spring 1999 OpenMP 2.0(soon) OpenMP is an evolving standard. Send comments over the feedback link on the OpenMP web site(http:/www.openmp.org),国家高性能计算中心(合肥),为什么要建立新标准?,ANSI X3H5, 1994 时机不好, 分
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 十三 共享 存储系统 编程
链接地址:https://www.31doc.com/p-2636995.html