DOC PREVIEW
CMU CS 15213 - Lecture

This preview shows page 1-2-3-21-22-23-43-44-45 out of 45 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 45 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Carnegie Mellon Thread Level Parallelism 15 213 Introduction to Computer Systems 26th Lecture Nov 30 2010 Instructors Randy Bryant and Dave O Hallaron 1 Carnegie Mellon Today Parallel Computing Hardware Multicore Multiple separate processors on single chip Hyperthreading Replicated instruction execution hardware in each processor Maintaining cache consistency Thread Level Parallelism Splitting program into independent tasks Example Parallel summation Some performance artifacts Divide and conquer parallelism Example Parallel quicksort 2 Carnegie Mellon Multicore Processor Core 0 Core n 1 Regs Regs L1 d cache L1 i cache L2 unified cache L1 d cache L1 i cache L2 unified cache L3 unified cache shared by all cores Main memory Intel Nehalem Processor E g Shark machines Multiple processors operating with coherent view of memory 3 Carnegie Mellon Memory Consistency int a 1 int b 100 Thread1 Wa a 2 Rb print b Thread2 Wb b 200 Ra print a Thread consistency constraints Wa Rb Wb Ra What are the possible values printed Depends on memory consistency model Abstract model of how hardware handles concurrent accesses Sequential consistency Overall effect consistent with each individual thread Otherwise arbitrary interleaving 4 Carnegie Mellon Sequential Consistency Example Thread consistency constraints Wa Rb int a 1 int b 100 Thread1 Wa a 2 Rb print b Wb Thread2 Wb b 200 Ra print a Rb Wa Wb Ra Wb Impossible outputs Wa Ra Wb Ra 100 2 Rb Ra 200 2 Ra Wa Rb 2 200 Rb 1 200 Ra Rb 2 200 Rb Ra 200 2 100 1 and 1 100 Would require reaching both Ra and Rb before Wa and Wb 5 Carnegie Mellon Non Coherent Cache Scenario Write back caches without coordination between them int a 1 int b 100 Thread1 Wa a 2 Rb print b Thread1 Cache a 2 b 100 Thread2 Wb b 200 Ra print a Thread2 Cache a 1 b 200 print 1 print 100 Main Memory a 1 b 100 6 Carnegie Mellon Snoopy Caches int a 1 int b 100 Tag each cache block with state Invalid Cannot use value Shared Readable copy Exclusive Writeable copy Thread1 Cache E Thread1 Wa a 2 Rb print b Thread2 Wb b 200 Ra print a Thread2 Cache a 2 E b 200 Main Memory a 1 b 100 7 Carnegie Mellon Snoopy Caches int a 1 int b 100 Tag each cache block with state Invalid Cannot use value Shared Readable copy Exclusive Writeable copy Thread1 Cache E S a 2 a 2 print 2 E b 200 S b 200 Main Memory a 1 Thread2 Wb b 200 Ra print a Thread2 Cache S S b 200 Thread1 Wa a 2 Rb print b b 100 print 200 When cache sees request for one of its E tagged blocks Supply value from cache Set tag to S 8 Carnegie Mellon Out of Order Processor Structure Instruction Control Instruction Decoder Registers Op Queue Instruction Cache PC Functional Units Integer Arith Integer Arith FP Arith Load Store Data Cache Instruction control dynamically converts program into stream of operations Operations mapped onto functional units to execute in parallel 9 Carnegie Mellon Hyperthreading Instruction Control Reg A Instruction Decoder Op Queue A Reg B Op Queue B PC A Instruction Cache PC B Functional Units Integer Arith Integer Arith FP Arith Load Store Data Cache Replicate enough instruction control to process K instruction streams K copies of all registers Share functional units 10 Carnegie Mellon Summary Creating Parallel Machines Multicore Separate instruction logic and functional units Some shared some private caches Must implement cache coherency Hyperthreading Also called simultaneous multithreading Separate program state Shared functional units caches No special control needed for coherency Combining Shark machines 8 cores each with 2 way hyperthreading Theoretical speedup of 16X Never achieved in our benchmarks 11 Carnegie Mellon Summation Example Sum numbers 0 N 1 Should add up to N 1 N 2 Partition into K ranges N K values each Accumulate leftover values serially Method 1 All threads update single global variable 1A No synchronization 1B Synchronize with pthread semaphore 1C Synchronize with pthread mutex Binary semaphore Only values 0 1 12 Carnegie Mellon Accumulating in Single Global Variable Declarations typedef unsigned long data t Single accumulator volatile data t global sum Mutex semaphore for global sum sem t semaphore pthread mutex t mutex Number of elements summed by each thread size t nelems per thread Keep track of thread IDs pthread t tid MAXTHREADS Identify each thread int myid MAXTHREADS 13 Carnegie Mellon Accumulating in Single Global Variable Operation nelems per thread nelems nthreads Set global value global sum 0 Create threads and wait for them to finish for i 0 i nthreads i myid i i Pthread create tid i NULL thread fun myid i for i 0 i nthreads i Pthread join tid i NULL result global sum Add leftover elements for e nthreads nelems per thread e nelems e result e 14 Carnegie Mellon Thread Function No Synchronization void sum race void vargp int myid int vargp size t start myid nelems per thread size t end start nelems per thread size t i for i start i end i global sum i return NULL 15 Carnegie Mellon Unsynchronized Performance N 230 Best speedup 2 86X Gets wrong answer when 1 thread 16 Carnegie Mellon Thread Function Semaphore Mutex Semaphore void sum sem void vargp int myid int vargp size t start myid nelems per thread size t end start nelems per thread size t i for i start i end i sem wait semaphore sem wait semaphore global sum i i global sum sem post semaphore sem post semaphore return NULL Mutex pthread mutex lock mutex global sum i pthread mutex unlock mutex 17 Carnegie Mellon Semaphore Mutex Performance Terrible Performance 2 5 seconds 10 minutes Mutex 3X faster than semaphore Clearly neither is successful 18 Carnegie Mellon Separate Accumulation Method 2 Each thread accumulates into separate variable 2A Accumulate in contiguous array elements 2B Accumulate in spaced apart array elements 2C Accumulate in registers Partial sum computed by each thread data t psum MAXTHREADS MAXSPACING Spacing between accumulators size t spacing 1 19 Carnegie Mellon Separate Accumulation Operation nelems per thread nelems nthreads Create threads and wait for them to finish for i 0 i nthreads i myid i i psum i spacing 0 Pthread create tid i NULL thread fun myid i for i 0 i nthreads i Pthread join tid i NULL result 0 Add up the partial sums computed by each thread for i 0 i nthreads i result psum i spacing Add leftover elements for e nthreads nelems per thread e nelems e result e 20 Carnegie Mellon Thread Function Memory Accumulation void sum global void vargp int myid int vargp size t start myid nelems per thread size t


View Full Document

CMU CS 15213 - Lecture

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?