Le 19/11/2012 21:01, Andrew Somorjai a écrit :
> 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.
CreateThread() and WaitForMultipleObjects() are not in hwloc since they
have nothing to do with topologies.
> 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);
This will likely be something such as:
hwloc_bitmap_t bitmap = hwloc_bitmap_alloc();
hwloc_set_thread_cpubind(topology, m_threads[i], bitmap, 0);
To get the number of processors with hwloc, use something like:
Then it depends if you want real cores (the former or hardware threads