[concurrency-interest] Merging forked tasks - Repeating because of some formatting problem

Doug Lea dl at cs.oswego.edu
Tue Mar 16 07:47:22 EDT 2010


On 03/16/10 06:55, Ramsundar Kandasamy wrote:
>
> I am playing around with this ForkJoin framework. I was trying the first
> sample usage of RecursiveAction given in its javaDoc page.
>
> class SortTask extends RecursiveAction {
> ....
> protected void compute() {
> if (hi - lo < THRESHOLD)
> sequentiallySort(array, lo, hi);
> else {
> int mid = (lo + hi) >>> 1;
> invokeAll(new SortTask(array, lo, mid), new SortTask(array, mid, hi));
> merge(array, lo, hi); //!!!!! how to do this
> }
> }
> }
>
> and following is my sequentiallySort method
>
> private void sequentiallySort(Integer[] array, int lo, int hi) {
> Arrays.sort(array, lo, hi + 1);
> }
>
> but I don't know how should I design the merge(array, lo, hi) method?
>

While any kind of array merge will suffice,
one way to do this that enables more parallelism
(adapted from "cilksort") is included in one of
our test programs, ScalaraLongSort that you now find in CVS:
http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/test/loops/ScalarLongSort.java?view=log

-Doug



More information about the Concurrency-interest mailing list