How to call stop from parallel foreach

seany seany at uni-bonn.de
Thu Jun 24 20:41:40 UTC 2021


On Thursday, 24 June 2021 at 20:33:00 UTC, Bastiaan Veelo wrote:

> By the way, nesting parallel `foreach` does not make much 
> sense, as one level already distributes the load across all 
> cores (but one). Additional parallelisation will likely just 
> add overhead, and have a net negative effect.
>
> — Bastiaan.

Okey. So consider :

     foreach(array_elem; parallel(an_array)) {
       dothing(array_elem);
     }


and then in `dothing()` :

     foreach(subelem; array_elem) {

       dootherthing(subelem);
     }

- Will this ALSO cause the same overhead?

Is there any way to control the number of CPU cores used in 
parallelization ?

E.g : take 3 cores for the first parallel foreach - and then for 
the second one, take 3 cores each -> so 3 + 3 * 3 = 12 cores out 
of a 16 core system? Thank you.



More information about the Digitalmars-d-learn mailing list