Difference between revisions of "Slices"
Line 15: | Line 15: | ||
Our "Slices" will actually be a list of objects called "Slice". A Slice contains a couple things, one of them being the full, original data that is passed through at the start. It is important that the entire array is given to the Slice. Not a copy of the array, nor a shortened version of the array, but the ''entire'' thing. | Our "Slices" will actually be a list of objects called "Slice". A Slice contains a couple things, one of them being the full, original data that is passed through at the start. It is important that the entire array is given to the Slice. Not a copy of the array, nor a shortened version of the array, but the ''entire'' thing. | ||
− | =class | + | =class IndexedRange= |
− | use: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/ | + | use: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/IndexedRange.html class IndexedRange] |
− | |||
− | |||
− | |||
− | |||
+ | This class has everything you need for [[Nucleobase_Counting#Coarsening_N-Way_Split|n-way split]] problems, specifically: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getSliceIndexId() getSliceIndexId()], [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getMinInclusive() getMinInclusive()], and [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getMaxExclusive() getMaxExclusive()]. | ||
=Code to Implement= | =Code to Implement= |
Revision as of 08:19, 15 January 2020
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 our Slices class, 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 in working order.
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 async() or finish().
Warning: Do NOT Copy The Data Into SubArrays |
Our "Slices" will actually be a list of objects called "Slice". A Slice contains a couple things, one of them being the full, original data that is passed through at the start. It is important that the entire array is given to the Slice. Not a copy of the array, nor a shortened version of the array, but the entire thing.
class IndexedRange
use: class IndexedRange
This class has everything you need for n-way split problems, specifically: getSliceIndexId(), getMinInclusive(), and getMaxExclusive().
Code to Implement
class: | Slices.java | |
methods: | createNSlicesForArrayObject | |
package: | slices.studio | |
source folder: | student/src/main/java |
createNSlicesForArrayObject
method: private static <A> List<Slice<A>> createNSlicesForArrayObject(A data, int numSlices)
(sequential implementation only)
Given an Array (A) and a number of slices to make, return a List of object Slice. Make sure to read through the Javadocs for the Slice class (linked above) before writing any code. Understanding what a Slice is and how it is used is important when writing this solution.
Note that a Slice has a minimum and maximum value. This acts as the "range" that sections off a part of the original array. 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: Because we are working with something of type A, "data.length" is not possible. To get the size of "data", we will need to use the Array.getLength(Object) method. |
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 defeats the purpose of balancing the workload!
Flexibility
In order to support primitive arrays (e.g. byte[], int[], et cetera) and non-primitive arrays (e.g. Object[]) we provide all of the public methods, each which simply call the single method requiring implementation:
public static <T> List<Slice<T[]>> createNSlices(T[] data, int numSlices) { return createNSlicesForArrayObject(data, numSlices); } public static List<Slice<byte[]>> createNSlices(byte[] data, int numSlices) { return createNSlicesForArrayObject(data, numSlices); } public static List<Slice<char[]>> createNSlices(char[] data, int numSlices) { return createNSlicesForArrayObject(data, numSlices); } public static List<Slice<short[]>> createNSlices(short[] data, int numSlices) { return createNSlicesForArrayObject(data, numSlices); } public static List<Slice<int[]>> createNSlices(int[] data, int numSlices) { return createNSlicesForArrayObject(data, numSlices); } public static List<Slice<long[]>> createNSlices(long[] data, int numSlices) { return createNSlicesForArrayObject(data, numSlices); } public static List<Slice<float[]>> createNSlices(float[] data, int numSlices) { return createNSlicesForArrayObject(data, numSlices); } public static List<Slice<double[]>> createNSlices(double[] data, int numSlices) { return createNSlicesForArrayObject(data, numSlices); }
Testing Your Solution
Correctness
class: | SlicesTestSuite.java | |
package: | slice.studio | |
source folder: | testing/src/test/java |