本文整理汇总了Scala中scala.collection.parallel.ExecutionContextTaskSupport类的典型用法代码示例。如果您正苦于以下问题:Scala ExecutionContextTaskSupport类的具体用法?Scala ExecutionContextTaskSupport怎么用?Scala ExecutionContextTaskSupport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExecutionContextTaskSupport类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ParallelTreeLikelihood
//设置package包名称以及导入依赖的类
package group.matsen.phylohmc.pll
import java.util.concurrent.Executors
import group.matsen.phylohmc.{Pattern, Patterns, Tree}
import spire.algebra.VectorSpace
import scala.collection.parallel.ExecutionContextTaskSupport
import scala.concurrent.ExecutionContext
class ParallelTreeLikelihood[N](val threads: Int, val patterns: Patterns, val gtr: GTR, val mu: Double, sse: Boolean = false, avx: Boolean = false, avx2: Boolean = false, avx512: Boolean = false, tipPatternCompression: Boolean = false) extends (Tree[Double, N] => (Double, IndexedSeq[Double])) {
private[this] val likelihoods = patterns.multiplicities.grouped(patterns.multiplicities.length / threads)
.map(x => Patterns.from(x: _*)(Patterns.configuration.compact[Pattern]))
.map(x => new TreeLikelihood[N](x, gtr, mu, sse, avx, avx2, avx512, tipPatternCompression)).toParArray
likelihoods.tasksupport = new ExecutionContextTaskSupport(new ExecutionContext {
val threadPool = Executors.newFixedThreadPool(threads)
def execute(runnable: Runnable) = threadPool.submit(runnable)
def reportFailure(t: Throwable) = throw t
})
override def apply(t: Tree[Double, N]): (Double, IndexedSeq[Double]) = {
import spire.std.double._
import spire.std.seq._
val (ls, dLs) = likelihoods.map(l => l(t)).unzip
(ls.sum, VectorSpace[IndexedSeq[Double], Double].sum(dLs.arrayseq))
}
}