Difference between revisions of "Scan"
(→Client) |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 50: | Line 50: | ||
=Code To Use= | =Code To Use= | ||
| + | ==ForkJoin== | ||
| + | [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop_to_int_array(int,int,fj.api.TaskIntFunction) join_fork_loop_to_int_array(min, maxExclusive, toIntFunction)] | ||
| + | |||
==[[PowersOf2Iterable]]== | ==[[PowersOf2Iterable]]== | ||
This [[PowersOf2Iterable|exercise]] should come in handy here. Recall that we implemented a <code>PowersOfTwoLessThan</code> class in this exercise. | This [[PowersOf2Iterable|exercise]] should come in handy here. Recall that we implemented a <code>PowersOfTwoLessThan</code> class in this exercise. | ||
| Line 59: | Line 62: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | <!-- | ||
==PhasableIntArrays== | ==PhasableIntArrays== | ||
class [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/edu/wustl/cse231s/phasable/PhasableIntArrays.html PhasableIntArrays] extends [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/edu/wustl/cse231s/phasable/AbstractPhasable.html AbstractPhasable] | class [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/edu/wustl/cse231s/phasable/PhasableIntArrays.html PhasableIntArrays] extends [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/edu/wustl/cse231s/phasable/AbstractPhasable.html AbstractPhasable] | ||
| Line 88: | Line 92: | ||
'''NOTE:''' think about which array is the correct one to return from your scan method given how you write your code. | '''NOTE:''' think about which array is the correct one to return from your scan method given how you write your code. | ||
| + | --> | ||
=Code To Implement= | =Code To Implement= | ||
Latest revision as of 03:42, 17 March 2026
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:
- 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 y_i = y_{i-1} + x_i}
make it seem to have little hope for parallelism. However, simple yet clever approaches can achieve 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 \log ^k n} critical path lengths.
While we will simply implement prefix sum, scan can be used for other associative operations.
Background
| Video: Hillis and Steele Scan |
|---|
Lecture
Visualization
| class: | ScanViz.java | VIZ |
| package: | scan.viz | |
| source folder: | student/src/main/java |
Warmup
Client
| class: | StepEfficientParallelSumScannerClient.java | CLIENT |
| package: | scan.client | |
| source folder: | student/src/main/java |
| StepEfficientParallelSumScannerClient |
|---|
OutOfPlaceSumScanner sumScanner = new StepEfficientParallelSumScanner();
int[] data = {1, 2, 3, 4, 5, 6, 7, 8};
System.out.println(Arrays.toString(data));
int[] result = sumScanner.sumScan(data);
System.out.println(Arrays.toString(result));
|
| StepEfficientParallelSumScannerClient Output |
|---|
[1, 2, 3, 4, 5, 6, 7, 8] [1, 3, 6, 10, 15, 21, 28, 36] |
Code To Use
ForkJoin
join_fork_loop_to_int_array(min, maxExclusive, toIntFunction)
PowersOf2Iterable
This exercise should come in handy here. Recall that we implemented a PowersOfTwoLessThan class in this exercise.
for(int v : new PowersOfTwoLessThan(71)) {
System.out.println(v);
}
Code To Implement
| class: | StepEfficientParallelSumScanner.java | |
| methods: | sumScan | |
| package: | scan.exercise | |
| source folder: | student/src/main/java |
method: int[] sumScan(int[] data)
(parallel implementation required)
Challenge Problem
Blelloch (Work-efficient) Scan
Testing Your Solution
| class: | __ScanTestSuite.java | |
| package: | scan.exercise | |
| source folder: | testing/src/test/java |
Pledge, Acknowledgments, Citations
| file: | exercise-scan-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge
