JuliaLang/julia

`JULIA_NUM_THREADS` ignored when embedding Julia on a Windows system

Open

#55.468 aberto em 12 de ago. de 2024

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)Julia (5.773 forks)batch import
bughelp wantedsystem:windows

Métricas do repositório

Stars
 (48.709 stars)
Métricas de merge de PR
 (Mesclagem média 23d 11h) (145 fundiu PRs em 30d)

Description

The following c# code...

Environment.SetEnvironmentVariable("JULIA_NUM_THREADS", "4");
jl_init_with_image__threading(mBinPath, mSysImg);
jl_eval_string("println(\"Threads=$(Threads.nthreads())\")");
jl_eval_string("println(\"JULIA_NUM_THREADS=$(ENV[\"JULIA_NUM_THREADS\"])\")");

Produces the following output

Threads=1
JULIA_NUM_THREADS=4

In discussions with the Jeff and Keno it appears this happens in Windows because there are several environment stores in Windows, and the threads are created by reading with getenv (which access the machine level environment), while later in Julia the ENV is retrieved using getenvw (which access the process level environment).

Guia do colaborador