2011/5/26 michael rice <[email protected]>
> Thank, Daniel
>
> Multiple threads are in evidence in my system monitor, but I wonder why I'm
> getting two different answers, one twice the other. The first is the
> parallel solution and the second is the non.
>
Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the
non-parallel one ?
>
> Michael
>
> ===========
>
> {-
> import Control.Parallel
>
> nfib :: Int -> Int
> nfib n | n <= 1 = 1
> | otherwise = par n1 (pseq n2 (n1 + n2 + 1))
> where n1 = nfib (n-1)
> n2 = nfib (n-2)
> -}
>
> nfib :: Int -> Int
> nfib n | n <= 1 = 1
> | otherwise = nfib (n-1) + nfib (n-2)
>
> main = do putStrLn $ show $ nfib 39
>
> =============
>
> [michael@hostname ~]$ ghc --make -threaded nfib.hs
> [1 of 1] Compiling Main ( nfib.hs, nfib.o )
> Linking nfib ...
> [michael@hostname ~]$ ./nfib +RTS -N3
> 204668309
> [michael@hostname ~]$ ghc --make nfib.hs
> [1 of 1] Compiling Main ( nfib.hs, nfib.o )
> Linking nfib ...
> [michael@hostname ~]$ ./nfib
> 102334155
> [michael@hostname ~]$
>
>
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe