Slices
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 |
Warning: Do NOT Copy The Data Into SubArrays |
Code to Implement
class: | Slices.java | |
methods: | createNSlicesForArrayObject | |
package: | slices.studio | |
source folder: | student/src/main/java |
createNSlicesForArrayObject
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:
method: private static <T> List<Slice<T>> createNSlicesForArrayObject(T data, int numSlices)
(sequential implementation only)
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); }
Tip: To pull this off we will need to use the Array.getLength(Object) method. |
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=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 |
Warning:Do NOT slice up the data by giving all of the remainder to one slice |
A
|B
|C
|D
|D
|D
|D
class Slice<T>
use: class Slice
This class has everything you need for n-way split problems, specifically: getSliceIndexId(), getMinInclusive(), and getMaxExclusive().
getOriginalUnslicedData() is not necessary until the K-Mer Counting Lab
Testing Your Solution
Correctness
class: | SlicesTestSuite.java | |
package: | slice.studio | |
source folder: | testing/src/test/java |