How to call stop from parallel foreach

seany seany at uni-bonn.de
Fri Jun 25 14:21:18 UTC 2021


On Friday, 25 June 2021 at 14:10:52 UTC, Ali Çehreli wrote:
> On 6/25/21 6:53 AM, seany wrote:
>
> >          [...]
> workUnitSize)) {
> > [...]
>
> Performance is not guaranteed depending on many factors. For 
> example, inserting a writeln() call in the loop would make all 
> threads compete with each other for stdout. There can be many 
> contention points some of which depending on your program 
> logic. (And "Amdahl's Law" applies.)
>
> Another reason: 1 can be a horrible value for workUnitSize. Try 
> 100, 1000, etc. and see whether it helps with performance.
>
> > [...]
> line...
> > [...]
>
> Do you still have two parallel loops? Are both with explicit 
> TaskPool objects? If not, I wonder whether multiple threads are 
> using the convenient 'parallel' function, stepping over each 
> others' toes. (I am not sure about this because perhaps it's 
> safe to do this; never tested.)
>
> It is possible that the segfaults are caused by your code. The 
> code you showed in your original post (myFunction0() and 
> others), they all work on independent data structures, right?
>
> Ali

The code without the parallel foreach works fine. No segfault.

In several instances, I do have multiple nested loops, but in 
every case. only the outer one in parallel foreach.

All of them are with explicit taskpool definition.






More information about the Digitalmars-d-learn mailing list