如何并发是Prolog? [英] How Concurrent is Prolog?

查看:176
本文介绍了如何并发是Prolog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在线上找不到任何资讯...我也是Prolog的新用户...

我Prolog可能是高度并发,也许尝试许多可能性时,尝试匹配一个规则。现代Prolog编译器/解释器本质上是否并发?哪一个?默认情况下是否启用并发?我需要以某种方式启用它吗?

It seems to me that Prolog could be highly concurrent, perhaps trying many possibilities at once when trying to match a rule. Are modern Prolog compilers/interpreters inherently* concurrent? Which ones? Is concurrency on by default? Do I need to enable it somehow?

*我对多线程感兴趣,只是固有的并发。

* I am not interested in multi-threading, just inherent concurrency.

推荐答案

在理论上看起来很有吸引力,但是有很多问题使得这样的实现看起来不明智。

In theory that seems attractive, but there are various problems that make such an implementation seem unwise.


  • 即使在Prolog中编程,人们习惯于将程序视为执行从左到右和自上而下。谓词和子句中的术语的子句的顺序在标准Prolog中在语义上是有意义的。并行化它们会改变过多的代码变得流行的行为。

  • for better or worse, people are used to thinking of their programs as executing left-to-right and top-down, even when programming in Prolog. Both the order of clauses for a predicate and of terms within a clause is semantically meaningful in standard Prolog. Parallelizing them would change the behaviour of far too much exising code to become popular.

非关系语言元素,例如cut操作符只能被有意义地使用除非发明了非常复杂的依赖性跟踪。

non-relational language elements such as the cut operator can only be meaningfully be used when you can rely on such execution orders, i.e. they would become unusable in a parallel interpreter unless very complicated dependency tracking were invented.

所有现有的并行解决方案都会导致

all existing parallelization solutions incur at least some performance overhead for inter-thread communication.

Prolog通常用于高级深度递归问题,如图遍历,定理证明等。在现代机器上(理想地)对于一些常数 n 可以实现 n 的加速,递归解法成为可行的方法,因为这将需要指数加速。相比之下,Fortran和C程序员通常解决的数值问题通常具有高但是相当有限的计算成本;非常值得并行化的努力将10小时的工作变成1小时的工作。相比之下,将一个可以将6个移动的程序转换为可以(平均)看起来6.5个移动的程序并不令人信服。

Prolog is typically used for high-level, deeply recursive problems such as graph traversal, theorem proving etc. Parallelization on a modern machines can (ideally) achieve a speedup of n for some constant n, but it cannot turn an unviable recursive solution method into a viable one, because that would require an exponential speedup. In contrast, the numerical problems that Fortran and C programmers usually solve typically have a high but quite finite cost of computation; it is well worth the effort of parallelization to turn a 10-hour job into a 1-hour job. In contrast, turning a program that can look about 6 moves ahead into one that can (on average) look 6.5 moves ahead just isn't as compelling.

这篇关于如何并发是Prolog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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