
Hi, I tried the first example from "A tutorial on Parallel and Concurrent programming in Haskell" but I cant seem to get sparks to get converted to OS threads. Below is the program I am using. I did ghc --make -threaded program.hs then ./program +RTS -N2 I don't see any speed gain compared to N1. Am I missing something? import System.Time import Control.Parallel fib :: Int -> Int fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) mkList :: Int -> [Int] mkList n = [1..n-1] relPrime :: Int -> Int -> Bool relPrime x y = gcd x y == 1 euler :: Int -> Int euler n = length (filter (relPrime n) (mkList n)) sumEuler :: Int -> Int sumEuler = sum . (map euler) . mkList sumFibEuler :: Int -> Int -> Int sumFibEuler a b = fib a + sumEuler b parSumFibEuler :: Int -> Int -> Int parSumFibEuler a b = f `par` (e `pseq` (e + f)) where f = fib a e = sumEuler b secDiff :: ClockTime -> ClockTime -> Float secDiff (TOD secs1 psecs1) (TOD secs2 psecs2) = fromInteger (psecs2 - psecs1) / 1e12 + fromInteger (secs2 - secs1) r1 :: Int r1 = sumFibEuler 38 5300 main :: IO () main = do t0 <- getClockTime pseq r1 (return()) t1 <- getClockTime putStrLn ("Sum: " ++ show r1) putStrLn ("time: " ++ show (secDiff t0 t1) ++ " seconds")

On Thursday 17 February 2011 17:02:55, C K Kashyap wrote:
Hi, I tried the first example from "A tutorial on Parallel and Concurrent programming in Haskell" but I cant seem to get sparks to get converted to OS threads.
Below is the program I am using. I did ghc --make -threaded program.hs then ./program +RTS -N2 I don't see any speed gain compared to N1. Am I missing something?
Hmm, using parSumFibEuler instead of sumFibEuler, I get > 100% CPU usage (close to 200% if I adjust parameters so both computations take approximately the same time). Works for me, then.

From: C K Kashyap
Hi, I tried the first example from "A tutorial on Parallel and Concurrent programming in Haskell" but I cant seem to get sparks to get converted to OS threads.
Below is the program I am using. I did ghc --make -threaded program.hs then ./program +RTS -N2 I don't see any speed gain compared to N1. Am I missing something?
If you are using ghc 7.01, you need to compile with -rtsopts for the compiled program to parse +RTS options. I don't know of any way to provide a default value at compile time. http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/runtime-control.... Also, in general a program might not run faster with speculation, so if you want to check if several threads are used, check if CPU time used is over 100%. Brandon

On 17/02/2011 05:20 PM, Brandon Moore wrote:
If you are using ghc 7.01, you need to compile with -rtsopts for the compiled program to parse +RTS options.
That's true.
I don't know of any way to provide a default value at compile time.
That would be -with-rtsopts="-N2" (or whatever) http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/runtime-control.... But note that with GHC 7.x, the RTS *automatically* chooses the correct number of threads now. You no longer need to specify this manually (unless you specifically want to use some other number of threads for some reason).

But note that with GHC 7.x, the RTS *automatically* chooses the correct number of threads now. You no longer need to specify this manually (unless you specifically want to use some other number of threads for some reason). Is that stated in the changelog or documentation somewhere? Do you still have to specify -threaded at compile-time? (Sorry for the dup Andrew, missed the 'reply all' button :\)
-- Edward Amsden Undergraduate Computer Science Rochester Institute of Technology www.edwardamsden.com

On 19/02/2011 04:57 PM, Edward Amsden wrote:
But note that with GHC 7.x, the RTS *automatically* chooses the correct number of threads now. You no longer need to specify this manually (unless you specifically want to use some other number of threads for some reason). Is that stated in the changelog or documentation somewhere? Do you still have to specify -threaded at compile-time?
You most definitely have to specify -threaded at compile-time; that selects the threaded RTS. (Otherwise you get the non-threaded RTS, which *always* uses 1 thread.) This much was always true; what is new is that the threaded RTS used to default to still using only 1 thread. Now it defaults to using a number of threads that is determined by how many CPU cores you actually have. (I'm not sure if it uses N cores or N-1 cores; I seem to recall that using *all* cores caused a slowdown on some systems. I don't know if that's fixed now...) I don't see this mentioned in the release notes, but it's definitely in the RTS flags documentation. http://haskell.org/ghc/docs/7.0.1/html/users_guide/using-smp.html#parallel-o...

For what it's worth, you can also use GHC.Conc.Sync.numCapabilities to find out how many cores are actually being used, if you wanted to check. (I thought this was also exported from Control.Concurrent, but apparently not...)
participants (5)
-
Andrew Coppin
-
Brandon Moore
-
C K Kashyap
-
Daniel Fischer
-
Edward Amsden