ocaml-multicore/domainslib

Question: Does a parallel map function exist in Domainslib?

tjazerzen opened this issue · 2 comments

Hello Domainslib maintainers,

I'm currently using the Domainslib library in my OCaml project, and I wanted to use a parallel map function. However, I could not find such a function in the library.

Does a parallel map exist in this library? If not, which implementation would you suggest instead (for example, Parany's)?

Hi @tjazerzen,

One can do a naive version of parallel_map with a parallel_for.

let parallel_map f arr pool =
  let len = Array.length arr in
  let res = Array.make len (f arr.(0)) in
  Domainslib.Task.parallel_for pool ~start:0 ~finish:(len - 1)
  ~body:(fun i -> res.(i) <- (f arr.(i)));
  res

You can also take a look at the parallel map in MPLLang's benchmark suite.

Parany supports parallel map indeed. Although, the latest release of Parany doesn't use shared memory parallelism, but uses Unix fork to spawn new processes. This may work for certain type of jobs, but if you want to use OCaml 5 features in your project I'd suggest going with one of the above two options.

Thank you!