第十三章共享存储系统编程.ppt
文本预览下载声明
第十三章 共享存储系统编程 共享存储系统编程 13.1 ANSI X3H5共享存储模型 13.2 POSIX 线程模型 13.3 OpenMP模型 ANSI X3H5共享存储器模型 Started in the mid-80’s 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) 并行循环(pdo ... Endo pdo) 单进程(psingle ... End psingle) 可嵌套 非共享块重复执行 隐式路障(nowait),显式路障和阻挡操作 共享/私有变量 线程同步 门插销(latch):临界区 锁:test,lock,unlock 事件:wait,post,clear 序数(ordinal):顺序 X3H5:并行性构造 Program main !程序以顺序模式开始,此时只有一个 A !A只由基本线程执行,称为主线程 parallel !转换为并行模式,派生出多个子线程(一个组) B !B为每个组员所复制 psections !并行块开始 section 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 共享存储系统编程 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(线程局部存储)—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). 线程共享相同的内存空间。 与标准 fork() 相比,线程带来的开销很小。内核无需单独复制进程的内存空间或文件描述符等等。这就节省了大量的 CPU 时间。 和进程一样,线程将利用多 CPU。如果软件是针对多处理器系统设计的,计算密集型应用。 支持内存共享无需使用繁琐的 IPC 和其它复杂的通信机制。 Linux __clone不可移植,Pthread可移植。 POSIX 线程标准不记录任何“家族”信息。无父无子。如果要等待一个线程终止,就必须将线程的 tid 传递给 pthread_join()。线程库无法为您断定 tid。 线程调用—线程管理 POSIX Solaris 2 pthread_create thr_create pthread_exit thr_exit pthread_kill thr_kill pthread_join thr_join pthread_self thr_self 线程调用—线程同步和互斥 POSIX Solaris 2 pthread_mutex_init mutex_init pthread_ mutex_
显示全部