Open MPI logo

Hardware Locality Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Users mailing list

Subject: Re: [hwloc-users] Windows api threading functions equivalent to hwloc?
From: Brice Goglin (Brice.Goglin_at_[hidden])
Date: 2012-11-19 15:08:43


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_bitmap_set_only(bitmap, i);
hwloc_set_thread_cpubind(topology, m_threads[i], bitmap, 0);
hwloc_bitmap_free(bitmap);

To get the number of processors with hwloc, use something like:
  hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
or
  hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PU);
Then it depends if you want real cores (the former or hardware threads
(the latter).

Brice