Limit number of threads in julia -t auto

Is there a way to start a (non-interactive) Julia process that automatically determines the sensible automatic number for theads but if that is higher than some threshold, limits it to the latter?

Eg on a laptop with 8 cores I would want to use 8 (which I get with julia -t auto), but on a server with 100+ cores I am sharing with others I would want to max out at, say, 24 to be a good citizen, and I want to use the same scripts on both without too much hassle.

1 Like

if you use -t auto and OhMyThreads.jl, you can use @set ntasks = min(nthreads(), 24) or something

1 Like

I would probably do a shell alias here rather than language-level solution

5 Likes

Or alternatively,

echo "export JULIA_NUM_THREADS=24" >> ~/.bashrc

on the server.

1 Like

Yes, that makes sense. I went with

julia -t `julia -t auto --startup-file=no -e 'print(min(Threads.nthreads(),24))'`

which does involve the shell (for the ``) but it is portable and requires no Bash magic.Âą

ÂąAnything beyond VAR=stuff ... $VAR is magic.

1 Like

Shouldn’t that be:

julia -t `julia -t auto --startup-file=no -e 'print(min(Threads.nthreads(),24))'`

?

Otherwise the “inner” julia will always have only one thread, no?

1 Like

thanks, I edited it