Haskell's Run Time System doesn't save electricity
Someone provided me with a sequential implementation of the fibonacci function. Out of curiosity, it was compiled with -threaded and we played with the -N option of the runtime.
That same someone noticed some suspicious behavior. I notice the same and so report about it: all cores specified by $np are fully used while there is no change in the wallclock time spent by the program.
The code:
import Text.Printf
fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
i = 44
main = printf "n=%d => %d\n" i (fib i)
The build:
ghc -threaded -O2 sequential_fib.hs
The run (on an eight cores machine), shell is Bash:
for np in `seq 1 8` ; do time ./sequential_fib +RTS -N$np ; done
The output:
n=44 => 701408733
real 0m10.838s
user 0m10.817s
sys 0m0.000s
n=44 => 701408733
real 0m10.762s
user 0m12.009s
sys 0m9.165s
n=44 => 701408733
real 0m10.774s
user 0m24.846s
sys 0m6.800s
n=44 => 701408733
real 0m10.769s
user 0m33.654s
sys 0m8.413s
n=44 => 701408733
real 0m11.222s
user 0m47.427s
sys 0m7.336s
n=44 => 701408733
real 0m11.217s
user 0m57.872s
sys 0m7.752s
n=44 => 701408733
real 0m11.208s
user 1m9.172s
sys 0m7.112s
n=44 => 701408733
real 0m11.204s
user 1m18.909s
sys 0m7.768s
Trac metadata
Trac field | Value |
---|---|
Version | 7.4.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Runtime System |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | jm@alliot.org |
Operating system | |
Architecture |