本文整理汇总了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))
}
}
开发者ID:armanbilge,项目名称:phyloHMC,代码行数:31,代码来源:ParallelTreeLikelihood.scala
注:本文中的scala.collection.parallel.ExecutionContextTaskSupport类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论