parallel
    anonymous via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Thu Nov  5 13:10:15 PST 2015
    
    
  
On 05.11.2015 21:52, Handyman wrote:
> On Thursday, 5 November 2015 at 20:45:25 UTC, Ali Çehreli wrote:
>> That's still 1 second per task. The function prepare() cannot be
>> executed by more than one core.
>
> Thanks.  OK.  So 'prepare' is atomic?  Then let's turn it around: how
> can I make the cores prepare a meal of 5 dishes in 1.25 secs?   Should I
> rewrite, or split, 'prepare'?
>
>
You'd have to split `prepare` further into parallelizable parts. In a 
real world scenario that may or may not be possible.
When the goal is just sleeping we can do it, of course. Just do another 
`parallel` loop in `prepare`:
     import std.range: iota;
     foreach (i; parallel(iota(50))) Thread.sleep(20.msecs);
This won't get you down to exactly 1.25 seconds, because the 
start/finish print outs still take some time, and because of 
parallelization overhead.
    
    
More information about the Digitalmars-d-learn
mailing list