如何有效地并行应用中等权重的函数 [英] how to efficiently apply a medium-weight function in parallel
问题描述
我希望将一个适度昂贵的函数并行映射到一个大的惰性 seq.pmap
很棒,但我在上下文切换方面失去了很多.我想我需要增加传递给每个线程的工作块的大小.
I'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.
我写了一个函数来将 seq 分成多个块,并将该函数 pmap 到每个块上并重新组合它们.这有效",但结果并不壮观.原始代码基本上是这样的:
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?
推荐答案
如何使用 partition
函数来分解你的 range
序列?在 http://www 上有一篇关于类似问题的有趣帖子.fatvat.co.uk/2009/05/jvisualvm-and-clojure.html
How about using the partition
function to break up your range
sequence? There was an interesting post on a similar problem at http://www.fatvat.co.uk/2009/05/jvisualvm-and-clojure.html
这篇关于如何有效地并行应用中等权重的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!