From d665bb10fc2b687c956bb976fc1b6adc099184ce Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 26 May 2010 08:43:37 +0000 Subject: [PATCH] update to work with weak sparks using the new Strategies --- parallel/partree/Tree.hs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/parallel/partree/Tree.hs b/parallel/partree/Tree.hs index 59a2e4d..97eb736 100644 --- a/parallel/partree/Tree.hs +++ b/parallel/partree/Tree.hs @@ -1,5 +1,5 @@ -- -*- haskell -*- --- Time-stamp: <2008-10-22 10:13:48 simonmar> +-- Time-stamp: <2010-05-25 16:25:18 simonmar> -- -- ADT of a binary tree (values only in leaves). -- Parallel functions use par and seq directly. @@ -12,6 +12,7 @@ module Tree(Tree, force_tree, par_tree_map) where import Control.Parallel +import Control.Parallel.Strategies infixl 2 ^: @@ -25,14 +26,15 @@ tree_map f (Node left right) = Node (tree_map f left) (tree_map f right) par_tree_map :: (Integral a, Integral b) => (a -> b) -> Tree a -> Tree b par_tree_map f (Leaf x) = Leaf (f x) -par_tree_map f (Node left right) = force_tree left' `par` - (force_tree right' `pseq` - (Node left' right')) - -- parentheses added because - -- some versions of GHC have the - -- wrong fixity for par & pseq - where left' = par_tree_map f left - right' = par_tree_map f right +par_tree_map f (Node left right) = + Node (par_tree_map f left) (par_tree_map f right) `using` partree + where + partree (Node l r) = do + l' <- (rpar `dot` rtree) l + r' <- rtree r + return (Node l' r') + +rtree t = force_tree t `pseq` Done t -- force evaluation of tree (could use Strategies module instead!) force_tree :: (Integral a) => Tree a -> () -- GitLab