Multicore Ocaml: parallel_for

I am working on a project in which I am using the OCaml language and I am using the parallel_for for parallel execution, now I have created a pool of domains and they will read the content of the array and print the output in any order, now my requirement is that wherever any of the domain from the pool gets the negative value, then-current domain and all the other domains should not proceed further i.e they should not take next index of the array, just terminate their execution. and also I want to use the same pool again.

Thanks

There is no function to do what you want in Domainslib, so you need to implement it using async. You just need to divide your array into chunks (the simplest way is to choose the chunk size to be the length of the array divided by the number of domains in the pool, but you run the risk of poor work sharing of one of the chunks is longer to process than the other, so smaller chunks may be better), and for each chunk spawn an async task to do the work.

To make the workers stop when a negative value has been encountered, a solution I see is to use an atomic flag that will be set to true once that happens, and that should be checked before every operation. But maybe someone will have a more efficient proposal.