
Luke Andrew wrote:
main = do print $ zipWith (+) (fiblist2 37 `par` fiblist1 37) (fiblist2 37)
compilation & testing:
luke@Sonata:~/mcls$ ghc -O2 -threaded --make test2
luke@Sonata:~/mcls$ time ./test2 +RTS -N1 [2,2,4,6,10,16,26,42... ...405774,18454930,29860704,48315634]
real 0m15.294s user 0m15.196s sys 0m0.013s
luke@Sonata:~/mcls$ time ./test2 +RTS -N2 [2,2,4,6,10,16,26,42... ...405774,18454930,29860704,48315634]
real 0m15.268s user 0m15.169s sys 0m0.013s
This is due to lazyness: 'fiblist2 37' does not evaluate the whole resulting list, so the thread spawned by 'par' will almost immediately return. Take a look at Control.Parallel.Strategies, the 'parList' combinator is probably what you need here. To get a feel what this 'strategies' stuff is all about, it is a good idea to read (or at least skim over) the accompanying paper, just google for "Algorithm + Strategy = Parallelism". Cheers Ben