OCaml 的并行化能力状况如何?

发布于 2024-11-18 17:50:38 字数 159 浏览 0 评论 0原文

我对在项目中使用 OCaml 很感兴趣,但是我不确定它的并行化功能在哪里。 OCaml中有消息传递能力吗? OCaml 是否能够有效地使用 1 个以上的 CPU?

我读到的关于这个主题的大部分内容都是在 2002 年至 2006 年写的,我没有看到任何更新的内容。

谢谢!

I'm interested in using OCaml for a project, however I'm not sure about where its parallelization capabilities are anymore. Is there a message passing ability in OCaml? Is OCaml able to efficiently use more than 1 CPU?

Most of what I have read on the subject was written in 2002-2006, and I haven't seen anything more recent.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深巷少女 2024-11-25 17:50:38

Caml 每周新闻(“CWN”,来自caml 列表) 显示:

还有:

  • Netmulticore - 通过映射共享进行多处理共享 ocaml 值内存。

  • CamlP3l - Caml 并行程序的编译器。

  • OCaml-Java - 生成 Java 字节码的 OCaml 编译器


我最近没有关注关于 Ocaml & 的讨论不过,并行编程。 我将离开此 CW 以便其他人可以更新我的内容 如果这个问题能够达到与 Haskell 的类似内容

This 2009 issue of the Caml weekly news ("CWN", a digest of interesting messages from the caml list) shows that:

  • the official party line on threads and Ocaml hasn't changed. A notable quote:

    (...) in general, the whole standard library is not thread-safe. Probably that should be stated in the
    documentation for the threads library, but there isn't much point in documenting it per standard library module. -- X. Leroy

    (for how Ocaml threads can still be useful, see a remark by the culprit himself in another question on SO)

  • the most frequently adopted paradigm for parallelism is message-passing, and of note is X. Leroy's OcamlMPI, providing bindings for programming in SPMD style against the MPI standard. The same CWN issue I pointed to above provides references to examples, and numerous other related projects.

  • another message-passing solution is JoCaml, pioneering new style of concurrent communications known as join calculus. Note that it is binary-compatible with OCaml compilers.

  • that did not prevent the confection of a runtime whose GC is ok with parallelism, though: see a discussion of OCAML4MC in this other issue of the CWN.

There is also:

  • Netmulticore - multi-processing sharing ocaml values via mapped shared memory.

  • CamlP3l - compiler for Caml parallel programs.

  • OCaml-Java - an OCaml compiler that emits Java bytecode


I haven't followed more recent discussions about Ocaml & parallel programming, though. I'm leaving this CW so that others can update what I mention. It would be great if this question could reach the same level of completeness as the analogous one for Haskell.

心奴独伤 2024-11-25 17:50:38

目前,OCaml运行时不支持跨多个核心并行运行,因此单个OCaml进程无法利用多个核心。这不太可能直接改变; OCaml 开发人员最感兴趣的提高并行性的方向似乎是允许多个 OCaml 运行时在单个进程中并行运行;这将允许非常快速的消息传递,但不允许多个线程在共享内存配置中并行运行。主要的问题是垃圾收集器;几年前,该团队尝试了并发 GC,但它在单线程情况下导致了不可接受的速度下降。

有几个项目,即 FunctoryOCamlnet,它通过使用多个进程提供多核并行。

一般来说,OCaml 社区倾向于支持消息传递方法,这种方法可以跨进程边界完成(就像 OCamlnet 那样),而不是单进程共享内存多线程。如果您的程序可以拆分为多个进程(很多都可以!),那么您可以有效地使用多个 CPU。

At present, the OCaml runtime does not support running across multiple cores in parallel, so a single OCaml process cannot take advantage of multiple cores. This is unlikely to change directly; the direction the OCaml developers are most interested in taking for increased parallelism seems to be allowing multiple OCaml runtimes to run in parallel in a single process; this will allow for very fast message passing, but will not allow multiple threads to run in parallel in a shared-memory configuration. The major hangup is the garbage collector; some years ago, the team experimented with a concurrent GC, but it introduced unacceptable slowdowns in the single-threaded case.

There are a couple of projects, namely Functory and OCamlnet, which provide multicore-happy parallelism by using multiple processes.

In general, the OCaml community tends to favor message passing approaches, which can be done across process boundaries (like OCamlnet does), over single-process shared-memory multithreading. If your program can be split into multiple processes (many can!), then yes, you can efficiently use multiple CPUs.

白龙吟 2024-11-25 17:50:38

Ocaml 5.0(2022 年 12 月 16 日) 引入了多核支持,这意味着 OCaml支持操作系统线程上的并行执行。

另请参阅OCaml 5.0 手册中的相关文档。使用domainslib,可以支持async/await 风格的并行任务和用于直接并行执行的parallel_for - 使用共享内存并行性。

从 OCaml 5.1 开始,它仍然有一些限制,多核仅支持架构:ARM64、x86-64、RISC-V、IBM Z(请在更改时编辑此答案),并且最多仅 128 个域 - 对应 128 个操作系统线程。

Ocaml 5.0 (16 Dec 2022) introduced multicore support which means that OCaml supports parallel execution on OS threads.

See also the documentation for this in the OCaml 5.0 Manual. Using domainslib, there is support for both async/await style parallel tasks and a parallel_for for direct parallel execution - using shared memory parallelism.

As of OCaml 5.1 it still has some limitations, multicore is only supported for architectures: ARM64, x86-64, RISC-V, IBM Z (please edit this answer when this changes), and only up to 128 domains - corresponding to 128 OS threads.

慵挽 2024-11-25 17:50:38

BSMLlib 为 OCaml 中的数据并行编程提供了简化的编程接口。
它的执行相当于 BSP 风格的消息传递,但它是确定性的,甚至对于 OCaml 的子集来说是声明性的。
关键概念是“a par 类型”,它对应于一个值向量,每个进程一个。

http://traclifo.univ-orleans.fr/BSML/
http://fr.wikipedia.org/wiki/Bulk_Synchronous_Parallel_ML

盖坦·海恩斯
巴黎东部大学

BSMLlib provides a simplified programming interface for data-parallel programming in OCaml.
Its execution amounts to BSP-style message passing but it is deterministic and even declarative for a subset of OCaml.
The key concept is the 'a par type which corresponds to a vector of values, one per process.

http://traclifo.univ-orleans.fr/BSML/
http://fr.wikipedia.org/wiki/Bulk_Synchronous_Parallel_ML

Gaétan Hains
University Paris-Est

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文