Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the state of OCaml's parallelization abilities?

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!

like image 364
Andrew Spott Avatar asked Jul 05 '11 20:07

Andrew Spott


People also ask

Is OCaml multicore?

Multicore OCaml is an extension of OCaml with native support for Shared-Memory Parallelism (SMP) through Domains and Concurrency through Algebraic Effects . It is merged to trunk OCaml. OCaml 5.0 will be the first release to officially support Multicore.

What can be parallelized in a program?

In parallel programming, tasks are parallelized so that they can be run at the same time by using multiple computers or multiple cores within a CPU. Parallel programming is critical for large scale projects in which speed and accuracy are needed.


2 Answers

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.

like image 140
10 revs, 2 users 82% Avatar answered Nov 11 '22 03:11

10 revs, 2 users 82%


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.

like image 42
Michael Ekstrand Avatar answered Nov 11 '22 05:11

Michael Ekstrand