Skip to content

Default JULIA_NUM_THREADS to half the physical cores for the Julia backend#9

Merged
manuhuth merged 2 commits into
mainfrom
feat/julia-threads-default
Jul 2, 2026
Merged

Default JULIA_NUM_THREADS to half the physical cores for the Julia backend#9
manuhuth merged 2 commits into
mainfrom
feat/julia-threads-default

Conversation

@manuhuth

@manuhuth manuhuth commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

The refactored Coconots.jl backend (manuhuth/Coconots.jl#8) parallelizes its likelihood evaluations, but a Julia process starts single-threaded unless JULIA_NUM_THREADS is set when it is spawned — so R users were always running the backend on one thread.

This PR adds an internal set_julia_threads() helper (called at the top of addJuliaFunctions() and installJuliaPackages(), i.e. before the first juliaEval/juliaCall of a session) that:

  • never overrides a pre-existing JULIA_NUM_THREADS (from .Renviron, the shell, or set earlier in the session),
  • otherwise defaults it to physical cores − 1 (parallel::detectCores(logical = FALSE) - 1, minimum 1, logical-cores fallback), leaving one core free for R and the system,
  • is a no-op if core detection fails or Julia is already running.

Measured effect: second-order fits on long/overdispersed series run ~3× faster at 8 threads; verified end-to-end that the JuliaConnectoR-spawned session picks the setting up (13 threads on a 14-core machine) and fits are unchanged.

parallel (base R) added to Imports. New unit test covers the respect-user-setting and set-when-unset behaviors.

Full testthat suite (NOT_CRAN=true, against the dev Julia backend): 31 pass, 0 fail.

🤖 Generated with Claude Code

manuhuth and others added 2 commits July 2, 2026 16:10
…ckend

Coconots.jl parallelizes its likelihood evaluations, but a Julia process
starts single-threaded unless JULIA_NUM_THREADS is set when it is
spawned. Set it (to half the physical cores) before the first
JuliaConnectoR call in addJuliaFunctions()/installJuliaPackages(),
never overriding a user-provided value. Second-order fits on long or
overdispersed series gain roughly 3x on 8 threads.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@manuhuth manuhuth merged commit 06f2abf into main Jul 2, 2026
14 checks passed
@manuhuth manuhuth deleted the feat/julia-threads-default branch July 2, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant