# StackOverflowError when using PRIMA.jl on Ubuntu (works fine on macOS and Windows)

**URL:** <https://discourse.julialang.org/t/stackoverflowerror-when-using-prima-jl-on-ubuntu-works-fine-on-macos-and-windows/131012>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package\
**Created:** [July 24, 2025, 3:28pm UTC](https://discourse.julialang.org/t/stackoverflowerror-when-using-prima-jl-on-ubuntu-works-fine-on-macos-and-windows/131012 "2025-07-24T15:28:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pclins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pclins/32/217884_2.png) [@pclins](https://discourse.julialang.org/u/pclins)\
**Post date:** [July 24, 2025, 3:28pm UTC](https://discourse.julialang.org/t/stackoverflowerror-when-using-prima-jl-on-ubuntu-works-fine-on-macos-and-windows/131012/1 "2025-07-24T15:28:45Z")

</div>

Hi everyone,

I’m running into a strange `StackOverflowError` when using Julia on **Ubuntu**. The same code runs without any issues on **macOS** and **Windows**.

I’m using `PRIMA.jl` (via `OptimizationPRIMA.jl`) to optimize a function. My real use case is more complex, but I was able to replicate the error with the following minimal working example:

```julia
using Optimization, OptimizationPRIMA

function debug_objective(x, p)
    result = sum((x .- p).^2)
    return result
end

function test_optimizer()
    x0 = [1.0, 2.0]
    p = [3.0, 4.0]
    lb = [0.0, 0.0]
    ub = [10.0, 10.0]

    prob = OptimizationProblem(debug_objective, x0, p; lb=lb, ub=ub)
    result = Optimization.solve(prob, BOBYQA(), maxiters=100)

    return result
end

test_optimizer()

```

I have checked related GitHub issues and discussions about platform-specific behavior, but nothing helped so far.

Has anyone encountered similar issues using PRIMA.jl on Ubuntu, or do you have any ideas on how to debug further?

Thanks in advance!

Edit 1: I found a GitHub issue that seems to describe the same problem: [Problems with Linux (Arch) · Issue #25 · libprima/PRIMA.jl · GitHub](https://github.com/libprima/PRIMA.jl/issues/25)

Edit 2: After discussing it with @abraemer, I observed that when I run the code above sequentially in the terminal, there is no problem. When I run it in VS Code, I **do** encounter the problem.

However, running the code in parallel results in the same problem **both** in the terminal and in VS Code. Here’s the parallel version that reproduces the issue:

```julia
using Distributed
addprocs(8) # Add some workers

@everywhere begin
    using Optimization, OptimizationPRIMA

    function debug_objective(x, p)
        result = sum((x .- p).^2)
        return result
    end

    function test_optimizer()
        x0 = [1.0, 2.0]
        p = [3.0, 4.0]
        lb = [0.0, 0.0]
        ub = [10.0, 10.0]

        prob = OptimizationProblem(debug_objective, x0, p; lb=lb, ub=ub)
        result = Optimization.solve(prob, BOBYQA(), maxiters=100)
        return result
    end
end

# Run the optimizer on the worker (process 2)
result = fetch(@spawnat 2 test_optimizer())
println(result)

```

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [July 24, 2025, 3:43pm UTC](https://discourse.julialang.org/t/stackoverflowerror-when-using-prima-jl-on-ubuntu-works-fine-on-macos-and-windows/131012/2 "2025-07-24T15:43:55Z")

</div>

cannot confirm. What’s your OS and `versioninfo()`?

```julia-repl
julia> test_optimizer()
retcode: Success
u: 2-element Vector{Float64}:
 2.999999999999999
 3.999999999999999

julia> versioninfo()
Julia Version 1.11.4
Commit 8561cc3d68d (2025-03-10 11:36 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 4800H with Radeon Graphics
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

shell> lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.2 LTS
Release:	24.04
Codename:	noble

```

---

<div class="post-metadata">

**Author:** ![pclins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pclins/32/217884_2.png) [@pclins](https://discourse.julialang.org/u/pclins)\
**Post date:** [July 24, 2025, 3:50pm UTC](https://discourse.julialang.org/t/stackoverflowerror-when-using-prima-jl-on-ubuntu-works-fine-on-macos-and-windows/131012/3 "2025-07-24T15:50:21Z")

</div>

Thanks for checking. I don’t know what is happening. Others have found similar issue: [Problems with Linux (Arch) · Issue #25 · libprima/PRIMA.jl · GitHub](https://github.com/libprima/PRIMA.jl/issues/25)

```julia
Julia Version 1.11.6
Commit 9615af0f269 (2025-07-09 12:58 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × Intel(R) Core(TM) i9-14900
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 32 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_VSCODE_REPL = 1

shell> lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 24.04.2 LTS
Release:	24.04
Codename:	noble

```

---

<div class="post-metadata">

**Author:** ![pclins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pclins/32/217884_2.png) [@pclins](https://discourse.julialang.org/u/pclins)\
**Post date:** [July 24, 2025, 5:14pm UTC](https://discourse.julialang.org/t/stackoverflowerror-when-using-prima-jl-on-ubuntu-works-fine-on-macos-and-windows/131012/4 "2025-07-24T17:14:21Z")

</div>

Some updates on your comment. When I run the code sequentially in the terminal, there is no problem. When I run it in VS Code, I **do** encounter the problem.

However, running the code in parallel results in the same problem **both** in the terminal and in VS Code.

```julia
using Distributed
addprocs(8) # Add some workers

@everywhere begin
    using Optimization, OptimizationPRIMA

    function debug_objective(x, p)
        result = sum((x .- p).^2)
        return result
    end

    function test_optimizer()
        x0 = [1.0, 2.0]
        p = [3.0, 4.0]
        lb = [0.0, 0.0]
        ub = [10.0, 10.0]

        prob = OptimizationProblem(debug_objective, x0, p; lb=lb, ub=ub)
        result = Optimization.solve(prob, BOBYQA(), maxiters=100)
        return result
    end
end

# Run the optimizer on the worker (process 2)
result = fetch(@spawnat 2 test_optimizer())
println(result)

```

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [July 24, 2025, 5:24pm UTC](https://discourse.julialang.org/t/stackoverflowerror-when-using-prima-jl-on-ubuntu-works-fine-on-macos-and-windows/131012/5 "2025-07-24T17:24:44Z")

</div>

Ok tried again with that code and that does indeed reproduce the issue for me. Strange that even Distributed.jl causes this. Since Distributed.jl uses processes and each process has its own copy of the library I am really surprised that this changes things. Anyhow I don’t think that I can contribute more besides reproducing the issue 😅

---

<div class="post-metadata">

**Author:** ![francesco.alemanno](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)\
**Post date:** [December 7, 2025, 3:29pm UTC](https://discourse.julialang.org/t/stackoverflowerror-when-using-prima-jl-on-ubuntu-works-fine-on-macos-and-windows/131012/7 "2025-12-07T15:29:12Z")

</div>

just encountered this issue. For the next user stumbling on this issue:  
use NLopt’s NEWUOA it works flawlessly.
