Hoang Truong wrote:
Hello everybody,

I am following "A Tutorial on Parallel and Concurrent Programming in Haskell" and I have a problem with making Haskell to use my multi-cores (Core 2 Quad CPU). The Haskel version I used is GHC 6.10.1, for Haskell 98. I compile my below program with command: ghc --make -threaded -debug thread0.hs, and run with: thread0 +RTS -N4 while watching the cpu usage on another terminal (by: mpstat -P ALL 1 100), but the program uses only one core of my Ubuntu Linux.
Do any of you know why or has any suggestions? Below is my program:

Why do people still insist on using forkOS? You don't need forkOS unless you need to call C libraries that use thread-local state. Otherwise, it will just reduce your performance compared to forkIO. Admittedly the documentation for forkOS has been misleading in the past, but I think the current version is pretty clear:

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#v%3AforkOS

import Control.Concurrent
import Control.Concurrent.MVar

fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)

dowork =
putStrLn ("fib 35 = " ++ (show (fib 35)))

Perhaps you were expecting "fib 35" to be repeatedly executed each time you call dowork? Laziness means it only gets evaluated once.

Cheers,
        Simon
_______________________________________________
Glasgow-haskell-users mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to