Skip to content

Commit 684d5fc

Browse files
DilumAluthgevtjnash
authored andcommitted
Support passing auto as the value to the JULIA_NUM_THREADS environment variable
1 parent 5cd07f8 commit 684d5fc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/threading.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,18 @@ void jl_init_threading(void)
392392

393393
// how many threads available, usable
394394
jl_n_threads = JULIA_NUM_THREADS;
395-
if (jl_options.nthreads < 0) // --threads=auto
395+
if (jl_options.nthreads < 0) { // --threads=auto
396396
jl_n_threads = jl_cpu_threads();
397-
else if (jl_options.nthreads > 0) // --threads=N
397+
}
398+
else if (jl_options.nthreads > 0) { // --threads=N
398399
jl_n_threads = jl_options.nthreads;
399-
else if ((cp = getenv(NUM_THREADS_NAME)))
400-
jl_n_threads = (uint64_t)strtol(cp, NULL, 10);
400+
}
401+
else if ((cp = getenv(NUM_THREADS_NAME))) {
402+
if (strcmp(cp, "auto"))
403+
jl_n_threads = (uint64_t)strtol(cp, NULL, 10); // ENV[NUM_THREADS_NAME] == "N"
404+
else
405+
jl_n_threads = jl_cpu_threads(); // ENV[NUM_THREADS_NAME] == "auto"
406+
}
401407
if (jl_n_threads <= 0)
402408
jl_n_threads = 1;
403409
#ifndef __clang_analyzer__

0 commit comments

Comments
 (0)