Haskell parallel computing

When I run this Haskell fragment, it only gets 1 loaded CPU. Both f and g do not make sense, but should they not load two processors when they are available? Compiled as ghc -O2 snippet.hs .

 fx = 1 + (f $! x) gx = 5 + (g $! x) z = a `par` b `seq` a+b where a = f 3 b = g 5 main = do print z 
+8
parallel-processing haskell ghc
source share
1 answer

You need to compile using the threaded option, i.e. ghc -O2 -threaded snippet.hs , and then pass the number of cores on the command line to the executable, as shown below for the four cores:

 ./snippet +RTS -N4 

Or you can force the machine to select the number of cores with only -N .

See http://www.haskell.org/haskellwiki/Haskell_for_multicores

+9
source share

All Articles