# How to increase stack size for Julia in Windows?

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.

Welcome to Julia.

Ignoring that, assuming that your real problem is similar, I say it would be easy to use a loop instead of recursion and it would be much faster too. Doing some more thinking you can get rid of

too.

This doesn’t exist. I bet you already run it several times.

AFAIK there is nothing like `ulimit` for windows. The stack size is set during build/compile of the .exe. There is `editbin`, which comes with Visual Studio. You can try it on the julia.exe but I doubt that this is working seamless as you expect it: /STACK | Microsoft Docs

Proving myself wrong:

``````c:\Users\Oli\AppData\Local\Programs\Julia-1.7.2\bin>"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64\editbin.exe" /STACK:2000000000 julia.exe
``````

did it:

``````julia> n = 2000
2000

julia> visited = fill(false, (n,n));

julia> @time visit_four_neighbours(1,1)
4.018976 seconds (53.59 M allocations: 817.735 MiB, 62.21% gc time)

``````

Well, I hate it.
If you do it in a well designed loop you will get increased performance by huge orders of magnitudes!!!

1 Like

Someone can get the bounty there. I don’t like my answer, so I refuse to answer at SO

2 Likes