[Haskell-cafe] Re[5]: Parallel combinator, performance advice
Bulat Ziganshin
bulat.ziganshin at gmail.com
Tue Apr 7 12:10:43 EDT 2009
Hello Bulat,
Tuesday, April 7, 2009, 7:50:08 PM, you wrote:
>> parallel_ (x1:xs) = do
>> sem <- newQSem $ 1 - length xs
>> forM_ xs $ \x ->
>> writeChan queue (x >> signalQSem sem, False)
>> x1
>> addWorker
>> waitQSem sem
>> writeChan queue (signalQSem sem, True)
>> waitQSem sem
> Neil, executing x1 directly in parallel_ is incorrect idea.
forget this. but it still a bit suboptimal: after everything was
finished, we schedule one more empty job and wait while some worker
thread will pick up it. it will go into Chan after all jobs scheduled
at the time our jobs was executed so that we are doing here is
eventually don't do any internal activity while we have all N external
programs running
instead, my solution packed this flag together with last job so once
last job is finished we are immediately returned from parallel_ so
other internal activity may go on
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list