[Haskell-cafe] Using parallels for fibonacci

Michael Litchard michael at schmong.org
Tue May 10 16:39:20 UTC 2016


I am trying to efficiently use multicores for my fizzbuzz
<https://github.com/mlitchard/swiftfizz> project. My fizzbuzz uses a
Fibonacci generator as input, and this is where it can get computationally
heavy. I believe I have picked the best algorithm for my project (please
correct this if wrong), and now I am trying to use the parallel package
<https://hackage.haskell.org/package/parallel-3.2.1.0>. I am not getting
any better performance in the sense that if I try to compute the 100th
Fibonacci number, it is still computing , using 4 cores, several minutes
later.

Here is my attempt. Please show me how to use this library right.

from src/FizzBuzz.hs

fizzBuzzFib :: Integer -> [Text]
fizzBuzzFib ub = parMap rdeepseq fizzbuzz $! fibSeq ub

from src/FizzFub.hs

fibSeq :: Integer -> [Integer]
fibSeq ub =
withStrategy (parBuffer buffer rdeepseq) $ genericTake ub fibbwhere
  buffer = 100

fibb :: [Integer]
fibb = 0 : 1 : zipWith (+) fibb (tail fibb)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160510/d7020b00/attachment.html>


More information about the Haskell-Cafe mailing list