필터 지우기
필터 지우기

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 CenterFile Exchange에서 Execution Speed에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by