Difference between revisions of "Scan"

From CSE231 Wiki
Jump to navigation Jump to search
(Added default arrays holder, still need to change code to investigate)
Line 41: Line 41:
 
{{Sequential|public int[] sumScan(int[] data)}}
 
{{Sequential|public int[] sumScan(int[] data)}}
  
==Hillis and Steele Parallel Scan==
+
==Default Arrays Holder==
 
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.
 
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.
  
Line 54: Line 54:
  
 
'''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.
 +
 +
{{CodeToImplement|DefaultArraysHolder|getSrc<br>getDst<br>nextSrcAndDst<br>size|scan.studio}}
 +
 +
==Hillis and Steele Parallel Scan==
  
 
{{CodeToImplement|ParallelScan|sumScan|scan.studio}}
 
{{CodeToImplement|ParallelScan|sumScan|scan.studio}}

Revision as of 21:26, 16 May 2018

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

Prefix Sum

Required

Hillis and Steele Algorithm

Hillis-Steele Prefix Sum.svg

Optional

Blelloch Algorithm

Prefix sum 16.svg

Code To Investigate

class ArraysHolder

getSrc()
getDst()
nextSrcAndDst()

class PowersOfTwoLessThan implements Iterable<Integer>

Code To Implement

Sequential Scan

class: SequentialScan.java Java.png
methods: sumScan
package: scan.studio
source folder: student/src/main/java

method: public int[] sumScan(int[] data) Sequential.svg (sequential implementation only)

Default Arrays Holder

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 if nextSrcAndDst used appropriately from a parallel scan.

1 2 4 8 16
src: data a b a b
dst: a b a b a

NOTE: think about which array is the correct one to return from your scan method given how you write your code.

class: DefaultArraysHolder.java Java.png
methods: getSrc
getDst
nextSrcAndDst
size
package: scan.studio
source folder: student/src/main/java

Hillis and Steele Parallel Scan

class: ParallelScan.java Java.png
methods: sumScan
package: scan.studio
source folder: student/src/main/java

method: public int[] sumScan(int[] data) Parallel.svg (parallel implementation required)

(Optional) Blelloch Work Efficient Scan

class: WorkEfficientScan.java Java.png
methods: sumScan
package: scan.challenge
source folder: student/src/main/java

method: public int[] sumScan(int[] data) Parallel.svg (parallel implementation required)

Testing Your Solution

Correctness

Required

class: ScanTestSuite.java Junit.png
package: scan.studio
source folder: testing/src/test/java

Optional Work Efficient

class: WorkEfficientScanTestSuite.java Junit.png
package: scan.challenge
source folder: testing/src/test/java