Crossfire JXClient, Trunk
|
Classes | |
class | MergeSortTask |
Public Member Functions | |
MergeSort (int parallelism) | |
void | sort (int[] array) |
Private Attributes | |
final ForkJoinPool | pool |
A class for sorting an array of
in parallel. A
is used for the parallelism, using the merge sort algorithm the array is split into halves and a new sub task is created for each part. Each sub task is dispatched to the
which will schedule the task to a
. This happens until the size of the array is at most 2 elements long. At this point the array is sorted using a simple compare and possibly a swap. The tasks then finish by using insert sort to merge the two just sorted arrays.
The idea of this class is to demonstrate the usage of RecursiveAction not to implement the best possible parallel merge sort. This version creates a small array for each merge (creating a lot of objects), this could be avoided by keeping a single array.
Definition at line 62 of file MergeSort.java.
MergeSort.MergeSort | ( | int | parallelism | ) |
Creates a
containing a ForkJoinPool with the indicated parallelism level
parallelism | the parallelism level used |
Definition at line 125 of file MergeSort.java.
References pool.
void MergeSort.sort | ( | int[] | array | ) |
Sorts all the elements of the given array using the ForkJoin framework
array | the array to sort |
Definition at line 133 of file MergeSort.java.
References pool.
Referenced by MergeDemo.runForParallelism(), and MergeDemo.warmup().
|
private |
Definition at line 63 of file MergeSort.java.
Referenced by MergeSort(), and sort().