I mirror here my question at StackOverflow: How to increase stack size for Julia in Windows? - Stack Overflow
I wrote a recursive function (basically a flood fill), it works fine on smaller datasets, but for slightly larger input it throws StackOverflowError
.
How to increase the stack size for Julia under Windows 10? Ideally the solution should be applicable to JupyterLab.
It’s a singe use program, no point in optimizing/rewriting it, I just need to peak at the result and forget about the code.
As a test case, I provide the following MWE. This is just a simple algorithm that recursively visits each cell of n
by n
array:
n = 120
visited = fill(false, (n,n))
function visit_single_neighbour(i,j,Δi,Δj)
if 1 ≤ i + Δi ≤ n && 1 ≤ j + Δj ≤ n
if !visited[i+Δi, j+Δj]
visited[i+Δi, j+Δj] = true
visit_four_neighbours(i+Δi, j+Δj)
end
end
end
function visit_four_neighbours(i,j)
visit_single_neighbour(i,j,1,0)
visit_single_neighbour(i,j,0,1)
visit_single_neighbour(i,j,-1,0)
visit_single_neighbour(i,j,0,-1)
end
@time visit_four_neighbours(1,1)
For n = 120
the output is 0.003341 seconds
, but for n = 121
it throws StackOverflowError
.
On a Linux machine with ulimit -s unlimited
the code runs no problem for n = 2000
and takes about 2.4 seconds.