Closed artempyanykh closed 2 years ago
Hi @artempyanykh, Task.parallel_for
should be enclosed with a Task.run
, as mentioned here: https://github.com/ocaml-multicore/domainslib/blob/master/lib/task.mli#L37-L40. Your code snippet would then be:
open Domainslib
let () =
let n_workers = 4 in
let pool = Task.setup_pool ~num_domains:(n_workers - 1) () in
Task.run pool (fun () -> Task.parallel_for pool ~start:0 ~finish:5 ~body:(fun _idx -> ()));
Printf.printf "Main done";
()
Thanks for clarifying @Sudha247! This answers my question. I wonder, though, if the exception could be more specific rather than just Unhandled
? Having an exception pointing to the fact a task has to be enclosed in run
could help great with understandability/debuggability.
I'm running ocaml5~alpha1 with flambda on an Apple M1. The code below consistently crashes with the following exception:
The code (file:
domain_pool.ml
):The error manifests both with the currently released version in opam and when pinning to the latest dev.