|
|
@@ -4,7 +4,9 @@ class MultiRadixPar{ |
|
|
|
int n;
|
|
|
|
int [] a;
|
|
|
|
final static int NUM_BIT = 7; // alle tall 6-11 .. finn ut hvilken verdi som er best
|
|
|
|
int nThreads = Runtime.getRuntime().availableProcessors();
|
|
|
|
int nThreads = Math.min(
|
|
|
|
Runtime.getRuntime().availableProcessors(),
|
|
|
|
8);
|
|
|
|
|
|
|
|
int [] radixMulti(int [] a) {
|
|
|
|
long tt = System.nanoTime();
|
|
|
@@ -49,11 +51,12 @@ class MultiRadixPar{ |
|
|
|
class Worker implements Runnable {
|
|
|
|
int[] a, b, count;
|
|
|
|
int start, end, shift, mask;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
Worker(int[] a, int[] b, int[] count, int start, int end, int shift, int mask) {
|
|
|
|
this.a = a;
|
|
|
|
this.b = b;
|
|
|
|
this.count = Arrays.copyOf(count, count.length);
|
|
|
|
this.count = count; //Arrays.copyOf(count, count.length);
|
|
|
|
this.start = start;
|
|
|
|
this.end = end;
|
|
|
|
this.shift = shift;
|
|
|
@@ -61,17 +64,9 @@ class MultiRadixPar{ |
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
// c) Add up in 'count' - accumulated values
|
|
|
|
int j = 0;
|
|
|
|
int acumVal = 0;
|
|
|
|
for (int i = 0; i <= mask; i++) {
|
|
|
|
j = count[i];
|
|
|
|
count[i] = acumVal;
|
|
|
|
acumVal += j;
|
|
|
|
}
|
|
|
|
|
|
|
|
// d) move numbers in sorted order a to b
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
for (int i = start; i < end - 1; i++) {
|
|
|
|
b[count[(a[i]>>>shift) & mask]++] = a[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -88,7 +83,17 @@ class MultiRadixPar{ |
|
|
|
count[(a[i]>>> shift) & mask]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// c) Add up in 'count' - accumulated values
|
|
|
|
int j = 0;
|
|
|
|
int acumVal = 0;
|
|
|
|
for (int i = 0; i <= mask; i++) {
|
|
|
|
j = count[i];
|
|
|
|
count[i] = acumVal;
|
|
|
|
acumVal += j;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parallel
|
|
|
|
Timer td = new Timer().start();
|
|
|
|
int d = n / nThreads;
|
|
|
|
Thread[] threads = new Thread[nThreads];
|
|
|
|
Worker[] workers = new Worker[nThreads];
|
|
|
@@ -103,6 +108,7 @@ class MultiRadixPar{ |
|
|
|
for (Thread t: threads) {
|
|
|
|
try { t.join(); } catch (InterruptedException ex) {}
|
|
|
|
}
|
|
|
|
System.out.println("par D: "+td.end().prettyTime());
|
|
|
|
|
|
|
|
}// end radixSort
|
|
|
|
|