I need to pin various c/c++ processes to specific cores on a machine for benchmarking only on Windows 7 64-bit. My machine has 16 cores (2x8). I'm trying to do this by calling SetProcessAffinityMask from within the code for a given process. Assuming that's correct I am unsure of how exactly to use this function. I've seen the documentation but am unable to understand its description of what the second argument needs to be. I also haven't found any example c/c++ usage either on SO or on Google having searched.
Question1: Taking a 16 core machine (2cpux8) for example and a c/c++ project would you please provide an illustrative example for how to use SetProcessAffinityMask to pick each of the 16 cores and an explanation of the second argument for my understanding? How would I translate a core id from 0-15 to its equivalent bitmask?
Question2: Does it make a difference to the usage if there are 2x8 cores as opposed to 16 cores on one cpu? Or is it the same usage?
Many thanks. Here's what I have so far.
#include <Windows.h>
#include <iostream>
using namespace std;
int main () {
HANDLE process = GetCurrentProcess();
DWORD_PTR processAffinityMask = 0; /// What to do here?
BOOL success = SetProcessAffinityMask(process, processAffinityMask);
cout << success << endl;
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…