cavegen candidate 0

This commit is contained in:
minjaesong
2019-08-25 18:53:01 +09:00
parent e449d34e3a
commit 004a9af098
2 changed files with 73 additions and 30 deletions

View File

@@ -10,7 +10,7 @@ typealias ThreadableFun = (Int) -> Unit
* Created by minjaesong on 2016-05-25.
*/
object ThreadParallel {
val threadCount = Runtime.getRuntime().availableProcessors() + 1 // modify this to your taste
val threadCount = Runtime.getRuntime().availableProcessors() // not using (logicalCores + 1) method; it's often better idea to reserve one extra thread for other jobs in the app
private val pool: Array<Thread?> = Array(threadCount) { null }
@@ -206,5 +206,14 @@ fun IntProgression.sliceEvenly(slices: Int): List<IntProgression> {
}
}
fun IntProgression.mapToThreadPoolDirectly(prefix: String, worker: (IntProgression) -> Unit) {
this.sliceEvenly(ThreadParallel.threadCount).forEachIndexed { index, intProgression ->
val workerFun: ThreadableFun = {
worker(intProgression)
}
ThreadParallel.map(index, prefix, workerFun)
}
}
private inline fun Float.roundInt(): Int = Math.round(this)