如何有效地并行地应用中等权重函数 [英] how to efficiently apply a medium-weight function in parallel
问题描述
我想把一个价格昂贵的函数映射到一个大型的懒惰seq并行。 pmap
是伟大的,但我失去了很多上下文切换。我想我需要增加传递给每个线程的工作块的大小。
我在一个函数上写了一个函数,将seq分成块,并将函数pmap到每个块上并将它们重新组合。这个工作,但结果没有壮观。原始代码本质上是这样的:
(pmap eval-polynomial(range x)coificients)
如何在保持懒惰的同时真正挤压这个?
方案如何使用
分区
函数分解您的范围
序列?在 http://上有一篇关于类似问题的有趣文章www.fatvat.co.uk/2009/05/jvisualvm-and-clojure.htmlI'm looking to map a modestly-expensive function onto a large lazy seq in parallel.
pmap
is great but i'm loosing to much to context switching. I think I need to increase the size of the chunk of work thats passed to each thread.I wrote on a function to break the seq into chunks and pmap the function onto each chunk and recombine them. this 'works' but the results have not been spectacular. The origional code essentially looks like this:
(pmap eval-polynomial (range x) coificients)
How can I really squeez this while keeping it lazy?
解决方案How about using the
partition
function to break up yourrange
sequence? There was an interesting post on a similar problem at http://www.fatvat.co.uk/2009/05/jvisualvm-and-clojure.html这篇关于如何有效地并行地应用中等权重函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!