# How to increase stack size for Julia in Windows?

**URL:** <https://discourse.julialang.org/t/how-to-increase-stack-size-for-julia-in-windows/79932>\
**Category:** General Usage\
**Tags:** windows, stackoverflow\
**Created:** [April 24, 2022, 7:34am UTC](https://discourse.julialang.org/t/how-to-increase-stack-size-for-julia-in-windows/79932 "2022-04-24T07:34:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yrogirg](https://avatars.discourse-cdn.com/v4/letter/y/df788c/32.png) [@Yrogirg](https://discourse.julialang.org/u/Yrogirg)\
**Post date:** [April 24, 2022, 7:34am UTC](https://discourse.julialang.org/t/how-to-increase-stack-size-for-julia-in-windows/79932/1 "2022-04-24T07:34:11Z")

</div>

I mirror here my question at StackOverflow: [How to increase stack size for Julia in Windows? - Stack Overflow](https://stackoverflow.com/questions/71956946/how-to-increase-stack-size-for-julia-in-windows)

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 24, 2022, 9:48am UTC](https://discourse.julialang.org/t/how-to-increase-stack-size-for-julia-in-windows/79932/2 "2022-04-24T09:48:09Z")

</div>

Welcome to Julia.

> [@Yrogirg](#):
>
> It’s a single use program, no point in optimizing/rewriting it, I just need to peak at the result and forget about the code.

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

> [@Yrogirg](#):
>
> `if !visited[i+Δi, j+Δj]`

too.

> [@Yrogirg](#):
>
> It’s a single use program

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 Learn](https://docs.microsoft.com/en-us/cpp/build/reference/stack?view=msvc-170)

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 24, 2022, 10:01am UTC](https://discourse.julialang.org/t/how-to-increase-stack-size-for-julia-in-windows/79932/3 "2022-04-24T10:01:01Z")

</div>

> [@oheil](#):
>
> but I doubt that this is working seamless

Proving myself wrong:

```julia-auto
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-auto
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!!!

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 24, 2022, 10:03am UTC](https://discourse.julialang.org/t/how-to-increase-stack-size-for-julia-in-windows/79932/4 "2022-04-24T10:03:22Z")

</div>

> [@Yrogirg](#):
>
> I mirror here my question at StackOverflow: [How to increase stack size for Julia in Windows? - Stack Overflow](https://stackoverflow.com/questions/71956946/how-to-increase-stack-size-for-julia-in-windows)

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