I am computing a recursive function which overflows the stack for some argument values. Somewhere I heard that julia on linux uses the system stack size as set by ulimit -s
. So why do these two computations, one with ulimit -s
of 8192 and the other with ulimit -s
64 times larger, both fail with StackOverflowError and the exact same stack trace?
rec@t490:~$ ulimit -s
8192
rec@t490:~$ julia
_depth
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _ | |
| | |_| | | | (_| | | Version 1.4.2 (2020-05-23)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> include("julia/fuse.jl")
computem (generic function with 1 method)
julia> m(big"2.96678",true)
ERROR: StackOverflowError:
Stacktrace:
[1] BigFloat(; precision::Int64) at ./mpfr.jl:112
[2] BigFloat at ./mpfr.jl:112 [inlined]
[3] -(::BigFloat) at ./mpfr.jl:575
[4] m(::BigFloat, ::Bool) at /home/rec/julia/fuse.jl:7
[5] m(::BigFloat, ::Bool) at /home/rec/julia/fuse.jl:10 (repeats 9 times)
[6] m(::BigFloat, ::Bool) at /home/rec/julia/fuse.jl:9
[7] m(::BigFloat, ::Bool) at /home/rec/julia/fuse.jl:10 (repeats 10818 times)
[8] top-level scope at REPL[2]:1
julia>
rec@t490:~$ ulimit -s $(expr 256 \* 1024)
rec@t490:~$ ulimit -s
262144
rec@t490:~$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _ | |
| | |_| | | | (_| | | Version 1.4.2 (2020-05-23)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> include("julia/fuse.jl")
computem (generic function with 1 method)
julia> m(big"2.96678",true)
ERROR: StackOverflowError:
Stacktrace:
[1] BigFloat(; precision::Int64) at ./mpfr.jl:112
[2] BigFloat at ./mpfr.jl:112 [inlined]
[3] -(::BigFloat) at ./mpfr.jl:575
[4] m(::BigFloat, ::Bool) at /home/rec/julia/fuse.jl:7
[5] m(::BigFloat, ::Bool) at /home/rec/julia/fuse.jl:10 (repeats 9 times)
[6] m(::BigFloat, ::Bool) at /home/rec/julia/fuse.jl:9
[7] m(::BigFloat, ::Bool) at /home/rec/julia/fuse.jl:10 (repeats 10818 times)
[8] top-level scope at REPL[2]:1
julia>