Clear Filters
Clear Filters

Setting Matlab thread affinity in Linux

6 views (last 30 days)
Hello, I was wondering if there is a way to set thread affinity in matlab. Basically, I have a mex file with openmp and if I set the number of cores to say, 6, then when I open system manager it shows these threads jumping between cores. I don't need to set threads to specific cores (although this feature would be nice), I just need to make sure once they're assigned a core that they stay there. I tried the following:
!export OMP_PROC_BIND=true
Before running the program but this option doesn't work. Also, I'm using R2011b with ubuntu 11.04 64bit. Thanks.

Accepted Answer

Justin
Justin on 5 Apr 2012
Ok. I found a solution. I used:
export GOMP_CPU_AFFINITY=0-63
Instead of OMP_PROC_BIND. This is actually better in my opinion because, well, it works first of all, and secondly you can pick which threads get assigned to which cpus which is pretty cool.
Not sure why OMP_PROC_BIND didn't work, but it might be because I have a pre openmp 3.1 version installed. I'm using ubuntu 11.04 which has gcc 4.5.2. Tried to look up which openmp version comes installed with this gcc but couldn't find out within the first couple of minutes so I stopped searching. The method I used above works so I figured there's not much use in digging any deeper.

More Answers (1)

Walter Roberson
Walter Roberson on 5 Apr 2012
I have no information about that, but I do know that that !export would not work. Instead call
setenv('OMP_PROC_BIND','true');
When you use !export OMP_PROC_BIND=true then you set the environment variable only in the subshell that is created to handle the '!' command, and then that subshell exits leaving MATLAB and further subshells unchanged. Calling setenv() from MATLAB affects all following subshells.
  1 Comment
Justin
Justin on 5 Apr 2012
This does not work. Actually, this feature doesn't even seem to work for OMP_NUM_THREADS. I have to open a terminal, enter "export omp_num_threads = 6" and then open matlab within the same terminal for it to work properly. Tried the same for omp_proc_bind = true and it still doesn't work with this method... Maybe omp_proc_bind doesn't work in general for my setup. I'll try to look around for answers. Thanks

Sign in to comment.

Categories

Find more on Execution Speed in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!