Difference between revisions of "Scan"
Line 93: | Line 93: | ||
{{Parallel|private static int[] sumScanInclusive(PhasableIntArrays phasable)}} | {{Parallel|private static int[] sumScanInclusive(PhasableIntArrays phasable)}} | ||
− | ==(Extra Credit) | + | ==(Extra Credit) Work Efficient Scan== |
+ | Choose one path. | ||
+ | ===Inclusive (Blelloch)=== | ||
{{CodeToImplement|WorkEfficientParallelScan|sumScanExclusiveInPlace|scan.challenge}} | {{CodeToImplement|WorkEfficientParallelScan|sumScanExclusiveInPlace|scan.challenge}} | ||
{{Parallel|public static void sumScanExclusiveInPlace(int[] data)}} | {{Parallel|public static void sumScanExclusiveInPlace(int[] data)}} | ||
+ | |||
+ | ===Exclusive=== | ||
+ | |||
+ | {{CodeToImplement|WorkEfficientInPlaceInclusiveSumScanner|sumScan|scan.challenge}} | ||
+ | |||
+ | {{Parallel|void sumScan(int[] data)}} | ||
=Testing Your Solution= | =Testing Your Solution= |
Revision as of 19:06, 7 November 2021
Contents
Motivation
Scan, also known as parallel prefix, is a fundamental and useful operation in parallel programming. We will gain experience in building Hillis & Steele scan with an optional work efficient Blellock scan.
Further, the dependencies in scan:
make it seem to have little hope for parallelism. However, simple yet clever approaches can achieve critical path lengths.
While we will simply implement prefix sum, scan can be used for other associative operations.
Background
Hillis-Steele Prefix Sum
(Extra Credit) Work-efficient Blelloch Scan
Scan Primitives for Vector Computers
Prefix Sums and Their Applications
Lecture
Code To Use
class PhasableIntArrays extends AbstractPhasable
PhasableIntArrays
One of the downsides to parallel scan requires memory. For our scans we add the additional requirement that we will not mutate the incoming array parameter. We could create log(n) arrays, one for each level but that would be wasteful. If we create two array buffers and switch which is the source to read from and which is the destination to write from at each power of two level of the scan, we should be good to go.
The table below shows which array will be passed back for each offset.
phase | 0 | 1 | 2 | 3 | 4 |
src | data | a | b | a | b |
dst | a | b | a | b | a |
bonus info: power of 2 | 1 | 2 | 4 | 8 | 16 |
NOTE: think about which array is the correct one to return from your scan method given how you write your code.
PowersOf2Iterable
This studio should come in handy here.
Example usage:
for(int v : new PowersOfTwoLessThan(71)) { System.out.println(v); }
Code To Implement
Sequential Scan
class: | SequentialScan.java | |
methods: | sumScanInclusive | |
package: | scan.studio | |
source folder: | student/src/main/java |
method: public static int[] sumScanInclusive(int[] data)
(sequential implementation only)
Warning:Do NOT mutate the data parameter. Return a new array which contains the sum scan of data. |
Implement the simple sequential scan algorithm with the dependencies depicted below:
Work: N
CPL: N
Hillis and Steele Parallel Scan
class: | StepEfficientParallelScan.java | |
methods: | sumScanInclusive | |
package: | scan.studio | |
source folder: | student/src/main/java |
method: private static int[] sumScanInclusive(PhasableIntArrays phasable)
(parallel implementation required)
(Extra Credit) Work Efficient Scan
Choose one path.
Inclusive (Blelloch)
class: | WorkEfficientParallelScan.java | |
methods: | sumScanExclusiveInPlace | |
package: | scan.challenge | |
source folder: | student/src/main/java |
method: public static void sumScanExclusiveInPlace(int[] data)
(parallel implementation required)
Exclusive
class: | WorkEfficientInPlaceInclusiveSumScanner.java | |
methods: | sumScan | |
package: | scan.challenge | |
source folder: | student/src/main/java |
method: void sumScan(int[] data)
(parallel implementation required)
Testing Your Solution
Correctness
Required
class: | ScanTestSuite.java | |
package: | scan.studio | |
source folder: | testing/src/test/java |
Optional Work Efficient
class: | WorkEfficientScanTestSuite.java | |
package: | scan.challenge | |
source folder: | testing/src/test/java |