Azzera filtri
Azzera filtri

Setting Matlab thread affinity in Linux

6 visualizzazioni (ultimi 30 giorni)
Justin
Justin il 4 Apr 2012
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.

Risposta accettata

Justin
Justin il 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.

Più risposte (1)

Walter Roberson
Walter Roberson il 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 Commento
Justin
Justin il 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

Accedi per commentare.

Categorie

Scopri di più su Execution Speed in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by