Crossfire JXClient, Trunk
MergeSort Class Reference
+ Collaboration diagram for MergeSort:

Classes

class  MergeSortTask
 

Public Member Functions

 MergeSort (int parallelism)
 
void sort (int[] array)
 

Private Attributes

final ForkJoinPool pool
 

Detailed Description

A class for sorting an array of

ints

in parallel. A

ForkJoinPool

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

ForkJoinPool

which will schedule the task to a

Thread

. 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.

Constructor & Destructor Documentation

◆ MergeSort()

MergeSort.MergeSort ( int  parallelism)

Creates a

containing a ForkJoinPool with the indicated parallelism level

Parameters
parallelismthe parallelism level used

Definition at line 125 of file MergeSort.java.

References pool.

Member Function Documentation

◆ sort()

void MergeSort.sort ( int[]  array)

Sorts all the elements of the given array using the ForkJoin framework

Parameters
arraythe array to sort

Definition at line 133 of file MergeSort.java.

References pool.

Referenced by MergeDemo.runForParallelism(), and MergeDemo.warmup().

+ Here is the caller graph for this function:

Member Data Documentation

◆ pool

final ForkJoinPool MergeSort.pool
private

Definition at line 63 of file MergeSort.java.

Referenced by MergeSort(), and sort().


The documentation for this class was generated from the following file:
MergeSort
Definition: MergeSort.java:62