Dominik Luecke wrote:

I am trying to use the code rels list = let o1 = (map makeCompEntry) $ head $ splitList list
        o2 = (map makeCompEntry) $ head $ tail $ splitList list
        o3 = (map makeCompEntry) $ head $ tail $ tail $ splitList list
    in
      case (head $ tail $ tail $ tail $ splitList list) of

you've written 'splitList list' 4 times here. The compiler might be clever enough to common them up, but personally I wouldn't rely on it. Your code can be shortened quite a lot, e.g:

      let
          (o1:o2:o3:rest) = map makeCompEntry (splitList list)
      in
        case rest of
          ...

        [] -> o1 `par` o2 `par` o3 `seq` o1 : o2 : o3 : []
_ -> let o4 = rels (head $ tail $ tail $ tail $ splitList list)
            in
o1 `par` o2 `par` o3 `par` o4 `seq` o1 : o2 : o3 : o4

without knowing what splitList and the rest of the program does, it's hard to say why you don't get any parallelism here. But note that when you say:

o1 `par` o2 `par` o3 `seq` o1 : o2 : o3 : []

what this does is create "sparks" for o1-o3 before returning the list [o1,o2,o3]. Now, something else is consuming this list - if whatever consumes it looks at the head of the list first, then you've immediately lost the opportunity to overlap o1 with anything else, because the program is demanding it eagerly.

All this is quite hard to think about, and there is a serious lack of tools at the moment to tell you what's going on. We do hope to address that in the future.

Right now, I suggest keeping things really simple. Use large-grain parallelism, in a very few places in your program. Use strategies - parMap is a good one because it hides the laziness aspect, you don't need to worry about what is getting evaluated when.

Cheers,
        Simon
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to