【教学课件】第十三章共享存储系统编程.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,ANSI X3H5共享存储器模型,Started in the mid-80s with the emergence of shared m
2、emory parallel computers with proprietary directive driven programming environments更早的标准化结果PCF共享存储器并行Fortran1993年制定的概念性编程模型Language BindingCFortran 77Fortran 90,并行块(工作共享构造)并行块(psections.end psections)并行循环(pdo.Endo pdo)单进程(psingle.End psingle)可嵌套非共享块重复执行隐式路障(nowait),显式路障和阻挡操作共享/私有变量线程同步门插销(latch):临界区
3、锁:test,lock,unlock事件:wait,post,clear序数(ordinal):顺序,X3H5:并行性构造,Program main!程序以顺序模式开始,此时只有一个A!A只由基本线程执行,称为主线程parallel!转换为并行模式,派生出多个子线程(一个组)B!B为每个组员所复制psections!并行块开始sectionC!一个组员执行CsectionD!一个组员执行Dend psections!等待C和D都结束psingle!暂时转换成顺序模式E!已由一个组员执行end psingle!转回并行模式pdo i=1,6!pdo构造开始F(i)!组员共享F的六次迭代end p
4、do 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),D,B,B,隐式路障同步,隐式路障同步,无隐式路障同步,隐式路障同步,共享存储系统编程,13.1 ANSI X3H5共享存储模型13.2 POSIX 线程模型13.3 OpenMP模型,POSIX线程模型,IEEE/ANSI标准IEEE POSIX 1003.1c-1995线程标准Unix/NT操作系统层上的,SMPChorus,Topaz,M
5、ach CthreadsWin32 ThreadGetThreadHandle,SetThreadPriority,SuspendThread,ResumeThreadTLS(线程局部存储)TlsAlloc,TlsSetValueLinuxThreads:_clone and sys_clone用户线程和内核线程(LWP)(一到一,一到多,多到多),What Are Threads?,General-purpose solution for managing concurrency.Multiple independent execution streams.Shared state.Pree
6、mptive scheduling.Synchronization(e.g.locks,conditions).,Shared state(memory,files,etc.),Threads,线程共享相同的内存空间。与标准 fork()相比,线程带来的开销很小。内核无需单独复制进程的内存空间或文件描述符等等。这就节省了大量的 CPU 时间。和进程一样,线程将利用多 CPU。如果软件是针对多处理器系统设计的,计算密集型应用。支持内存共享无需使用繁琐的 IPC 和其它复杂的通信机制。Linux _clone不可移植,Pthread可移植。POSIX 线程标准不记录任何“家族”信息。无父无子。如果
7、要等待一个线程终止,就必须将线程的 tid 传递给 pthread_join()。线程库无法为您断定 tid。,POSIX Threads:Basics and Examples by Uday Kamathhttp:/www.coe.uncc.edu/abw/parallel/pthreads/pthreads.htmlPOSIX 线程详解:一种支持内存共享的简单和快捷的工具by Daniel Robbinshttp:/,线程调用线程管理,POSIXSolaris 2pthread_createthr_createpthread_exitthr_exitpthread_killthr_kil
8、lpthread_jointhr_joinpthread_selfthr_self,线程调用线程同步和互斥,POSIXSolaris 2pthread_mutex_initmutex_initpthread_ mutex_destroy mutex_destroypthread_ mutex_lock mutex_lockpthread_ mutex_trylock mutex_trylockpthread_ mutex_unlock mutex_unlockpthread_cond_initpthread_cond_destroypthread_cond_waitpthread_cond_t
9、imedwaitpthread_cond_signalpthread_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(,共享存储系统编程,13.1 ANSI X3H5共享存储模型13.2 POSIX 线程模型13.3 Ope
10、nMP模型,The History of OpenMPWhat is directive/pragma?Directive-based general purpose parallel programming API with emphasis on the ability to parallelize existing serial programsWhy a new standard?Whos Involved?Parallelism model and basic directivesFortran77,Fortran90C,C+,OpenMP标准,The History of Open
11、MP,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 and too late.OpenMP is born:In 1996 a group formed to create an industry standard set of directives for SMP pro
12、grammingThis 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 specifications:OpenMP 1.0 for Fortran,Nov.1997OpenMP 1.0 for C/C+,Nov.1998OpenMP Fortran Interpretations,Spring 1999OpenMP 2.0(soon)O
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 教学课件 教学 课件 第十三 共享 存储系统 编程

链接地址:https://www.31ppt.com/p-5664119.html