How do multiple Julia instances handle JULIA_NUM_THREADS?

Say I have a computer with 12 CPU cores available (i.e. visible to software, 6 cores 12 threads in reality). And say I set JULIA_NUM_THREADS to 8, and launch a Julia instance.

If I launch another Julia instance, how do the two allocate threads? Will they each get 4 threads to themselves, and then fight over the remaining 4? Is the behavior undefined?

They both will have the number of threads you asked for available, and if both are doing computations they will compete for system resources, as any other two programs running at the same time in your computer.

Actually the number of threads available to Julia has not much relation with the actual number of threads your computer is able to handle. Currently there is a restriction by which one cannot launch Julia requesting more threads than the number of threads your computer provides, but I heard somewhere that even that restriction is being lifted (effectively, it is lifted in 1.6, I checked now).

@cadojo You are touching upon one of the reasons containers are used.
More exactly, why groups are used (control groups). On Linux operating systems you can run a process in a group which restricts the CPUs, memory and hardware devices which the processes can access.
So let’s say you have a multi GPU system - you can say that only GPU 1 is available to the Julia processes.
My ‘you’ I mean a resource scheduler.

1 Like