[Haskell-cafe] Parallelism on concurrent?

Pepe Iborra mnislaih at gmail.com
Tue Mar 13 13:00:44 EDT 2007


On 13/03/2007, at 17:46, Jefferson Heard wrote:

> Simon will probably chime in on it as well, but his paper on the  
> subject is
> the best there is:
>
> http://research.microsoft.com/~simonpj/Papers/strategies.ps.gz

It does work in GHC 6.6 very nicely.
You can try it with the following naive fib function, extracted from  
the paper mentioned above:

\begin{code}
import Control.Parallel
import System.Environment
import Fib

main = do
    (x:_) <- getArgs
    print$ pfib (read x)

pfib 0 = 1
pfib 1 = 1
pfib n = n1 `par` n2 `seq` n1+n2+1
   where (n1,n2) = (pfib(n-1), pfib(n-2))
\end{code}

pep:~/code/snippets/Parallelism$ ghc --make -O Main -threaded

pep:~/code/snippets/Parallelism$ time src/Main 33
11405773

real    0m1.444s
user    0m1.343s
sys     0m0.020s

pep:~/code/snippets/Parallelism$ time src/Main 33 +RTS -N2
11405773

real    0m0.764s
user    0m1.367s
sys     0m0.030s



Got a speedup of 100%, and didn't use threads at all. Yay!

pepe



More information about the Haskell-Cafe mailing list