Showing >100% CPU usage of parallel code

Hi, I copied the program below from a reddit post of dons'. I have a dual core laptop with ubuntu hardy and ghc 6.10.1. I can see the difference when I run the program with +RTS -N2 but CPU always says 100%. I'd like an example that shows >100 -- is it not showing >100 because of my timeformat or because of the program? If it's the latter can you point me to an example that will use more cpu? Here's the output: $ cat /proc/cpuinfo | grep processor | wc -l 2 $ export TIMEFORMAT="%E real,%U user,%S sys, %P cpu" $ ghc -O2 --make Par.hs -threaded $ time ./Par 1405006117752879898543142606244511569936384005711076 2.330 real,2.328 user,0.000 sys, 99.92 cpu $ time ./Par +RTS -N2 1405006117752879898543142606244511569936384005711076 1.504 real,2.316 user,0.016 sys, 100.00 cpu Here's the program: ---------------- import Control.Parallel main = a `par` b `par` c `pseq` print (a + b + c) where a = ack 3 10 b = fac 42 c = fib 34 fac 0 = 1 fac n = n * fac (n-1) ack 0 n = n+1 ack m 0 = ack (m-1) 1 ack m n = ack (m-1) (ack m (n-1)) fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) -------------------- Thanks, Jim -- View this message in context: http://www.nabble.com/Showing-%3E100--CPU-usage-of-parallel-code-tp22137081p... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Hello Jim, Saturday, February 21, 2009, 6:17:54 PM, you wrote:
main = a `par` b `par` c `pseq` print (a + b + c)
two things: 1) that are grouping order? may be, a `par` (b `par` (c `pseq` print (a + b + c))) ? 2) i recommend you to use 2 *same* computations. otherwise, it's easily possible that one of them needs much more time that the rest
where a = ack 3 10 b = fac 42 c = fib 34
fac 0 = 1 fac n = n * fac (n-1)
ack 0 n = n+1 ack m 0 = ack (m-1) 1 ack m n = ack (m-1) (ack m (n-1))
fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) --------------------
Thanks,
Jim
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Jim, I'm actually not sure that time will report greater than 100% cpu
on ubuntu hardy. (really not sure, and don't have it available right
this moment to check). I would however try making a computation that
will take a little longer and use the system monitor or /proc to look
at your CPU usage rather than time. I've had good luck with GHC 6.8
using > 100% cpu, so I assume 6.10 will work much better.
On Sat, Feb 21, 2009 at 10:32 AM, Bulat Ziganshin
Hello Jim,
Saturday, February 21, 2009, 6:17:54 PM, you wrote:
main = a `par` b `par` c `pseq` print (a + b + c)
two things: 1) that are grouping order? may be, a `par` (b `par` (c `pseq` print (a + b + c))) ?
2) i recommend you to use 2 *same* computations. otherwise, it's easily possible that one of them needs much more time that the rest
where a = ack 3 10 b = fac 42 c = fib 34
fac 0 = 1 fac n = n * fac (n-1)
ack 0 n = n+1 ack m 0 = ack (m-1) 1 ack m n = ack (m-1) (ack m (n-1))
fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) --------------------
Thanks,
Jim
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Jeff Heard wrote:
Jim, I'm actually not sure that time will report greater than 100% cpu on ubuntu hardy. (really not sure, and don't have it available right this moment to check). I would however try making a computation that will take a little longer and use the system monitor or /proc to look at your CPU usage rather than time. I've had good luck with GHC 6.8 using > 100% cpu, so I assume 6.10 will work much better.
Hi, thanks for that. The system monitor shows that I get ~160% usage, but like you I don't know if it's possible to get time to display that (on hardy, it clearly does elsewhere). The system monitor GUI is good enough, if less neat than showing it via time. Jim
On Sat, Feb 21, 2009 at 10:32 AM, Bulat Ziganshin
wrote: Hello Jim,
Saturday, February 21, 2009, 6:17:54 PM, you wrote:
main = a `par` b `par` c `pseq` print (a + b + c)
two things: 1) that are grouping order? may be, a `par` (b `par` (c `pseq` print (a + b + c))) ?
2) i recommend you to use 2 *same* computations. otherwise, it's easily possible that one of them needs much more time that the rest
where a = ack 3 10 b = fac 42 c = fib 34
fac 0 = 1 fac n = n * fac (n-1)
ack 0 n = n+1 ack m 0 = ack (m-1) 1 ack m n = ack (m-1) (ack m (n-1))
fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) --------------------
Thanks,
Jim
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/Showing-%3E100--CPU-usage-of-parallel-code-tp22137081p... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

On Sat, Feb 21, 2009 at 12:17 PM, Jim Burton
$ time ./Par +RTS -N2 1405006117752879898543142606244511569936384005711076 1.504 real,2.316 user,0.016 sys, 100.00 cpu
I don't know why it is only 100%, but you can see that the user time is greater than real time, so everything is working on GHC's side. You may also use -sstderr to see some more info. HTH, -- Felipe.
participants (4)
-
Bulat Ziganshin
-
Felipe Lessa
-
Jeff Heard
-
Jim Burton