parallel program in haskell in 5 steps
In step 4 of Haskell in 5 Steps [ http://haskell.org/haskellwiki/Haskell_in_5_steps], a parallel program is given. I changed it very slightly so it would run a long time (see below). It compiles and runs but my CPU meter is barely above 50%. I have a dual core processor. What in the world would keep this program from completely saturating the CPU? import Control.Parallel main = a `par` b `pseq` print (a + b) where a = ack 4 10 b = ack 4 10 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)
How are you running the program? You have to explicitly tell the compiler/interpreter to use multiple system threads. Michael On Tue, May 5, 2009 at 10:19 PM, Jack Kennedy <jack@realmode.com> wrote:
In step 4 of Haskell in 5 Steps [ http://haskell.org/haskellwiki/Haskell_in_5_steps], a parallel program is given. I changed it very slightly so it would run a long time (see below).
It compiles and runs but my CPU meter is barely above 50%. I have a dual core processor. What in the world would keep this program from completely saturating the CPU?
import Control.Parallel
main = a `par` b `pseq` print (a + b) where a = ack 4 10 b = ack 4 10
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)
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
I am compiling (Windows by the way) using the line from the tutorial: ghc -O2 --make par.hs -threaded and running with the line par +RTS -N2 CPU usage for the process flits around a little, but stays in the 45% - 55% range. On Tue, May 5, 2009 at 12:51 PM, Michael Snoyman <michael@snoyman.com>wrote:
How are you running the program? You have to explicitly tell the compiler/interpreter to use multiple system threads.
Michael
On Tue, May 5, 2009 at 10:19 PM, Jack Kennedy <jack@realmode.com> wrote:
In step 4 of Haskell in 5 Steps [ http://haskell.org/haskellwiki/Haskell_in_5_steps], a parallel program is given. I changed it very slightly so it would run a long time (see below).
It compiles and runs but my CPU meter is barely above 50%. I have a dual core processor. What in the world would keep this program from completely saturating the CPU?
import Control.Parallel
main = a `par` b `pseq` print (a + b) where a = ack 4 10 b = ack 4 10
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)
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
Does this happen for everyone, or just me? On Tue, May 5, 2009 at 2:05 PM, Jack Kennedy <jack@realmode.com> wrote:
I am compiling (Windows by the way) using the line from the tutorial: ghc -O2 --make par.hs -threaded
and running with the line
par +RTS -N2
CPU usage for the process flits around a little, but stays in the 45% - 55% range.
On Tue, May 5, 2009 at 12:51 PM, Michael Snoyman <michael@snoyman.com>wrote:
How are you running the program? You have to explicitly tell the compiler/interpreter to use multiple system threads.
Michael
On Tue, May 5, 2009 at 10:19 PM, Jack Kennedy <jack@realmode.com> wrote:
In step 4 of Haskell in 5 Steps [ http://haskell.org/haskellwiki/Haskell_in_5_steps], a parallel program is given. I changed it very slightly so it would run a long time (see below).
It compiles and runs but my CPU meter is barely above 50%. I have a dual core processor. What in the world would keep this program from completely saturating the CPU?
import Control.Parallel
main = a `par` b `pseq` print (a + b) where a = ack 4 10 b = ack 4 10
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)
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
Hello Jack, according to the source code your program should not run for a long time. If you're using GHC, use the '-threaded' flag when compiling and also pass the parameters '+RTS -N2' to your program to let it run with two parallel threads. However, my experience is that the pure parallel constructs are currently not really suitable for real world programs. With my dual core processor I get the expected ~190% CPU time using explicit parallelism using concurrency (i.e. forkIO and MVars), whereas with pure constructs like the ones from Control.Parallel and Control.Parallel.Strategies I get only about 140%. Greets, Ertugrul. Jack Kennedy <jack@realmode.com> wrote:
In step 4 of Haskell in 5 Steps [ http://haskell.org/haskellwiki/Haskell_in_5_steps], a parallel program is given. I changed it very slightly so it would run a long time (see below).
It compiles and runs but my CPU meter is barely above 50%. I have a dual core processor. What in the world would keep this program from completely saturating the CPU?
import Control.Parallel
main = a `par` b `pseq` print (a + b) where a = ack 4 10 b = ack 4 10
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)
-- nightmare = unsafePerformIO (getWrongWife >>= sex) http://blog.ertes.de/
participants (4)
-
Ertugrul Soeylemez -
Jack Kennedy -
Michael Snoyman -
Sean Bartell