[Haskell] Re: Pugs gains SMP parallelism support.

Simon Marlow simonmarhaskell at gmail.com
Mon Oct 23 07:26:08 EDT 2006

Audrey Tang wrote:
> I hacked +RTS -N support into Pugs today; here's a short writeup:
>     http://pugs.blogs.com/pugs/2006/10/smp_paralleliza.html
> Pugs's current implementation for concurrent operations on lists is  
> very naive:
>             chan    <- newChan
>             forM ([0..] `zip` xs) $ \(n, x) -> forkIO $ do
>                 rv  <- runEvalIO env (reduce x)
>                 writeChan chan (n, rv)
>             fmap (map snd . sort) (replicateM (length xs) (readChan  chan))
> While the initial result on Linux 2.6 is encouraging, on OSX/Intel  with 
> two CPUs
> it actually slightly slows down the program when running on -N2 or  above.
> I wonder if there is a more efficient way doing this...

Right, it all depends on how much you're doing in each thread.  You might want 
to divide the work into larger chunks (several elements of the array) rather 
than creating a thread for every element.


More information about the Haskell mailing list