0
假设我有一个〜10K元素的数组,我需要处理数组中的所有元素。我想以这种方式处理它们,只有K
元素被并行处理。我使用Scala 2.9
。我试过平行收集(见下文),但我看到更多比K
元素并行处理。Scala中的并行处理2.9
import collection.parallel.ForkJoinTasks.defaultForkJoinPool._ val old = getParallelism setParallelism(K) val result = myArray.par.map(...) // process the array in parallel setParallelism(old)
你会如何建议过程中Scala 2.9
只K
元素并行处理这样的阵列?
谢谢。你能否详细说一下使用'view'? – Michael
观点背后的想法是推迟评估中间集合,否则将使用'take','map'或'filter'在内存中创建集合,直到集合被强制执行为止。由于某些抽象惩罚和间接指导,这可能会或可能不会提高性能,具体取决于转换的内容。你可以在这里阅读更多关于它的内容:http://docs.scala-lang.org/overviews/collections/views.html – axel22