Thread and Executor Service Assignment

From CSE231 Wiki
Jump to navigation Jump to search

credit for this assignment: Voichick and Cosgrove

Building On Previous Exercises

Be sure to complete the Half & Half and Coarsening exercises first.

Thread

While we strive to make CSE 231 generally applicable across libraries and languages, it would be madness to have a parallel programming class in Java and not have students know how to create a Thread, start it, and join it. In this section of the lab, you will do just that.

Code To Use

class Thread

constructor
start
join

Code To Implement

ThreadHalfAndHalfNucleobaseCounter

Here we will construct, start, and join a Thread to count the chromosome in parallel.

class: ThreadHalfAndHalfNucleobaseCounter.java Java.png
methods: count
package: count.exercise
source folder: student/src/main/java

count

method: public int count(byte[] chromosome, Nucleobase targetNucleobase) Parallel.svg (parallel implementation required)

The constructor of a thread takes in a "Runnable", which is a runnable chunk of code (passed in using a lambda). In this case, the code is responsible for storing the count of one half of the chromosome.

Executors

Code To Use

interface ExecutorService

submit(task)
invokeAll(tasks)

interface Future

get()

NucleobaseUtils

countRange(chromosome, targetNucleobase, min, maxExclusive)

Ranges

slice​(min, maxExclusive, numRanges).


As always, the wiki's reference page can be of help.


Code To Implement

ExecutorHalfAndHalfNucleobaseCounter

Here we will use the executorService passed to the constructor to submit a task and join its future to count the chromosome in parallel.

class: ExecutorHalfAndHalfNucleobaseCounter.java Java.png
methods: constructor
executorService
count
package: count.exercise
source folder: student/src/main/java

constructor

constructor: public ExecutorHalfAndHalfNucleobaseCounter(ExecutorService executorService)

Hang onto the value of executorService parameter in an instance variable for later use.

executorService

method: public ExecutorService executorService() Sequential.svg (sequential implementation only)

Simply return the value of the executorService passed to the constructor.

count

method: public int count(byte[] chromosome, Nucleobase targetNucleobase) Parallel.svg (parallel implementation required)

ExecutorCoarseningNucleobaseCounter

Here we will use the executorService and numRanges passed to the constructor to count the chromosome in parallel with the correct coarsening level.

class: ExecutorCoarseningNucleobaseCounter.java Java.png
methods: constructor
executorService
numRanges
count
package: count.exercise
source folder: student/src/main/java

constructor

constructor: public ExecutorCoarseningNucleobaseCounter(ExecutorService executorService, int numRanges)

Hang onto the values of the executorService and numRanges parameters in instance variables for later use.

executorService

method: public ExecutorService executorService() Sequential.svg (sequential implementation only)

Simply return the value of the executorService passed to the constructor.

numRanges

method: public int numRanges() Sequential.svg (sequential implementation only)

Simply return the value of numRanges passed to the constructor.

count

method: public int count(byte[] chromosome, Nucleobase targetNucleobase) Parallel.svg (parallel implementation required)

Slice the chromosome up and use invokeAll(tasks) to count the targetNucleobase in parallel.

Correctness

class: __ThreadAndExecutorTestSuite.java Junit.png
package: count.exercise
source folder: testing/src/test/java

Pledge, Acknowledgments, Citations

file: thread-and-executor-pledge-acknowledgments-citations.txt

More info about the Honor Pledge