Default JULIA_NUM_THREADS to half the physical cores for the Julia backend#9
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The refactored
Coconots.jlbackend (manuhuth/Coconots.jl#8) parallelizes its likelihood evaluations, but a Julia process starts single-threaded unlessJULIA_NUM_THREADSis 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 ofaddJuliaFunctions()andinstallJuliaPackages(), i.e. before the firstjuliaEval/juliaCallof a session) that:JULIA_NUM_THREADS(from.Renviron, the shell, or set earlier in the session),parallel::detectCores(logical = FALSE) - 1, minimum 1, logical-cores fallback), leaving one core free for R and the system,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 toImports. 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