Open MPI logo

Hardware Locality Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |  

This web mail archive is frozen.

This page is part of a frozen web archive of this mailing list.

You can still navigate around this archive, but know that no new mails have been added to it since July of 2016.

Click here to be taken to the new web archives of this list; it includes all the mails that are in this frozen archive plus all new mails that have been sent to the list since it was migrated to the new archives.

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);

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