Difference between revisions of "Parallel Partition"
(Created page with "==(Optional) Parallel Partition Challenge== The partitioning step can also be done in [http://www.classes.cec.wustl.edu/~cse341/web/handouts/lecture07.pdf parallel with scan]....") |
|||
| (7 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | Partition does almost all of the work of quicksort. Further, the classic sequential partition, although wonderful, dominates the span of the quicksort algorithm. If we can parallelize partition, the span can be improved from <math>\mathcal{O}(n)</math> down to <math>\mathcal{O}(\lg^k{}n)</math>. | ||
| + | |||
| + | For N=16: | ||
| + | |||
| + | {| class="wikitable" style="text-align:center;" | ||
| + | ! | ||
| + | ! colspan="16" | <- - - - - - - - - - - - - - N - - - - - - - - - - - - - -> | ||
| + | |- | ||
| + | ! ^ | ||
| + | | colspan="16" style="background-color:#CCCCFF;" | partition [0, 16) | ||
| + | |- | ||
| + | ! | | ||
| + | | colspan="8" style="background-color:#CCCCFF;" | partition [0, 8) | ||
| + | | colspan="8" | partition [8, 16) | ||
| + | |- | ||
| + | ! lg N | ||
| + | | colspan="4" style="background-color:#CCCCFF;" | partition [0, 4) | ||
| + | | colspan="4" | partition [4, 8) | ||
| + | | colspan="4" | partition [8, 12) | ||
| + | | colspan="4" | partition [12, 16) | ||
| + | |- | ||
| + | ! | | ||
| + | | colspan="2" style="background-color:#CCCCFF;" | partition [0, 2) | ||
| + | | colspan="2" | partition [2, 4) | ||
| + | | colspan="2" | partition [4, 6) | ||
| + | | colspan="2" | partition [6, 8) | ||
| + | | colspan="2" | partition [8, 10) | ||
| + | | colspan="2" | partition [10, 12) | ||
| + | | colspan="2" | partition [12, 14) | ||
| + | | colspan="2" | partition [14, 16) | ||
| + | |- | ||
| + | ! v | ||
| + | | style="background-color:#CCCCFF;" | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | | base | ||
| + | |} | ||
| + | |||
==(Optional) Parallel Partition Challenge== | ==(Optional) Parallel Partition Challenge== | ||
| − | The partitioning step can also be done | + | The partitioning step can also be done [https://www.cse.wustl.edu/~angelee/archive/cse341/fall14/handouts/lecture08.pdf in parallel] with [[Scan|Scan]] remarkably similar to how [[Pack|Pack]] worked. |
| − | {{CodeToImplement|ParallelPartitioner|partitionRange|sort.challenge | + | {{CodeToImplement|ParallelPartitioner|partitionRange|sort.quick.challenge}} |
| − | {{Parallel| | + | {{Parallel|SubRangePair partitionRange(int[] data, int min, int maxExclusive)}} |
=Testing Your Solution= | =Testing Your Solution= | ||
==Correctness== | ==Correctness== | ||
| − | {{TestSuite| | + | {{TestSuite|_ParallelPartitionerTestSuite|sort.quick.challenge}} |
Latest revision as of 18:06, 20 March 2026
Partition does almost all of the work of quicksort. Further, the classic sequential partition, although wonderful, dominates the span of the quicksort algorithm. If we can parallelize partition, the span can be improved from Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \mathcal{O}(n)} down to Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \mathcal{O}(\lg^k{}n)} .
For N=16:
| <- - - - - - - - - - - - - - N - - - - - - - - - - - - - -> | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ^ | partition [0, 16) | |||||||||||||||
| | | partition [0, 8) | partition [8, 16) | ||||||||||||||
| lg N | partition [0, 4) | partition [4, 8) | partition [8, 12) | partition [12, 16) | ||||||||||||
| | | partition [0, 2) | partition [2, 4) | partition [4, 6) | partition [6, 8) | partition [8, 10) | partition [10, 12) | partition [12, 14) | partition [14, 16) | ||||||||
| v | base | base | base | base | base | base | base | base | base | base | base | base | base | base | base | base |
(Optional) Parallel Partition Challenge
The partitioning step can also be done in parallel with Scan remarkably similar to how Pack worked.
| class: | ParallelPartitioner.java | |
| methods: | partitionRange | |
| package: | sort.quick.challenge | |
| source folder: | student/src/main/java |
method: SubRangePair partitionRange(int[] data, int min, int maxExclusive)
(parallel implementation required)
Testing Your Solution
Correctness
| class: | _ParallelPartitionerTestSuite.java | |
| package: | sort.quick.challenge | |
| source folder: | testing/src/test/java |