Presentation is loading. Please wait.

Presentation is loading. Please wait.

6/16/2010 Parallel Performance Parallel Performance.

Similar presentations


Presentation on theme: "6/16/2010 Parallel Performance Parallel Performance."— Presentation transcript:

1 6/16/2010 Parallel Performance Parallel Performance

2 Performance Considerations
6/16/2010 Parallel Performance Performance Considerations I parallelized my code and … The code slower than the sequential version, or I don’t get enough speedup What should I do?

3 Performance Considerations
6/16/2010 Parallel Performance Performance Considerations Algorithmic Fine-grained parallelism True contention False contention Other Bottlenecks

4 Algorithmic Bottlenecks
6/16/2010 Parallel Performance Algorithmic Bottlenecks Parallel algorithms might sometimes be completely different from their sequential counterparts Might need different design and implementation

5 Algorithmic Bottlenecks
6/16/2010 Parallel Performance Algorithmic Bottlenecks Parallel algorithms might sometimes be completely different from their sequential counterparts Might need different design and implementation Example: MergeSort (once again )

6 Recall from Previous Lecture
6/16/2010 Parallel Performance Recall from Previous Lecture Merge was the bottleneck 1 8 1 16 1 8

7 Most Efficient Sequential Merge is not Parallelizable
6/16/2010 Parallel Performance Most Efficient Sequential Merge is not Parallelizable Merge(int* a, int* b, int* result ){ while( <end condition> ) { if(*a <= *b){ *result++ = *a++; } else { *result++ = *b++;

8 Parallel Merge Algorithm
6/16/2010 Parallel Performance Parallel Merge Algorithm Merge two sorted arrays A and B using divide and conquer

9 Parallel Merge Algorithm
6/16/2010 Parallel Performance Parallel Merge Algorithm Merge two sorted arrays A and B Let A be the larger array (else swap A and B) Let n be the size of A Split A into A[0…n/2-1], A[n/2], A[n/2+1…n] Do binary search to find smallest m such that B[m] >= A[n/2] Split B into B[0...m-1], B[m,..] return Merge(A[0…n/2-1], B[0…m-1]), A[n/2], Merge(A[n/2+1…n], B[m…])

10 Assignment 1 Extra Credit
6/16/2010 Parallel Performance Assignment 1 Extra Credit Implement the Parallel Merge algorithm and measure performance improvement with your work stealing queue implementation

11 Fine Grained Parallelism
6/16/2010 Parallel Performance Fine Grained Parallelism Overheads of Tasks Each Task uses some memory (not as much resources as threads, though) Work stealing queue operations If the work done in each task is small, then the overheads might not justify the improvements in parallelism

12 False Sharing Data Locality & Cache Behavior
6/16/2010 Parallel Performance False Sharing Data Locality & Cache Behavior Performance of computation depends HUGELY on how well the cache is working Too many cache misses, if processors are “fighting” for the same cache lines Even if they don’t access the same data

13 6/16/2010 Parallel Performance Cache Coherence P1 P2 P3 P3 P1 P2 P3 P3 P1 P2 P3 P3 i i i i s i s s i i x i Each cacheline, on each processor, has one of these states: i - invalid : not cached here s - shared : cached, but immutable x - exclusive: cached, and can be read or written State transitions require communication between caches (cache coherence protocol) If a processor writes to a line, it removes it from all other caches

14 Ping-Pong & False Sharing
6/16/2010 Parallel Performance Ping-Pong & False Sharing Ping-Pong If two processors both keep writing to the same location, cache line has to go back and forth Very inefficient (lots of cache misses) False Sharing Two processors writing to two different variables may happen to write to the same cacheline If both variables are allocated on the same cache line Get ping-pong effect as above, and horrible performance

15 False Sharing Example void WithFalseSharing() {
6/16/2010 Parallel Performance False Sharing Example void WithFalseSharing() { Random rand1 = new Random(), rand2 = new Random(); int[] results1 = new int[ ], results2 = new int[ ]; Parallel.Invoke( () => { for (int i = 0; i < results1.Length; i++) results1[i] = rand1.Next(); }, for (int i = 0; i < results2.Length; i++) results2[i] = rand2.Next(); }); }

16 False Sharing Example void WithFalseSharing() {
6/16/2010 Parallel Performance rand1, rand2 are allocated at same time => likely on same cache line. False Sharing Example void WithFalseSharing() { Random rand1 = new Random(), rand2 = new Random(); int[] results1 = new int[ ], results2 = new int[ ]; Parallel.Invoke( () => { for (int i = 0; i < results1.Length; i++) results1[i] = rand1.Next(); }, for (int i = 0; i < results2.Length; i++) results2[i] = rand2.Next(); }); } Call to Next() writes to the random object => Ping-Pong Effect

17 False Sharing, Eliminated?
6/16/2010 Parallel Performance False Sharing, Eliminated? rand1, rand2 are allocated by different tasks => Not likely on same cache line. void WithoutFalseSharing() { int[] results1, results2; Parallel.Invoke( () => { Random rand1 = new Random(); results1 = new int[ ]; for (int i = 0; i < results1.Length; i++) results1[i] = rand1.Next(); }, Random rand2 = new Random(); results2 = new int[ ]; for (int i = 0; i < results2.Length; i++) results2[i] = rand2.Next(); }); }


Download ppt "6/16/2010 Parallel Performance Parallel Performance."

Similar presentations


Ads by Google