fun runTrialParallel( size: Int,set: TrialSuite,pts: Array<IPoint>,selector: IPivotIndex?,numThreads: Int,ratio: Int) {val ar = arrayOfNulls<Int>(size) run { var i = 0 var idx = 0 while (i < pts.size) { ar[idx++] = (pts[i].getX() * BASE) as Int ar[idx++] = (pts[i].getY() * BASE) as Int i++ } } val qs: MultiThreadQuickSort<Int> = MultiThreadQuickSort<Int>(ar) qs.setPivotMethod(selector) qs.setNumberHelperThreads(numThreads) qs.setThresholdRatio(ratio) System.gc() val start = System.currentTimeMillis() qs.qsort(0, size - 1) val end = System.currentTimeMillis() set.addTrial(size, start, end) for (i in 0 until ar.size - 1) { assert(ar[i]!! <= ar[i + 1]!!) } }
Change the number of helper threads inside to try different configurations . < p > Set to NUM_THREADS by default .