haskell - Writing "fib" to run in parallel: -N2 is slower? -



haskell - Writing "fib" to run in parallel: -N2 is slower? -

i'm learning haskell , trying write code execute in parallel, haskell runs sequentially. , when execute -n2 runtime flag take more time execute if omit flag.

here code:

import control.parallel import control.parallel.strategies fib :: int -> int fib 1 = 1 fib 0 = 1 fib n = fib (n - 1) + fib (n - 2) fib2 :: int -> int fib2 n = `par` (b `pseq` (a+b)) = fib n b = fib n + 1 fib3 :: int -> int fib3 n = runeval $ <- rpar (fib n) b <- rpar (fib n + 1) rseq rseq b homecoming (a+b) main = putstrln (show (fib3 40))

what did wrong? tried sample in windows 7 on intel core i5 , in linux on atom.

here log console session:

ghc -rtsopts -threaded -o2 test.hs [1 of 1] compiling main ( test.hs, test.o ) test +rts -s 331160283 64,496 bytes allocated in heap 2,024 bytes copied during gc 42,888 bytes maximum residency (1 sample(s)) 22,648 bytes maximum slop 1 mb total memory in utilize (0 mb lost due fragmentation) generation 0: 0 collections, 0 parallel, 0.00s, 0.00s elapsed generation 1: 1 collections, 0 parallel, 0.00s, 0.00s elapsed parallel gc work balance: nan (0 / 0, ideal 1) mut time (elapsed) gc time (elapsed) task 0 (worker) : 0.00s ( 6.59s) 0.00s ( 0.00s) task 1 (worker) : 0.00s ( 0.00s) 0.00s ( 0.00s) task 2 (bound) : 6.33s ( 6.59s) 0.00s ( 0.00s) sparks: 2 (0 converted, 0 pruned) init time 0.00s ( 0.00s elapsed) mut time 6.33s ( 6.59s elapsed) gc time 0.00s ( 0.00s elapsed) exit time 0.00s ( 0.00s elapsed) total time 6.33s ( 6.59s elapsed) %gc time 0.0% (0.0% elapsed) alloc rate 10,191 bytes per mut sec productivity 100.0% of total user, 96.0% of total elapsed gc_alloc_block_sync: 0 whitehole_spin: 0 gen[0].sync_large_objects: 0 gen[1].sync_large_objects: 0 test +rts -n2 -s 331160283 72,688 bytes allocated in heap 5,644 bytes copied during gc 28,300 bytes maximum residency (1 sample(s)) 24,948 bytes maximum slop 2 mb total memory in utilize (0 mb lost due fragmentation) generation 0: 1 collections, 0 parallel, 0.00s, 0.00s elapsed generation 1: 1 collections, 1 parallel, 0.00s, 0.01s elapsed parallel gc work balance: 1.51 (937 / 621, ideal 2) mut time (elapsed) gc time (elapsed) task 0 (worker) : 0.00s ( 9.29s) 0.00s ( 0.00s) task 1 (worker) : 4.53s ( 9.29s) 0.00s ( 0.00s) task 2 (bound) : 5.84s ( 9.29s) 0.00s ( 0.01s) task 3 (worker) : 0.00s ( 9.29s) 0.00s ( 0.00s) sparks: 2 (1 converted, 0 pruned) init time 0.00s ( 0.00s elapsed) mut time 10.38s ( 9.29s elapsed) gc time 0.00s ( 0.01s elapsed) exit time 0.00s ( 0.00s elapsed) total time 10.38s ( 9.30s elapsed) %gc time 0.0% (0.1% elapsed) alloc rate 7,006 bytes per mut sec productivity 100.0% of total user, 111.6% of total elapsed gc_alloc_block_sync: 0 whitehole_spin: 0 gen[0].sync_large_objects: 0 gen[1].sync_large_objects: 0

i think reply "ghc optimise fib function no allocation, , computations no allocation cause problems rts because scheduler never gets run , load-balancing (which necessary parallelism)" wrote simon in discussion group. found tutorial.

haskell parallel-processing ghc

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -