How to increase the stack size of Julia threads?

I’m doing multiple recursive computations (Welzl’s algorithm) in parallel using Threads.@threads, producing a stack overflow. This is on latest Linux and Julia 1.7.0-rc2.
How do increase the size of a thread’s stack?

(It turns out that in this particular case the stack overflow is my fault and can’t be fixed by having larger stacks, but I’m still interested in how to change stack size.)

I know this thread is old but I’ve found it multiple times now searching for the same answer, so here is what I did, in case it helps others who find this:

with_stacksize(f, n) = fetch(schedule(Task(f, n)))
Threads.@threads for ...
    with_stacksize(8*1024*1024) do # execute with 8MiB stack size
        foo()
    end
end

I found it in this github issue

It also looks like the default thread stack size will be increased in Julia 1.12: Increase stack size limit to 8 MB? · Issue #54998 · JuliaLang/julia · GitHub

3 Likes

This is now also documented:

2 Likes