A second combinator: pseq pseg : a->b->b x pseg Y pseg: Evaluate x in the current thread then return y. ■ Operationally pseq y bottom if x -> bottom Y otherwise With pseg, we can control evaluation order e par f pseg (f + e)
pseq: Evaluate x in the current thread, then return y. Operationally, With pseq, we can control evaluation order. pseq :: a -> b -> b x `pseq` y x `pseq` y = bottom if x -> bottom = y otherwise. e `par` f `pseq` (f + e)
Using pseq f par(e pseq (f +el) spark for f created thread1 eval e evalf+e thread2 eval f spark for f instantiated onto thread2
ThreadScope ThreadScope (in beta displays event logs generated by ghc to track spark behavior Thread 1 Thread 2 (Idle) f par (f + e) Figure 1. No parallelization of f'par'(f +e)
ThreadScope (in Beta) displays event logs generated by GHC to track spark behavior: Thread 1 Thread 2 (Idle) Thread 1 Thread 2 (Busy) f `par` (f + e) f `par` (e + f)
Sample Program fib : Int - Int fib 0= 0 fib 1=1 fib n fib (n-1)+ fib(n-2) sumEuler : Int 工nt sumEuler n =.. in Concfutorial hs parSumFibEuler Good : Int - Int ->Int parSumFibEuler Good a b f par(e pseg (f e) where f s fib a e sumEuler b The fib and sumEuler functions are unchanged
The fib and sumEuler functions are unchanged. fib :: Int -> Int fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib(n-2) sumEuler :: Int -> Int sumEuler n = … in ConcTutorial.hs … parSumFibEulerGood :: Int -> Int -> Int parSumFibEulerGood a b = f `par` (e `pseq` (f + e)) where f = fib a e = sumEuler b
Performance Numbers -gray - mandel △- matou|t 米 peartree umeuler 5 Number of cpu
Performance Numbers