Below I posted a simple windows thread creation C++ routine which sets the processor affinity to two cores.
What I want is the equivalent code using hwloc. Sorry for being somewhat new to this but I'm not sure what
api calls are equivalent to the windows calls and I did search hwloc.h for "affinity" thinking the function call
would be easy to find. More specifically I'm
wondered whats the equivalent of " CreateThread
", " SetThreadAffinityMask
",
" GetSystemInfo
", and " WaitForMultipleObjects
" in hwloc.
Thanks for any useful suggestions.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
HANDLE *m_threads = NULL;
static DWORD_PTR WINAPI threadMain(void* p);
DWORD_PTR GetNumCPUs()//this function is not actually used by this example
{
SYSTEM_INFO m_si = {0, };
GetSystemInfo(&m_si);
return (DWORD_PTR)m_si.dwNumberOfProcessors;
}
int main(int argc, char **args)
{
DWORD_PTR c = 2;
m_threads = new HANDLE[c];
for(DWORD_PTR i = 0; i < c; i++)
{
DWORD_PTR m_id = 0;
DWORD_PTR m_mask = 1 << i;
m_threads[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadMain, (LPVOID)i, NULL, &m_id);
SetThreadAffinityMask(m_threads[i], m_mask);
//wprintf(L"Creating Thread %d (0x%08x) Assigning to CPU 0x%08x\r\n", i, (LONG_PTR)m_threads[i], m_mask);
}
WaitForMultipleObjects(c, m_threads, TRUE, INFINITE);
return 0;
}
static DWORD_PTR WINAPI threadMain(void* p)
{
double result = 0.0;
for (int i = 0; i < 1000000000; i++)
{
result = result + sin(i) * tan(i);
}
return 0;
}