MATLAB: How to Pin Workers to Specific Cores

Parallel Computing Toolboxparpool

I would like to know how to pin parpool workers to specific cores. I have a dual socket system, so each socket has faster access to certain resources, like GPUs.
Therefore, say I have 8 workers in my pool and 8 GPUs. I want to pin each worker to a specific core on my dual socket system.

Best Answer

What OS are you using? If Windows, you could adapt the code from this answer on Stack Overflow. One way to pick the affinitization is to use an spmd block after opening the pool and using labindex to choose the CPU.
On Linux, you can use this approach to set affinity. I would adapt that approach and use the undocumented feature('getpid') means of accessing the current process' PID, something like this
spmd
pid = feature('getpid');
system(sprintf('taskset -pc %d %d', labindex-1, pid));
end