Work on hwloc thread pinning

Fixing affinity masks. This is related to #473, #526 and #529