[Haskell-cafe] Re: Can't seem to get `par` working appropriately
with lists
Ben Franksen
ben.franksen at online.de
Thu Feb 21 19:13:10 EST 2008
Luke Andrew wrote:
> main = do print $ zipWith (+) (fiblist2 37 `par` fiblist1 37)
> (fiblist2 37)
>
> compilation & testing:
>
> luke at Sonata:~/mcls$ ghc -O2 -threaded --make test2
>
> luke at 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 at 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
More information about the Haskell-Cafe
mailing list