[Haskell-cafe] Re: Problem getting code from AFP08 parallel tutorial to run in parallel

Olivier Boudry olivier.boudry at gmail.com
Thu Nov 27 06:58:57 EST 2008


On Tue, Nov 25, 2008 at 11:07 PM, Don Stewart <dons at galois.com> wrote:
> What does the code look like?

It looks like that. Of course it doesn't compute the same number as
the initial code, but it starts 3 sparks and I get the expected 100%
CPU usage instead of 50%.

    parSumFibEuler :: Int -> Int -> Int -> Int
    parSumFibEuler a b c
      = f `par` (e `par` (g `pseq` (f + e + g)))
        where
          f = fib a
          e = sumEuler b
          g = sumEuler c

    r1 :: Int
    r1 = parSumFibEuler 40 7450 7449

Instead of:

    parSumFibEuler :: Int -> Int -> Int
    parSumFibEuler a b
      = f `par` (e `pseq` (f + e))
        where
          f = fib a
          e = sumEuler b

    r1 :: Int
    r1 = parSumFibEuler 40 7450

Olivier.


More information about the Haskell-Cafe mailing list