
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2) nfib 0 = 1 nfib 1 = 1 nfib n = 1 + nfib (n-1) + nfib (n-2) diffib n = nfib n - fib n main = print (diffib 38) 2
par x y is semantically just y, but hints to the compiler that it might be useful to start evaluating x
pseq x y is semantically just y, but will evaluate x before returning a result
fib 0 = … nfib 0 = … diffib n = let l = nfib n r = fib n in par l (l - r) main = print (diffib 38)
prompt$ ./par1a +RTS -s -N 87403802 prompt$ cat par1a.stat 16,759,034,636 bytes allocated in the heap 11,618,096 bytes copied during GC (scavenged) 2,878,584 bytes copied during GC (not scavenged) 24,576 bytes maximum residency (2 sample(s)) INIT time 0.00s ( 0.00s elapsed) MUT time 16.47s ( 16.89s elapsed) GC time 0.25s ( 0.33s elapsed) EXIT time 0.00s ( 0.00s elapsed) Total time 16.73s ( 17.23s elapsed) prompt$
fib 0 = … nfib 0 = … diffib n = let l = nfib n r = fib n in par r (l - r) main = print (diffib 38)
fib 0 = … nfib 0 = … diffib n = let l = nfib n r = fib n in par l (pseq r (l - r)) main = print (diffib 38)
fib 0 = … nfib 0 = … diffib n = let l = nfib n r = fib n in l
parrpseq(l-r) main = print (diffib 38)
sample :: Grid Point -> Image color -> Grid color sample points image = map (map image) points This looks like a good candidate for parallelization … But how?
rnf is a strategy for reducing values to normal form
16
Evaluate a list in parallel, using the argument strategy for each element. parMap :: Strategy b -> (a -> b) -> [a] -> [b] parMap s f xs = map f xs using parList s
sample :: NFData color => Grid Point -> Image color -> Grid color sample points image = map (map image) points
usingparList rnf (also need to add an NFData color context to the type of draw)
sample :: Grid Point -> Image color -> Grid color sample points image = map (map image) points draw pal grid render = render (sample grid (fracImage pal)
usingparList rnf)