Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Does a parallel map function exist in Domainslib? #117

Open
tjazerzen opened this issue Jul 25, 2023 · 2 comments
Open

Question: Does a parallel map function exist in Domainslib? #117

tjazerzen opened this issue Jul 25, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@tjazerzen
Copy link

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)?

@tjazerzen tjazerzen changed the title Does a parallel map function exist in Domainslib? Question: Does a parallel map function exist in Domainslib? Jul 25, 2023
@Sudha247
Copy link
Contributor

Sudha247 commented Aug 1, 2023

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.

@tjazerzen
Copy link
Author

tjazerzen commented Aug 1, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants