Hubbry Logo
search button
Sign in
Affinity mask
Affinity mask
Comunity Hub
History
arrow-down
starMore
arrow-down
bob

Bob

Have a question related to this hub?

bob

Alice

Got something to say related to this hub?
Share it here.

#general is a chat channel to discuss anything related to the hub.
Hubbry Logo
search button
Sign in
Affinity mask
Community hub for the Wikipedia article
logoWikipedian hub
Welcome to the community hub built on top of the Affinity mask Wikipedia article. Here, you can discuss, collect, and organize anything related to Affinity mask. The purpose of the hub is to connect peopl...
Add your contribution
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.[1] 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

[edit]

Thread affinity in Microsoft Windows can be specified with the SetThreadAffinityMask function.[1] 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);
     }
 }

See also

[edit]

References

[edit]
  1. ^ a b "SetThreadAffinityMask function (winbase.h) - Win32 apps". learn.microsoft.com. January 27, 2022. Retrieved April 7, 2023.
[edit]