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: Samuel Thibault (samuel.thibault_at_[hidden])
Date: 2012-11-19 20:10:22


Andrew Somorjai, le Tue 20 Nov 2012 01:39:47 +0100, a écrit :
> "CreateThread() and WaitForMultipleObjects() are not in hwloc since they have nothing to do with topologies."
>
> I thought hwloc was also for threading?

It can bind your threads, yes, but the way to create the thread is
yours, it can be CreateThread, or OpenMP, etc...

> "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);"
>
> How would I pass a function like threadMain in the above CreateThread function into the thread itself. Someone told me to use this library for this purpose so I wasn't sure what it was made for.

You should indeed use hwloc to replace the SetThreadAffinityMask, but
keep your CreateThread.

> How would I create an array m_threads and pass it
> into hwloc_set_thread_cpubind. I would still need this part then correct?
>
> m_threads[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadMain, (LPVOID)i, NULL, &m_id);

Yes, something like:

m_threads[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadMain, (LPVOID)i, NULL, &m_id);

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

> I would like to be independent of windows.h by the way, not using windows api calls is the motivation for all of this.

Ah, then you may want to also use the pthread-win32 package, which is
meant to replace CreateThread, and use pthread_getw32threadhandle_np in
the windows case to convert from pthread-win32's pthread_t into a HANDLE
for hwloc.

Samuel