Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

affinity in openmp??

rrr1989
Beginner
873 Views
i am a newbie...

can anyone explain me in detail how to set kmp_affinity etc... i am not clear about it..

i just know that it is used to set affinity to threads - cores (processors).. but how to do it?? i dont know..!

i am having a desktop with windows XP SP3 installed on it, also visual studio 2008 and along with it openmp...

also is it possible to set affinity for threads through program at runtime..?? if so how??
0 Kudos
4 Replies
TimP
Honored Contributor III
873 Views
SET KMP_AFFINITY=compact
would cause your Intel OpenMP application to attempt to pair up threads [0,1],[2,3],.... on shared cache. This would usually be a good strategy, provided that it is the only task running.
If you have a HyperThreading enabled, as on quad core I7, and wish to use 1 thread per core, try
SET KMP_AFFINITY=compact,1
SET OMP_NUM_THREADS=4

The ,1 directs the affinity to use alternate logical processors.

The verbose option gives you all the information about topology discovery and the assignments you requested, including whether it is set to choose any logical processor in a specified group.
You can specifiy a full mapping with the proclist option, e.g.
SET KMP_AFFINITY="proclist=[0,2],explicit,verbose"
SET OMP_NUM_THREADS=2
for 1 job, and proclist=[1,3] for another, if you wanted to run 2 2-thread jobs on a Q6600 with minimum interference. Note that Q6600 BIOS numbers cores in a checkerboard order; you can see this with verbose.

kmp_set_affinity() is available as a call to libiomp from the application. It takes similar strings to the environment variable strings. Evidently, you would include verbose at first to check it. It would not affect a current parallel region.

The documents on this subject which come with the compiler are important reading.
0 Kudos
rrr1989
Beginner
873 Views
hi thanks for the help...

but it says :
error C2065: 'KMP_AFFINITY' : undeclared identifier

is there any prerequisite required before writing this statement in my program?? i mean any environment variable to be set explicitly?? if so can you please elaborate it.. please.. as i said i am a newbie so please explain in detail...
0 Kudos
Gennady_F_Intel
Moderator
873 Views
- Use Intel compiler
- specify the -openmp ( in the case of Linux and Mac OS) or /Qopenmp ( for Windows) compiler option.
or
- expliciltly add IntelOpenMP* run-time library to your linking path ...
perform on non-Intel microprocessors. The
0 Kudos
TimP
Honored Contributor III
873 Views
KMP_AFFINITY is an environment variable. I set it in bash, but I assumed you would use SET.
kmp_set_affinity should be resolved in libiomp, if you make the function call. Try the environment variable first.
0 Kudos
Reply