Package tnx.lab.executor
Class XNucleobaseCounting
java.lang.Object
tnx.lab.executor.XNucleobaseCounting
A parallel nucleobase counter that uses Java's
ExecutorService
interface to count different sections of the chromosome in parallel.- Author:
- __STUDENT_NAME__, Finn Voichick
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountDivideAndConquer(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, IntPredicate isParallelPredicate)Should use a divide-and-conquer approach to count all of the instances of a specific nucleobase.static intcountLowerUpperSplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase)Should count all of the instances of a specific nucleobase in parallel.static intcountNWaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int numTasks)Should asynchronously count all of the instances of a specific nucleobase, creating the given number of tasks.
-
Constructor Details
-
XNucleobaseCounting
public XNucleobaseCounting()
-
-
Method Details
-
countLowerUpperSplit
public static int countLowerUpperSplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase) throws InterruptedException, ExecutionExceptionShould count all of the instances of a specific nucleobase in parallel. The chromosome should be split into two halves, and the "lower" half should be counted in parallel with the "upper" half.- Parameters:
executor- anExecutorServicethat you should use to submit taskschromosome- the chromosome to examine, represented as an array of bytesnucleobase- the nucleobase to look for in the chromosome- Returns:
- the total number of times that the given nucleobase occurs in the given chromosome
- Throws:
InterruptedException- if the computation was cancelledExecutionException- if the computation threw an exception
-
countNWaySplit
public static int countNWaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int numTasks) throws InterruptedException, ExecutionExceptionShould asynchronously count all of the instances of a specific nucleobase, creating the given number of tasks. For example, if numTasks is 8, the chromosome should be divided into 8 slices, and each slice should be counted in a separate task. NOTE: You are required to use theExecutorService.invokeAll(Collection)method for this part of the assignment.- Parameters:
executor- anExecutorServicethat you should use to invoke taskschromosome- the chromosome to examine, represented as an array of bytesnucleobase- the nucleobase to look for in the chromosomenumTasks- the number of tasks to create- Returns:
- the total number of times that the given nucleobase occurs in the given chromosome
- Throws:
InterruptedException- if the computation was cancelledExecutionException- if the computation threw an exception
-
countDivideAndConquer
public static int countDivideAndConquer(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, IntPredicate isParallelPredicate) throws InterruptedException, ExecutionExceptionShould use a divide-and-conquer approach to count all of the instances of a specific nucleobase.- Parameters:
executor- anExecutorServicethat you should use to submit taskschromosome- the chromosome to examine, represented as an array of bytesnucleobase- the nucleobase to look for in the chromosomeisParallelPredicate- Predicate whose test method will return whether or not the current range length is large enough to justify running in parallel.- Returns:
- the total number of times that the given nucleobase occurs in the given chromosome
- Throws:
InterruptedException- if the computation was cancelledExecutionException- if the computation threw an exception
-