[Haskell-cafe] Failing to make `par`

Jefferson Heard jefferson.r.heard at gmail.com
Mon Mar 3 11:14:42 EST 2008


I've used Control.Parallel and Control.Parallel.Strategies extensively in
the past, and I thought I knew what I was doing.  I declared the following
function:

findSupernodes' :: S.Set Name -> Int -> Tree -> Protein.Tree -> S.Set Name
findSupernodes' set size (Node i _ _ s il ir) (Protein.Node _ pl pr _ g)
    | S.size g > size = (Name (fromIntegral i)) `S.insert` set
    | otherwise       =  leftNodes `S.union` rightNodes
    where leftNodes =  (findSupernodes' set size il pl)
          rightNodes = (findSupernodes' set size il pl)
findSupernodes' set size (Leaf _ _) (Protein.Gene _ _ _) = set

and then simply wrote the following as an initial stab at parallelizing it,
because actually calling this function causes the program to execute an
absurd number of string comparisons:

findSupernodes = findSupernodes' S.empty
findSupernodes' :: S.Set Name -> Int -> Tree -> Protein.Tree -> S.Set Name
findSupernodes' set size (Node i _ _ s il ir) (Protein.Node _ pl pr _ g)
    | S.size g > size = (Name (fromIntegral i)) `S.insert` set
    | otherwise       =  leftNodes `par` rightNodes `seq` leftNodes
`S.union` rightNodes
    where leftNodes =  (findSupernodes' set size il pl)
          rightNodes = (findSupernodes' set size il pl)
findSupernodes' set size (Leaf _ _) (Protein.Gene _ _ _) = set

The thing is, these two functions don't return the same thing.  The parallel
version is returning an empty set, while the sequential version returns what
it should return.  Any clue what I did wrong?

-- Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080303/33193347/attachment.htm


More information about the Haskell-Cafe mailing list