Skip to content

How to set nthreads for library at load time #152

Description

@visr

In #113 the number of threads is set to 1, with the option to change it at compile time.

I am compiling Julia code to a library with JuliaC, and used to set the threads at runtime from a Rust CLI by setting JULIA_NUM_THREADS, which worked fine (code here if interested).

I'm fine with defaulting to 1, but I don't see how I can control it at runtime. I see testset "jl_options applied at runtime (library)" but that only seems to read out the values at runtime.

Or should really not do this? I don't understand what in #112 is meant by until it has multi-threading / chained signal support. EDIT: just found JuliaLang/julia#61319

Activity

  1. visr commented on Jul 16, 2026

    @visr
    SponsorContributorAuthor

    Since I didn't want to be stuck on an older JuliaC version, in Deltares/Ribasim#3151 I added c_sources = ["build/set_julia_threads.c"] which adds C API to our library to set the number of threads before Julia is initialized. When nthreads > 1, signal handling is turned on as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions