为什么在Haskell中没有隐式并行性? [英] Why is there no implicit parallelism in Haskell?

查看:245
本文介绍了为什么在Haskell中没有隐式并行性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Haskell功能和纯粹,因此基本上它具有编译器所需的所有属性,能够处理隐式并行性

Haskell is functional and pure, so basically it has all the properties needed for a compiler to be able to tackle implicit parallelism.

考虑一下这个例子:

f = do
  a <- Just 1
  b <- Just $ Just 2
  -- ^ The above line does not utilize an `a` variable, so it can be safely
  -- executed in parallel with the preceding line
  c <- b
  -- ^ The above line references a `b` variable, so it can only be executed
  -- sequentially after it
  return (a, c)
  -- On the exit from a monad scope we wait for all computations to finish and 
  -- gather the results

执行计划可以描述为:

               do
                |
      +---------+---------+
      |                   |
  a <- Just 1      b <- Just $ Just 2
      |                   |
      |                 c <- b
      |                   |
      +---------+---------+
                |
           return (a, c)

为什么在编译器中没有实现这样的功能一个标志还是一个pragma呢?有什么实际原因?

Why is there no such functionality implemented in the compiler with a flag or a pragma yet? What are the practical reasons?

推荐答案

这是一个长期研究的主题。虽然你可以隐式地导出Haskell代码中的并行性,但问题是对于当前的硬件来说,太多的并行性,太细粒度了。

This is a long studied topic. While you can implicitly derive parallelism in Haskell code, the problem is that there is too much parallelism, at too fine a grain, for current hardware.

因为我们没有无限的并行硬件,它是关于选择正确的粒度 - 太
粗糙,并且将有空闲的处理器,太精简和开销
将是不可接受的。

Since we don't have infinite parallel hardware, it is all about picking the right granularity -- too coarse and there will be idle processors, too fine and the overheads will be unacceptable.

我们有更粗粒度的并行(火花)数千或数百万个并行任务(因此不在指令级别),它们映射到我们目前通常可用的少数核心。

What we have is more coarse grained parallelism (sparks) suitable for generating thousands or millions of parallel tasks (so not at the instruction level), which map down onto the mere handful of cores we typically have available today.

请注意,对于某些子集(例如数组处理),存在具有严格成本模型的全自动并行化库。

Note that for some subsets (e.g. array processing) there are fully automatic parallelization libraries with tight cost models.

有关这方面的背景,请参阅 http://research.microsoft.com/en-us/um/people/tharris/papers/2007-fdip.pdf < a>,其中他们引入了在任意Haskell程序中插入 par 的自动方法。

For background on this see, http://research.microsoft.com/en-us/um/people/tharris/papers/2007-fdip.pdf , where they introduce an automated approach to the insertion of par in arbitrary Haskell programs.

这篇关于为什么在Haskell中没有隐式并行性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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