Skip to content

Commit

Permalink
Fixed #1245: HPX fails on startup (setting thread affinity mask)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Sep 5, 2014
1 parent 0f96b30 commit bfb6898
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/runtime/threads/policies/hwloc_topology.cpp
Expand Up @@ -260,6 +260,9 @@ namespace hpx { namespace threads
, error_code& ec
) const
{ // {{{

#if !defined(__APPLE__)
// setting thread affinities is not supported by OSX
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();

for (std::size_t i = 0; i < mask_size(mask); ++i)
Expand All @@ -278,13 +281,17 @@ namespace hpx { namespace threads
// Strict binding not supported or failed, try weak binding.
if (hwloc_set_cpubind(topo, cpuset, HWLOC_CPUBIND_THREAD))
{
char* buff = 0;
hwloc_bitmap_asprintf(&buff, cpuset);
hwloc_bitmap_free(cpuset);

boost::scoped_ptr<char> buffer(buff);

HPX_THROWS_IF(ec, kernel_error
, "hpx::threads::hwloc_topology::set_thread_affinity_mask"
, boost::str(boost::format(
"failed to set thread %x affinity mask")
% mask));
"failed to set thread affinity mask (0x%x) for cpuset %s")
% mask % buff));

if (ec)
return;
Expand All @@ -294,8 +301,8 @@ namespace hpx { namespace threads
#if defined(__linux) || defined(linux) || defined(__linux__) || defined(__FreeBSD__)
sleep(0); // Allow the OS to pick up the change.
#endif

hwloc_bitmap_free(cpuset);
#endif // __APPLE__

if (&ec != &throws)
ec = make_success_code();
Expand Down

0 comments on commit bfb6898

Please sign in to comment.