Presentation is loading. Please wait.

Presentation is loading. Please wait.

Improve Run Generation Overlap input,output, and internal CPU work. Reduce the number of runs (equivalently, increase average run length). DISK MEMORY.

Similar presentations


Presentation on theme: "Improve Run Generation Overlap input,output, and internal CPU work. Reduce the number of runs (equivalently, increase average run length). DISK MEMORY."— Presentation transcript:

1 Improve Run Generation Overlap input,output, and internal CPU work. Reduce the number of runs (equivalently, increase average run length). DISK MEMORY DISK

2 Internal Quick Sort 6285111041973 Use 6 as the pivot (median of 3). Input first, middle, and last blocks first. In-place partitioning. Input blocks from the ends toward the middle. Sort left and right groups recursively. Can begin output as soon as left most block is ready. 4235161011978

3 Alternative Internal Sort Scheme DISK B1B2B3 Partition into 3 buffers.

4 Steady State Operation Read from disk Write to disk Run generation Synchronization is done when the active input buffer gets empty (the active output buffer will be full at this time).

5 DISK MEMORY DISK New Strategy Use 2 input and 2 output buffers. Rest of memory is used for a min loser tree. Input 1Input 0Output 0Output 1 Loser Tree

6 Steady State Operation Read from disk Write to disk Run generation Synchronization is done when the active input buffer gets empty (the active output buffer will be full at this time).

7 4368157326945258 4 3 8 O0O1 I0 I1 Initialize

8 4368157326945258 4 6 8 3 5 1 7 O0O1 I0 I1

9 4368157326945258 4 6 8 3 5 3 7 1 6 2 9 Initialize O0O1 I0 I1

10 4368157326945258 4 6 8 3 5 3 7 2 5 2 8 1 6 4 9 Initialize O0O1 I0 I1

11 4368157326945258 4 6 8 3 5 3 7 2 5 5 8 1 6 4 9 Initialize O0O1 I0 I1

12 4368157326945258 4 6 8 3 5 3 7 2 5 5 8 2 6 4 9 Initialize O0O1 I0 I1

13 Generate Run 1 1436857326945258 4 6 8 3 5 3 7 2 5 5 8 2 6 4 9 O0O1 I0 I1 354354

14 Generate Run 1 436857326945258 4 6 8 3 5 3 7 2 5 5 8 2 6 4 9 O0O1 I0 I1 354354 1 3 3

15 5 O0 2 3 Generate Run 1 43685736945258 4 6 8 3 5 3 7 2 5 5 8 3 6 4 9 O1 I0 I1 354354 1 54

16 45 O0 2 3 Generate Run 1 43685736945 2 58 4 6 8 3 5 3 7 2 5 5 8 3 6 4 9 O1 I0 I1 354354 1 54

17 5 O0 2 3 43685736945 2 58 4 6 8 3 5 3 7 2 5 5 8 3 6 4 9 O1 I0 I1 1 54 4 192192

18 5 O0 2 3 43685736945 2 58 4 6 8 3 5 3 7 4 5 5 8 3 6 4 9 O1 I0 I1 1 54 4 192192 Continue With Run 1

19 O1 3 45 O0 2 43685736945 2 58 4 6 8 3 5 3 7 4 5 5 8 4 6 4 9 I0 I1 1 5 1 192192 Continue With Run 1 1 5

20 1 O1 3 45 O0 2 436857 3 6945 2 58 4 6 8 3 5 3 7 4 5 5 8 4 6 4 9 I0 I1 1 5 1 192192 Continue With Run 1 5 9 957

21 9 1 O1 3 45 O0 2 4 3 6857 3 6945 2 58 4 6 8 3 5 3 7 4 5 5 8 4 6 4 9 I0 I1 1 5 1 192192 Continue With Run 1 5957 2

22 9 1 O1 3 45 O0 4 3 6857 3 694558 4 6 8 3 5 3 7 4 5 5 8 4 6 4 9 I0 I1 5 1 613613 5957 2

23 9 1 O1 3 45 O0 4 3 6857 3 694558 4 6 8 3 5 3 7 4 5 5 8 4 6 4 9 I0 I1 5 1 613613 5957 2 Continue With Run 1 2

24 2 9 1 O1 3 45 O0 4 3 6857 3 694558 4 6 8 3 5 3 7 4 5 5 8 4 6 4 9 I0 I1 5 1 613613 5957 Continue With Run 1 2 6 65

25 2 9 1 O1 3 45 O0 4 3 6857 3 69 4 558 4 6 8 3 5 3 7 4 5 5 8 4 6 4 9 I0 I1 5 1 613613 5957 Continue With Run 1 2 6 65 1 1 95

26 Buffer Reduction We may reduce the number of buffers to 3. At any time, 1 us used to read into, 1 to write from, and the 3 rd both feeds the loser tree and is filled from the tree. The 3 physical buffers rotate through these three roles.

27 Let k be number of external nodes in loser tree. Run size >= k. Sorted input => 1 run. Reverse of sorted input => n/k runs. Average run size is ~2k.

28 Memory capacity = m records. Run size using fill memory, sort, and output run scheme = m. Use loser tree scheme.  Assume block size is b records.  Need memory for 4 buffers (4b records).  Loser tree k = m – 4b.  Average run size = 2k = 2(m – 4b).  2k >= m when m >= 8b.

29 Assume b = 100. m6001000500010000 k200 6004600 9600 2k4001200920019200

30 Total internal processing time using fill memory, sort, and output run scheme = O((n/m) m log m) = O(n log m). Total internal processing time using loser tree = O(n log k). Loser tree scheme generates runs that differ in their lengths.

31 4369 Merging Runs Of Different Length 43 6 9 715 22 7 13 22


Download ppt "Improve Run Generation Overlap input,output, and internal CPU work. Reduce the number of runs (equivalently, increase average run length). DISK MEMORY."

Similar presentations


Ads by Google