I think we do want to respect taskset when it is explicit. Please file a
bug -- or PR if you can test this (second answer):

http://stackoverflow.com/questions/4592575/is-it-possible-to-prevent-children-inheriting-the-cpu-core-affinity-of-the-paren

See some discussion here:
https://github.com/JuliaLang/julia/issues/1802#issuecomment-17175787
https://github.com/JuliaLang/julia/pull/3097

On Sun, Jan 4, 2015 at 12:52 PM, Aaron Okano <[email protected]> wrote:

> I am running some code on a system with two processor sockets, and would
> prefer for the processes to be restricted to a single socket for the time
> being. I have tried to use taskset, but Julia appears to manually set its
> own affinity when it starts.
>
> $ taskset -c 0,1,2,3,4,5 julia -q -p 5 &
> [1] 13173
> $ ps -eF | grep -e 'julia\|PSR'
> UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
> aokano   13173  4626 54 192807 108788 0 09:48 pts/2    00:00:02 julia -q
> -p 5
> aokano   13185 13173 27 114376 71492  6 09:49 ?        00:00:01
> /home/aokano/julia/usr/bin/./julia --worker --bind-to 169.237.10.172
> aokano   13186 13173 31 131261 73616  9 09:49 ?        00:00:01
> /home/aokano/julia/usr/bin/./julia --worker --bind-to 169.237.10.172
> aokano   13187 13173 30 123234 74216  8 09:49 ?        00:00:01
> /home/aokano/julia/usr/bin/./julia --worker --bind-to 169.237.10.172
> aokano   13188 13173 30 123077 73700  2 09:49 ?        00:00:01
> /home/aokano/julia/usr/bin/./julia --worker --bind-to 169.237.10.172
> aokano   13189 13173 29 126412 87232  5 09:49 ?        00:00:01
> /home/aokano/julia/usr/bin/./julia --worker --bind-to 169.237.10.172
> aokano   13246  4626  0  1908  1008   0 09:49 pts/2    00:00:00 grep
> --color=auto -e julia\|PSR
>
>
> Note the processor number is shown in the PSR column.
>
> The offending code appears to be this segment of init.c
>
>     int ncores = jl_cpu_cores();
>     if (ncores > 1) {
>         cpu_set_t cpumask;
>         CPU_ZERO(&cpumask);
>         for(int i=0; i < ncores; i++) {
>             CPU_SET(i, &cpumask);
>         }
>         sched_setaffinity(0, sizeof(cpu_set_t), &cpumask);
>     }
>
>
> where the function jl_cpu_cores() calls sysconf(_SC_NPROCESSORS_ONLN) to
> determine the number of available cores. According to my tests, this
> function ignores taskset,
>
> $ cat test.c
> #include <stdio.h>
> #include <unistd.h>
>
> int main() {
>   printf("%d\n",sysconf( _SC_NPROCESSORS_ONLN ) );
>   return 0;
> }
>
>
> $ ./a.out
> 12
> $ taskset -c 0,1,2,3,4,5 ./a.out
> 12
>
> Long explanation aside, is there any way to set CPU affinity for Julia
> processes?
>

Reply via email to