《并行程序设计导论》 第二章PPT_免费下载.ppt.ppt 免费下载
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Copyright 2010, Elsevier Inc. All rights Reserved,Chapter 2,Parallel Hardware and Parallel Software,An Introduction to Parallel Programming Peter Pacheco,Copyright 2010, Elsevier Inc. All rights Reserved,Roadmap,Some background Modifications to the von Neumann model Parallel hardware Parallel softwa
2、re Input and output Performance Parallel program design Writing and running parallel programs Assumptions,# Chapter Subtitle,Some background,Copyright 2010, Elsevier Inc. All rights Reserved,Serial hardware and software,Copyright 2010, Elsevier Inc. All rights Reserved,input,output,programs,Computer
3、 runs one program at a time.,Copyright 2010, Elsevier Inc. All rights Reserved,The von Neumann Architecture,# Chapter Subtitle,Figure 2.1,Main memory,This is a collection of locations, each of which is capable of storing both instructions and data. Every location consists of an address, which is use
4、d to access the location, and the contents of the location.,Copyright 2010, Elsevier Inc. All rights Reserved,Central processing unit (CPU),Divided into two parts. Control unit - responsible for deciding which instruction in a program should be executed. (the boss) Arithmetic and logic unit (ALU) -
5、responsible for executing the actual instructions. (the worker),Copyright 2010, Elsevier Inc. All rights Reserved,add 2+2,Key terms,Register very fast storage, part of the CPU. Program counter stores address of the next instruction to be executed. Bus wires and hardware that connects the CPU and mem
6、ory.,Copyright 2010, Elsevier Inc. All rights Reserved,Copyright 2010, Elsevier Inc. All rights Reserved,memory,CPU,fetch/read,Copyright 2010, Elsevier Inc. All rights Reserved,memory,CPU,write/store,von Neumann bottleneck,Copyright 2010, Elsevier Inc. All rights Reserved,An operating system “proces
7、s”,An instance of a computer program that is being executed. Components of a process: The executable machine language program. A block of memory. Descriptors of resources the OS has allocated to the process. Security information. Information about the state of the process.,Copyright 2010, Elsevier I
8、nc. All rights Reserved,Multitasking,Gives the illusion that a single processor system is running multiple programs simultaneously. Each process takes turns running. (time slice) After its time is up, it waits until it has a turn again. (blocks),Copyright 2010, Elsevier Inc. All rights Reserved,Thre
9、ading,Threads are contained within processes. They allow programmers to divide their programs into (more or less) independent tasks. The hope is that when one thread blocks because it is waiting on a resource, another will have work to do and can run.,Copyright 2010, Elsevier Inc. All rights Reserve
10、d,A process and two threads,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.2,the “master” thread,starting a thread Is called forking,terminating a thread Is called joining,Modifications to the von neumann model,Copyright 2010, Elsevier Inc. All rights Reserved,Basics of caching,A collect
11、ion of memory locations that can be accessed in less time than some other memory locations. A CPU cache is typically located on the same chip, or one that can be accessed much faster than ordinary memory.,Copyright 2010, Elsevier Inc. All rights Reserved,Principle of locality,Accessing one location
12、is followed by an access of a nearby location. Spatial locality accessing a nearby location. Temporal locality accessing in the near future.,Copyright 2010, Elsevier Inc. All rights Reserved,Principle of locality,Copyright 2010, Elsevier Inc. All rights Reserved,float z1000; sum = 0.0; for (i = 0; i
13、 1000; i+) sum += zi;,Levels of Cache,Copyright 2010, Elsevier Inc. All rights Reserved,L1,L2,L3,smallest i 1000; i+) zi = xi + yi;,Multiple Issue (2),static multiple issue - functional units are scheduled at compile time. dynamic multiple issue functional units are scheduled at run-time.,Copyright
14、2010, Elsevier Inc. All rights Reserved,superscalar,Speculation (1),In order to make use of multiple issue, the system must find instructions that can be executed simultaneously.,Copyright 2010, Elsevier Inc. All rights Reserved,In speculation, the compiler or the processor makes a guess about an in
15、struction, and then executes the instruction on the basis of the guess.,Speculation (2),Copyright 2010, Elsevier Inc. All rights Reserved,z = x + y ; i f ( z 0) w = x ; e l s e w = y ;,Z will be positive,If the system speculates incorrectly, it must go back and recalculate w = y.,Hardware multithrea
16、ding (1),There arent always good opportunities for simultaneous execution of different threads. Hardware multithreading provides a means for systems to continue doing useful work when the task being currently executed has stalled. Ex., the current task has to wait for data to be loaded from memory.,
17、Copyright 2010, Elsevier Inc. All rights Reserved,Hardware multithreading (2),Fine-grained - the processor switches between threads after each instruction, skipping threads that are stalled. Pros: potential to avoid wasted machine time due to stalls. Cons: a thread thats ready to execute a long sequ
18、ence of instructions may have to wait to execute every instruction.,Copyright 2010, Elsevier Inc. All rights Reserved,Hardware multithreading (3),Coarse-grained - only switches threads that are stalled waiting for a time-consuming operation to complete. Pros: switching threads doesnt need to be near
19、ly instantaneous. Cons: the processor can be idled on shorter stalls, and thread switching will also cause delays.,Copyright 2010, Elsevier Inc. All rights Reserved,Hardware multithreading (3),Simultaneous multithreading (SMT) - a variation on fine-grained multithreading. Allows multiple threads to
20、make use of the multiple functional units.,Copyright 2010, Elsevier Inc. All rights Reserved,Parallel hardware,A programmer can write code to exploit.,Copyright 2010, Elsevier Inc. All rights Reserved,Flynns Taxonomy,Copyright 2010, Elsevier Inc. All rights Reserved,classic von Neumann,not covered,S
21、IMD,Parallelism achieved by dividing data among the processors. Applies the same instruction to multiple data items. Called data parallelism.,Copyright 2010, Elsevier Inc. All rights Reserved,SIMD example,Copyright 2010, Elsevier Inc. All rights Reserved,control unit,ALU1,ALU2,ALUn,for (i = 0; i n;
22、i+) xi += yi;,x1,x2,xn,n data items n ALUs,SIMD,What if we dont have as many ALUs as data items? Divide the work and process iteratively. Ex. m = 4 ALUs and n = 15 data items.,Copyright 2010, Elsevier Inc. All rights Reserved,SIMD drawbacks,All ALUs are required to execute the same instruction, or r
23、emain idle. In classic design, they must also operate synchronously. The ALUs have no instruction storage. Efficient for large data parallel problems, but not other types of more complex parallel problems.,Copyright 2010, Elsevier Inc. All rights Reserved,Vector processors (1),Operate on arrays or v
24、ectors of data while conventional CPUs operate on individual data elements or scalars. Vector registers. Capable of storing a vector of operands and operating simultaneously on their contents.,Copyright 2010, Elsevier Inc. All rights Reserved,Vector processors (2),Vectorized and pipelined functional
25、 units. The same operation is applied to each element in the vector (or pairs of elements). Vector instructions. Operate on vectors rather than scalars.,Copyright 2010, Elsevier Inc. All rights Reserved,Vector processors (3),Interleaved memory. Multiple “banks” of memory, which can be accessed more
26、or less independently. Distribute elements of a vector across multiple banks, so reduce or eliminate delay in loading/storing successive elements. Strided memory access and hardware scatter/gather. The program accesses elements of a vector located at fixed intervals.,Copyright 2010, Elsevier Inc. Al
27、l rights Reserved,Vector processors - Pros,Fast. Easy to use. Vectorizing compilers are good at identifying code to exploit. Compilers also can provide information about code that cannot be vectorized. Helps the programmer re-evaluate code. High memory bandwidth. Uses every item in a cache line.,Cop
28、yright 2010, Elsevier Inc. All rights Reserved,Vector processors - Cons,They dont handle irregular data structures as well as other parallel architectures. A very finite limit to their ability to handle ever larger problems. (scalability),Copyright 2010, Elsevier Inc. All rights Reserved,Graphics Pr
29、ocessing Units (GPU),Real time graphics application programming interfaces or APIs use points, lines, and triangles to internally represent the surface of an object.,Copyright 2010, Elsevier Inc. All rights Reserved,GPUs,A graphics processing pipeline converts the internal representation into an arr
30、ay of pixels that can be sent to a computer screen. Several stages of this pipeline (called shader functions) are programmable. Typically just a few lines of C code.,Copyright 2010, Elsevier Inc. All rights Reserved,GPUs,Shader functions are also implicitly parallel, since they can be applied to mul
31、tiple elements in the graphics stream. GPUs can often optimize performance by using SIMD parallelism. The current generation of GPUs use SIMD parallelism. Although they are not pure SIMD systems.,Copyright 2010, Elsevier Inc. All rights Reserved,MIMD,Supports multiple simultaneous instruction stream
32、s operating on multiple data streams. Typically consist of a collection of fully independent processing units or cores, each of which has its own control unit and its own ALU.,Copyright 2010, Elsevier Inc. All rights Reserved,Shared Memory System (1),A collection of autonomous processors is connecte
33、d to a memory system via an interconnection network. Each processor can access each memory location. The processors usually communicate implicitly by accessing shared data structures.,Copyright 2010, Elsevier Inc. All rights Reserved,Shared Memory System (2),Most widely available shared memory syste
34、ms use one or more multicore processors. (multiple CPUs or cores on a single chip),Copyright 2010, Elsevier Inc. All rights Reserved,Shared Memory System,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.3,UMA multicore system,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.5,Tim
35、e to access all the memory locations will be the same for all the cores.,NUMA multicore system,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.6,A memory location a core is directly connected to can be accessed faster than a memory location that must be accessed through another chip.,Dist
36、ributed Memory System,Clusters (most popular) A collection of commodity systems. Connected by a commodity interconnection network. Nodes of a cluster are individual computations units joined by a communication network.,Copyright 2010, Elsevier Inc. All rights Reserved,a.k.a. hybrid systems,Distribut
37、ed Memory System,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.4,Interconnection networks,Affects performance of both distributed and shared memory systems. Two categories: Shared memory interconnects Distributed memory interconnects,Copyright 2010, Elsevier Inc. All rights Reserved,Sha
38、red memory interconnects,Bus interconnect A collection of parallel communication wires together with some hardware that controls access to the bus. Communication wires are shared by the devices that are connected to it. As the number of devices connected to the bus increases, contention for use of t
39、he bus increases, and performance decreases.,Copyright 2010, Elsevier Inc. All rights Reserved,Shared memory interconnects,Switched interconnect Uses switches to control the routing of data among the connected devices. Crossbar Allows simultaneous communication among different devices. Faster than b
40、uses. But the cost of the switches and links is relatively high.,Copyright 2010, Elsevier Inc. All rights Reserved,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.7,(a) A crossbar switch connecting 4 processors (Pi) and 4 memory modules (Mj),(b) Configuration of internal switches in a cro
41、ssbar,(c) Simultaneous memory accesses by the processors,Distributed memory interconnects,Two groups Direct interconnect Each switch is directly connected to a processor memory pair, and the switches are connected to each other. Indirect interconnect Switches may not be directly connected to a proce
42、ssor.,Copyright 2010, Elsevier Inc. All rights Reserved,Direct interconnect,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.8,ring,toroidal mesh,Bisection width,A measure of “number of simultaneous communications” or “connectivity”. How many simultaneous communications can take place “acr
43、oss the divide” between the halves?,Copyright 2010, Elsevier Inc. All rights Reserved,Two bisections of a ring,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.9,A bisection of a toroidal mesh,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.10,Definitions,Bandwidth The rate at w
44、hich a link can transmit data. Usually given in megabits or megabytes per second. Bisection bandwidth A measure of network quality. Instead of counting the number of links joining the halves, it sums the bandwidth of the links.,Copyright 2010, Elsevier Inc. All rights Reserved,Fully connected networ
45、k,Each switch is directly connected to every other switch.,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.11,bisection width = p2/4,impractical,Hypercube,Highly connected direct interconnect. Built inductively: A one-dimensional hypercube is a fully-connected system with two processors.
46、A two-dimensional hypercube is built from two one-dimensional hypercubes by joining “corresponding” switches. Similarly a three-dimensional hypercube is built from two two-dimensional hypercubes.,Copyright 2010, Elsevier Inc. All rights Reserved,Hypercubes,Copyright 2010, Elsevier Inc. All rights Re
47、served,Figure 2.12,one-,three-dimensional,two-,Indirect interconnects,Simple examples of indirect networks: Crossbar Omega network Often shown with unidirectional links and a collection of processors, each of which has an outgoing and an incoming link, and a switching network.,Copyright 2010, Elsevi
48、er Inc. All rights Reserved,A generic indirect network,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.13,Crossbar interconnect for distributed memory,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.14,An omega network,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.
49、15,A switch in an omega network,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.16,More definitions,Any time data is transmitted, were interested in how long it will take for the data to reach its destination. Latency The time that elapses between the sources beginning to transmit the dat
50、a and the destinations starting to receive the first byte. Bandwidth The rate at which the destination receives data after it has started to receive the first byte.,Copyright 2010, Elsevier Inc. All rights Reserved,Copyright 2010, Elsevier Inc. All rights Reserved,Message transmission time = l + n /
51、 b,latency (seconds),bandwidth (bytes per second),length of message (bytes),Cache coherence,Programmers have no control over caches and when they get updated.,Copyright 2010, Elsevier Inc. All rights Reserved,Figure 2.17,A shared memory system with two cores and two caches,Cache coherence,Copyright
52、2010, Elsevier Inc. All rights Reserved,x = 2; /* shared variable */,y0 privately owned by Core 0 y1 and z1 privately owned by Core 1,y0 eventually ends up = 2 y1 eventually ends up = 6 z1 = ?,Snooping Cache Coherence,The cores share a bus . Any signal transmitted on the bus can be “seen” by all cor
53、es connected to the bus. When core 0 updates the copy of x stored in its cache it also broadcasts this information across the bus. If core 1 is “snooping” the bus, it will see that x has been updated and it can mark its copy of x as invalid.,Copyright 2010, Elsevier Inc. All rights Reserved,Director
54、y Based Cache Coherence,Uses a data structure called a directory that stores the status of each cache line. When a variable is updated, the directory is consulted, and the cache controllers of the cores that have that variables cache line in their caches are invalidated.,Copyright 2010, Elsevier Inc
55、. All rights Reserved,Parallel software,Copyright 2010, Elsevier Inc. All rights Reserved,The burden is on software,Hardware and compilers can keep up the pace needed. From now on In shared memory programs: Start a single process and fork threads. Threads carry out tasks. In distributed memory progr
56、ams: Start multiple processes. Processes carry out tasks.,Copyright 2010, Elsevier Inc. All rights Reserved,SPMD single program multiple data,A SPMD programs consists of a single executable that can behave as if it were multiple different programs through the use of conditional branches.,Copyright 2
57、010, Elsevier Inc. All rights Reserved,if (Im thread process i) do this; else do that;,Writing Parallel Programs,Copyright 2010, Elsevier Inc. All rights Reserved,double xn, yn; for (i = 0; i n; i+) xi += yi;,Divide the work among the processes/threads so each process/threadgets roughly the same amo
58、unt of work and communication isminimized. Arrange for the processes/threads to synchronize. Arrange for communication among processes/threads.,Shared Memory,Dynamic threads Master thread waits for work, forks new threads, and when threads are done, they terminate Efficient use of resources, but thr
59、ead creation and termination is time consuming. Static threads Pool of threads created and are allocated work, but do not terminate until cleanup. Better performance, but potential waste of system resources.,Copyright 2010, Elsevier Inc. All rights Reserved,Nondeterminism,Copyright 2010, Elsevier Inc. All rights Reserved,. . . printf ( Thread %d my_val = %dn , my_rank , my_x ) ; . . .,Thread 0 my_val = 7 Thread 1 my_val = 19,Thread 1 my_val = 19 Thread 0 my_val = 7,Nondeterminism,Copyright 2010, Elsevier Inc. All rights Reserved,my_val = Comput
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 化工厂保卫培训课件内容
- 2025~2026学年济南市天桥区七年级第一学期地理期末考试试题以及答案
- 2025-2026学年河北省五个一名校联盟高三(上)期末数学试卷(含答案)
- 钢结构涂装技术方法详解
- 特异体质学生管理制度
- 2026山东事业单位统考威海市荣成市招聘初级综合类岗位84人备考考试试题及答案解析
- 市场营销管理制度
- 2026浙江杭州海康存储科技有限公司招聘考试参考试题及答案解析
- 2026云南中铝数为(成都)科技有限责任公司社会招聘8人参考考试题库及答案解析
- 小区私人财产管理制度内容(3篇)
- 2025-2026人教版数学七年级上册期末模拟试卷(含答案)
- 2026年九江市八里湖新区国有企业面向社会公开招聘工作人员【48人】笔试参考题库及答案解析
- 广告行业法律法规与行业规范(标准版)
- 2025年CFA二级道德与专业标准题
- 2026年郑州电力高等专科学校单招职业技能测试题库新版
- 2026年八年级物理上册期末考试试卷及答案(共四套)
- 节能与新能源汽车技术路线图2.0
- 保育员配合教学培训工作指南
- 华为公司奖罚管理制度
- 2026年安全员之A证考试题库500道附答案(典型题)
- 2025-2030卫星互联网产业发展趋势与战略布局分析报告
评论
0/150
提交评论