フィルターのクリア

Setting Matlab thread affinity in Linux

6 ビュー (過去 30 日間)
Justin
Justin 2012 年 4 月 4 日
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.

採用された回答

Justin
Justin 2012 年 4 月 5 日
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.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 4 月 5 日
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 件のコメント
Justin
Justin 2012 年 4 月 5 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeExecution Speed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by