matthias_buehlmann
matthias_buehlmann

Reputation: 5061

how to set c++11 thread affinity to NUMA node on Windows?

On Windows, how can I:

Upvotes: 3

Views: 843

Answers (1)

CommanderLake
CommanderLake

Reputation: 61

To get the index of the highest node:

auto highestnode = 0UL;
GetNumaHighestNodeNumber(&highestnode);

To get the affinity of all logical cores on a node for up to 64 total logical cores:

auto mask = 0ULL;
GetNumaNodeProcessorMask(nodeindex, &mask);

To set thread affinity:

SetThreadAffinityMask(GetCurrentThread(), mask);

Or for greater than 64 total logical cores:

auto node = static_cast<PGROUP_AFFINITY>(malloc(sizeof(PGROUP_AFFINITY)));;
GetNumaNodeProcessorMaskEx(nodeindex, node);

Where the mask for the node is nodes->Mask.

Large nodes with more than 64 logical cores will be split up into groups specified by nodes->Group.

Upvotes: 2

Related Questions