[Haskell-cafe] Re: Can't seem to get `par` working appropriately with lists
Luke Andrew wrote: main = do print $ zipWith (+) (fiblist2 37 `par` fiblist1 37) (fiblist2 37) compilation testing: [EMAIL PROTECTED]:~/mcls$ ghc -O2 -threaded --make test2 [EMAIL PROTECTED]:~/mcls$ time ./test2 +RTS -N1 [2,2,4,6,10,16,26,42......405774,18454930,29860704,48315634] real0m15.294s user0m15.196s sys 0m0.013s [EMAIL PROTECTED]:~/mcls$ time ./test2 +RTS -N2 [2,2,4,6,10,16,26,42......405774,18454930,29860704,48315634] real0m15.268s user0m15.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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Can't seem to get `par` working appropriately with lists
ben.franksen: Luke Andrew wrote: main = do print $ zipWith (+) (fiblist2 37 `par` fiblist1 37) (fiblist2 37) compilation testing: [EMAIL PROTECTED]:~/mcls$ ghc -O2 -threaded --make test2 [EMAIL PROTECTED]:~/mcls$ time ./test2 +RTS -N1 [2,2,4,6,10,16,26,42......405774,18454930,29860704,48315634] real0m15.294s user0m15.196s sys 0m0.013s [EMAIL PROTECTED]:~/mcls$ time ./test2 +RTS -N2 [2,2,4,6,10,16,26,42......405774,18454930,29860704,48315634] real0m15.268s user0m15.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. or 'rnf' on the result. rnf x `par` y is the basic fully strict strategy. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe