//
you're reading...
CPP

Using KMP_AFFINITY to create OpenMP thread mapping to OS proc IDs

The Intel compiler’s OpenMP runtime library has ability to bind OpenMP threads to physical processing units.

This article will show you how to use KMP_AFFINITY environment variable extensions from Intel compiler, the high-level affinity interface, to determine the machine topology and assigns OpenMP threads to the processors based upon their physical location in the machine.

Example 1:

 

You have one quad core system with Hyper-Threading Technology (HT Technology) enabled.  By default, Intel compiler OpenMP runtime libraries will create 8 threads, running freely on 8 logic processors provided by opreation system.

Now you want the OpenMP thread ID 0 running exclusively on OS proc ID 0, and OpenMP thread ID 1 on OS proc ID 1 only.  All other OpenMP threads ID 2-7 could run on any OS proc ID betwen 2 to 7.

To do this, we need add the modifier proclist into Intel defined environment variable KMP_AFFINITY before the program is executed.

Another modifier verbose tell the Intel OpenMP runtime libraries to prints out messages concerning the supported affinity, include information about the number of packages, number of cores in each package, number of thread contexts for each core, and OpenMP thread bindings to physical thread contexts.

Here is commands we used in Windows:

> icl /Qpenmp testcase.cpp

> set KMP_AFFINITY=verbose,granularity=fine,proclist=[0,1,{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7}],explicit

> testcase.exe

……

OMP: Info #204: KMP_AFFINITY: decoding cpuid leaf 11 APIC ids.

OMP: Info #202: KMP_AFFINITY: Affinity capable, using global cpuid leaf 11 info

OMP: Info #154: KMP_AFFINITY: Initial OS proc set respected: {0,1,2,3,4,5,6,7}

OMP: Info #156: KMP_AFFINITY: 8 available OS procs

OMP: Info #157: KMP_AFFINITY: Uniform topology

OMP: Info #179: KMP_AFFINITY: 1 packages x 4 cores/pkg x 2 threads/core (4 total cores)

OMP: Info #206: KMP_AFFINITY: OS proc to physical thread map:

OMP: Info #171: KMP_AFFINITY: OS proc 0 maps to package 0 core 0 thread 0

OMP: Info #171: KMP_AFFINITY: OS proc 1 maps to package 0 core 0 thread 1

OMP: Info #171: KMP_AFFINITY: OS proc 2 maps to package 0 core 1 thread 0

OMP: Info #171: KMP_AFFINITY: OS proc 3 maps to package 0 core 1 thread 1

OMP: Info #171: KMP_AFFINITY: OS proc 4 maps to package 0 core 2 thread 0

OMP: Info #171: KMP_AFFINITY: OS proc 5 maps to package 0 core 2 thread 1

OMP: Info #171: KMP_AFFINITY: OS proc 6 maps to package 0 core 3 thread 0

OMP: Info #171: KMP_AFFINITY: OS proc 7 maps to package 0 core 3 thread 1

OMP: Info #147: KMP_AFFINITY: Internal thread 0 bound to OS proc set {0}

OMP: Info #147: KMP_AFFINITY: Internal thread 1 bound to OS proc set {1}

OMP: Info #147: KMP_AFFINITY: Internal thread 2 bound to OS proc set {2,3,4,5,6,7}

OMP: Info #147: KMP_AFFINITY: Internal thread 3 bound to OS proc set {2,3,4,5,6,7}

OMP: Info #147: KMP_AFFINITY: Internal thread 4 bound to OS proc set {2,3,4,5,6,7}

OMP: Info #147: KMP_AFFINITY: Internal thread 5 bound to OS proc set {2,3,4,5,6,7}

OMP: Info #147: KMP_AFFINITY: Internal thread 7 bound to OS proc set {2,3,4,5,6,7}

OMP: Info #147: KMP_AFFINITY: Internal thread 6 bound to OS proc set {2,3,4,5,6,7}

……

For Linux, you should use export command instead (with quotation mark)

]$ export KMP_AFFINITY=”verbose,granularity=fine,proclist=[0,1,{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7},{2,3,4,5,6,7}],explicit”

From compiler output message, you will see that OS processors specified in the list are assigned to OpenMP threads, in order of OpenMP Global Thread IDs.  If more OpenMP threads are created than there are elements in the list, then the assignment occurs modulo the size of the list. That is, OpenMP Global Thread ID n is bound to list element n mod .Remember, information about binding OpenMP threads to physical thread contexts is indirectly shown in the form of the mappings between hardware thread contexts and the operating system (OS) processor (proc) IDs. The affinity mask for each OpenMP thread is printed as a set of OS processor IDs.

More information is discussed on “Thread Affinity Interface (Linux* and Windows*)” section in Intel C/C++ compiler and Intel Fortran compiler user and reference guides.

Do you need more help?

Click tags links for related articles

Search Knowledge Base

Visit User Forums

Get other Support options

This article applies to: Intel® C++ Compiler for Linux* Knowledge Base,   Intel® C++ Compiler for Windows* Knowledge Base,   Intel® Fortran Compiler for Linux* Knowledge Base,   Intel® Visual Fortran Compiler for Windows* Knowledge Base

Refer to our Optimization Notice for more information regarding performance and optimization choices in Intel software products.

Discussion

4 thoughts on “Using KMP_AFFINITY to create OpenMP thread mapping to OS proc IDs

  1. Howdy! Do you use Twitter? I’d like to follow you if that would be ok. I’m undoubtedly
    enjoying your blog and look forward to new posts.

    Posted by seo services package | December 31, 2012, 1:09 pm
  2. Hello gentlemen! How are you presently now?

    Posted by playernparo | January 20, 2013, 8:33 pm
  3. Superb post but I was wondering if you could write a litte
    more on this subject? I’d be very thankful if you could elaborate a little bit further. Thank you!

    Posted by website optimization report | February 17, 2013, 7:37 pm
  4. Undeniably consider that which you stated. Your favourite
    justification appeared to be on the net the easiest thing to take into accout of.
    I say to you, I definitely get annoyed even as other people think about worries that they plainly do not recognise about.
    You managed to hit the nail upon the top and outlined out
    the whole thing with no need side-effects , folks could take a signal.
    Will probably be back to get more. Thank you

    Posted by creating a blog | March 16, 2013, 5:48 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: