Ranges
credit for this assignment: Finn Voichick and Dennis Cosgrove
Contents
Motivation
Coarsening, or n-way split as we tend to call it in this course, comes up a fair amount. In this studio, we will create a Range class and a slice utility method, that allows us to split up our data n-times (depending on what value we pass in) in a consistent organized fashion. This makes sure that each thread is balanced in the work that it does, minimizing the Critical Path Length.
Since we will be utilizing this class throughout the semester in different studios and assignments, it is important that data is split up in a specific way. The tests should help make sure your solution is strictly adhering to the specification.
Mistakes To Avoid
Warning: Do NOT Parallelize |
This studio is about creating an easier way to split data so that it can be worked on in parallel. The splitting of the data is still done sequentially. That means at no point in this studio should you be using fork() or join().
Code to Implement
class Range
class: | Range.java | |
methods: | constructor min maxExclusive |
|
package: | range.exercise | |
source folder: | student/src/main/java |
constructor
min
maxExclusive
class Ranges
class: | Ranges.java | |
methods: | createNSlices | |
package: | range.exercise | |
source folder: | student/src/main/java |
slice
method: public static List<IndexedRange> createNSlices(int minInclusive, int maxExclusive, int numSlices)
(sequential implementation only)
Given a range [minInclusive, maxExclusive) and a number of slices to make, return a List of IndexedRanges. Understanding what a IndexedRange is and how it is used is important when writing this solution.
The goal is to have each slice's range be the entire array when put together, with no overlap. Some examples are giving below. Working through more examples can be a helpful way of figuring out what code to write if you get stuck.
Tip: In a slice, the minimum is inclusive and the maximum is exclusive. This means for two slices next to each other, slice1.getMaxExclusive() is equal to slice2.getMinInclusive(). |
Strict Specification
We are overly strict about the specification of how the data must be sliced up. This is to allow to accurately compare results intermediate results throughout the semester.
Example: array.length=8; numSlices=4
A | A | B | B | C | C | D | D |
Slice ID | Min Inclusive | Max Exclusive |
---|---|---|
0 | 0 | 2 |
1 | 2 | 4 |
2 | 4 | 6 |
3 | 6 | 8 |
Example: array.length=7; numSlices=4
Distribute the remainder 1 each to the lower end slices (the first few slices or the lower index slices).
A | A | B | B | C | C | D |
Slice ID | Min Inclusive | Max Exclusive |
---|---|---|
0 | 0 | 2 |
1 | 2 | 4 |
2 | 4 | 6 |
3 | 6 | 7 |
Warning:Do NOT slice up the data by giving all of the remainder to one slice |
A
|B
|C
|D
|D
|D
|D
Giving all the remainder to one slice does not most effectively balance the workload!
Testing Your Solution
Correctness
class: | SlicesTestSuite.java | |
package: | slice.studio | |
source folder: | testing/src/test/java |
Pledge, Acknowledgments, Citations
file: | studio-slices-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge