Difference between revisions of "Threads and Executors"
Line 2: | Line 2: | ||
Habanero Java Library (HJlib) is the product of the [https://wiki.rice.edu/confluence/display/HABANERO/Habanero+Extreme+Scale+Software+Research+Project Habanero Extreme Scale Software Research Laboratory]. It builds on the [http://x10-lang.org/ X10 programming language]. | Habanero Java Library (HJlib) is the product of the [https://wiki.rice.edu/confluence/display/HABANERO/Habanero+Extreme+Scale+Software+Research+Project Habanero Extreme Scale Software Research Laboratory]. It builds on the [http://x10-lang.org/ X10 programming language]. | ||
− | HJlib provides static methods, most notably [https://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/Module1.html#async-edu.rice.hj.api.HjSuspendable- async] and [https://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/Module0.html#finish-edu.rice.hj.api.HjSuspendable- finish] which handle a lot of the details of starting and joining tasks. We in CSE231 have [http://www.cse.wustl.edu/~cosgroved/courses/cse231/f17/apidocs/edu/wustl/cse231s/rice/habanero/Habanero.html thinly wrapped these methods] for stylistic reasons as well as to afford more easily testing student code. | + | HJlib provides some parallel features via static methods, most notably [https://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/Module1.html#async-edu.rice.hj.api.HjSuspendable- async] and [https://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/Module0.html#finish-edu.rice.hj.api.HjSuspendable- finish] which handle a lot of the details of starting and joining tasks. We in CSE231 have [http://www.cse.wustl.edu/~cosgroved/courses/cse231/f17/apidocs/edu/wustl/cse231s/rice/habanero/Habanero.html thinly wrapped these methods] for stylistic reasons as well as to afford more easily testing student code. |
In this assignment we will remove the training wheels for a moment to get some experience with some core Java parallel features Threads and Executors. | In this assignment we will remove the training wheels for a moment to get some experience with some core Java parallel features Threads and Executors. |
Revision as of 04:42, 27 September 2017
Contents
- 1 Where To Start
- 2 Join All Warm Up
- 3 Threads
- 4 Executors
- 4.1 Videos
- 4.2 XNucleobaseCount
- 4.2.1 note countSequential
- 4.2.2 implement int countRangeSequential(byte[] chromosome, Nucleobase nucleobase, int min, int max)
- 4.2.3 implement int count2WaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase)
- 4.2.4 implement int countNWaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int numTasks)
- 4.2.5 implement int countDivideAndConquer(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int threshold)
- 4.2.6 implement int countDivideAndConquerKernel(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int min, int max, int threshold)
- 4.3 XQuicksort
- 4.3.1 note sequentialQuicksort
- 4.3.2 implement void sequentialQuicksortKernel(int[] array, int min, int maxExclusive)
- 4.3.3 implement void parallelQuicksort(ExecutorService executor, int[] array, int threshold)
- 4.3.4 implement void parallelQuicksortKernel(ExecutorService executor, int[] array, int min, int maxExclusive, Queue<Future<?>> futures, int threshold)
- 5 Pledge, Acknowledgments, Citations
Where To Start
Habanero Java Library (HJlib) is the product of the Habanero Extreme Scale Software Research Laboratory. It builds on the X10 programming language.
HJlib provides some parallel features via static methods, most notably async and finish which handle a lot of the details of starting and joining tasks. We in CSE231 have thinly wrapped these methods for stylistic reasons as well as to afford more easily testing student code.
In this assignment we will remove the training wheels for a moment to get some experience with some core Java parallel features Threads and Executors.
Tutorial
Java 8 Concurrency Tutorial: Threads and Executors
ThreadsAndExcutorsTestSuite
Join All Warm Up
source: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html
"Iterators are weakly consistent, returning elements reflecting the state of the queue at some point at or since the creation of the iterator."
JoinAllTestSuite
ThreadsEventually joinAllInQueueViaPoll
Threads
class SimpleThreadFactory
Video
implement Thread newThread(Runnable target)
Create and return a new thread with the target Runnable parameter you are passed.
Do *NOT* start this thread.
Certainly, do *NOT* run this thread.
Do not pass Go. Do not collect $200.
To repeat: just create a new Thread with the target Runnable and return it.
TAgeSum
implement int sumUpperLowerSplit(int[] ages, ThreadFactory threadFactory)
You will need use the passed in ThreadFactory to create a new thread or two (at your preference), start any threads you create, and join them.
Think about where you need to start and join any Threads to ensure both correctness and an appropriate amount of parallelism.
Executors
Videos
Executor submit and Future get
XNucleobaseCount
note countSequential
public static int countSequential(byte[] chromosome, Nucleobase nucleobase) { return countRangeSequential(chromosome, nucleobase, 0, chromosome.length); }
implement int countRangeSequential(byte[] chromosome, Nucleobase nucleobase, int min, int max)
implement int count2WaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase)
implement int countNWaySplit(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int numTasks)
Use SliceUtils
implement int countDivideAndConquer(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int threshold)
implement int countDivideAndConquerKernel(ExecutorService executor, byte[] chromosome, Nucleobase nucleobase, int min, int max, int threshold)
XQuicksort
note sequentialQuicksort
public static void sequentialQuicksort(int[] array) { sequentialQuicksortKernel(array, 0, array.length); }
implement void sequentialQuicksortKernel(int[] array, int min, int maxExclusive)
implement void parallelQuicksort(ExecutorService executor, int[] array, int threshold)
NOTE: ConcurrentLinkQueue's iterators are weakly consistent. Do the join all warm up to get experience with handling this issue.
implement void parallelQuicksortKernel(ExecutorService executor, int[] array, int min, int maxExclusive, Queue<Future<?>> futures, int threshold)
Pledge, Acknowledgments, Citations
hw3-pledge-acknowledgments-citations.txt