如何有效地并行地应用中等权重函数 [英] how to efficiently apply a medium-weight function in parallel

查看:126
本文介绍了如何有效地并行地应用中等权重函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把一个价格昂贵的函数映射到一个大型的懒惰seq并行。 pmap 是伟大的,但我失去了很多上下文切换。我想我需要增加传递给每个线程的工作块的大小。



我在一个函数上写了一个函数,将seq分成块,并将函数pmap到每个块上并将它们重新组合。这个工作,但结果没有壮观。原始代码本质上是这样的:

 (pmap eval-polynomial(range x)coificients)



如何在保持懒惰的同时真正挤压这个?

方案

如何使用分区函数分解您的范围序列?在 http://上有一篇关于类似问题的有趣文章www.fatvat.co.uk/2009/05/jvisualvm-and-clojure.html


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.

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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆