Affinity mask

An affinity mask is a bit mask indicating what processor(s) a thread or process should be run on by the scheduler of an operating system. Setting the affinity mask for certain processes running under Windows can be useful as there are several system processes (especially on domain controllers) that are restricted to the first CPU / Core. So, excluding the first CPU might lead to better application performance.

Windows API

Thread affinity in Microsoft Windows can be specified with the SetThreadAffinityMask function. Forcing of each OpenMP thread to distinctive cores in Windows can be accomplished by means of the following C code:

 #include <windows.h>
 #include <omp.h>
 // Set OpenMP thread affinity
 void set_thread_affinity () {
     #pragma omp parallel default(shared)
     {
         DWORD_PTR mask = (DWORD_PTR )1 << omp_get_thread_num();
         SetThreadAffinityMask(GetCurrentThread(), mask);
     }
 }
gollark: Plus efficiency exists…
gollark: I have a 5x5x16 doing TBU oxide at 640% efficiency.
gollark: How? Any decent-sized reactor will make that up in less than a tick.
gollark: They run on enderpearl magic, you see.
gollark: There's something reassuring about seeing the oddly purple fusion plasma in the reactor, and not out of it.

See also

References


    This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.