简体   繁体   English

命令与功能 - 了解冯诺依曼的瓶颈

[英]Imperative vs Functional - understanding the von Neumann bottleneck

In the Coursera course - Functional Programming in Scala - Martin Odersky talks about how Imperative Programming is constrained by the von Neumann bottleneck because it deals largely with mutable state and also, therefore, assignment and de-referencing. 在Coursera课程 - Scala中的函数式编程--Martin Odersky谈论了命令式编程如何受冯诺依曼瓶颈的约束,因为它主要处理可变状态,因此也分配了指派和解引用。

The von Neumann bottleneck being the latency involved in reading/writing data between the processor and memory. 冯·诺伊曼的瓶颈是在处理器和存储器之间读/写数据所涉及的延迟。

I am struggling to understand 2 things and am hoping someone can help shed some light on it:- 我正在努力理解两件事,我希望有人可以帮助解释它: -

  1. If we only used immutable objects when writing a Scala program - then we still have assignment when we initialize an immutable object with data when we construct it, but not further re-assignment. 如果我们在编写Scala程序时只使用了不可变对象 - 那么当我们构造一个带有数据的不可变对象时,我们仍然会进行赋值,但不能进一步重新赋值。 When we want to de-reference an immutable object, then there will still be the chance that it no longer exists in cache and will have to be fetched again from main memory -> latency. 当我们想要取消引用不可变对象时,它仍然有可能在缓存中不再存在,并且必须再次从主内存中获取 - >延迟。

    I'm struggling to understand how using immutable data structures helps with the von Neumann bottleneck. 我正在努力理解使用不可变数据结构如何帮助冯诺依曼瓶颈。 Can anyone help me appreciate the cases where it does? 任何人都可以帮助我欣赏它的情况吗?

  2. In his course lecture, Martin Odersky states the following while talking about the von Neumann bottleneck:- 在他的课程讲座中,Martin Odersky在谈到冯诺依曼瓶颈时说了以下几点:

    Imperative programming conceptualises programs word for word which becomes a problem for scalability since we are dealing with data structures at too low a level. 命令式编程逐字逐句地概念化程序,这成为可伸缩性的问题,因为我们处理的数据结构太低了。 Functional programming languages (in general) tend to focus on defining theories and techniques for working with higher-level abstractions such as collections , polynomials , documents etc. 函数式编程语言(通常)倾向于关注定义用于处理更高级抽象的理论和技术,例如collectionspolynomialsdocuments等。

    I understand that using higher-level abstractions can really help a developer scale the efficiency of their development work, but how do abstractions help address the von Neumann bottleneck? 我知道使用更高级别的抽象可以真正帮助开发人员扩展他们的开发工作的效率,但抽象如何帮助解决von Neumann的瓶颈?

You need to read the original paper published by John Backs "Can Programming Be liberated from the Von Neumann Style? A functional style and its algebra of programs". 你需要阅读John Backs发表的原始论文“可以从冯·诺依曼风格中解放出来的程序设计?功能风格及其程序代数”。 It basically talks about two kinds of bottlenecks one which is physical hardware limitations and the other which is a kind of conceptual bottleneck formed due to the way programmers think of languages. 它基本上讨论了两种瓶颈,一种是物理硬件限制,另一种是由于程序员对语言的思考方式而形成的一种概念瓶颈。 On your second question. 关于你的第二个问题。 As earlier languages were more closer to the respective hardware implementations the programmer thinking used to be mimic the sequential flow of events. 由于早期的语言更接近相应的硬件实现,程序员的思维过去常常模仿事件的顺序流。 Functional languages give us a new way to look at programs wherein parallel executions or operations on a set of data work. 函数式语言为我们提供了一种新的方式来查看程序,其中对一组数据的并行执行或操作起作用。

On the first question I would like to iterate a comment from wiki.c2.com 关于第一个问题,我想重复wiki.c2.com的评论

"What does the choice of programming language have on the hardware? A functional language which is compiled to run on a von Neumann machine will still suffer the bottleneck." “编程语言的选择在硬件上有什么作用?编译为在冯·诺依曼机器上运行的函数式语言仍然会遇到瓶颈。” The answer, is ReferentialTransparency--which makes parallel computation much more tractable (and capable of being automated). 答案是ReferentialTransparency - 这使得并行计算更容易处理(并且能够自动化)。 Effectively parallelizing imperative languages is still an active research topic. 有效地并行化命令式语言仍然是一个活跃的研究课题。

http://wiki.c2.com/?CanProgrammingBeLiberatedFromTheVonNeumannStyle http://wiki.c2.com/?CanProgrammingBeLiberatedFromTheVonNeumannStyle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM