From 00ff874bc9126fdba10e61c07e131bd38c358c17 Mon Sep 17 00:00:00 2001 From: Philippe Virouleau <philippe.virouleau@imag.fr> Date: Fri, 29 Dec 2017 15:26:47 +0100 Subject: [PATCH] Fixes to topology - fix native cpuset size - change default topology method (default to hwloc) --- runtime/src/kmp.h | 5 ++++- runtime/src/kmp_affinity.cpp | 7 ++++--- runtime/src/kmp_affinity.h | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/runtime/src/kmp.h b/runtime/src/kmp.h index 6f97ab2..400c02f 100644 --- a/runtime/src/kmp.h +++ b/runtime/src/kmp.h @@ -662,7 +662,10 @@ public: // Return true iff two sets are equals virtual int isequal(const Mask *d) const {} // Convert cpuset mask type to nodeset mask - virtual void cpuset2nodeset(Mask *d) const {} + virtual void cpuset2nodeset(Mask *d) const { + fprintf(stderr, "Using cpuset2nodeset with another topology than hwloc, it makes no sense. Please use KMP_TOPOLOGY_METHOD=hwloc!\n"); + KMP_ASSERT(0); + } // Set the system's affinity to this affinity mask's value virtual int set_system_affinity(bool abort_on_error) const { return -1; } // Set this affinity mask to the current system affinity diff --git a/runtime/src/kmp_affinity.cpp b/runtime/src/kmp_affinity.cpp index bc50288..d97c2df 100644 --- a/runtime/src/kmp_affinity.cpp +++ b/runtime/src/kmp_affinity.cpp @@ -65,9 +65,10 @@ void KMPAffinity::pick_api() { return; #if KMP_USE_HWLOC // Only use Hwloc if affinity isn't explicitly disabled and - // user requests Hwloc topology method - if (__kmp_affinity_top_method == affinity_top_method_hwloc && - __kmp_affinity_type != affinity_disabled) { + // unless the user specified a specific method + if (__kmp_affinity_type != affinity_disabled && + (__kmp_affinity_top_method == affinity_top_method_default || + __kmp_affinity_top_method == affinity_top_method_hwloc)) { affinity_dispatch = new KMPHwlocAffinity(); } else #endif diff --git a/runtime/src/kmp_affinity.h b/runtime/src/kmp_affinity.h index c479a8b..edec3c6 100644 --- a/runtime/src/kmp_affinity.h +++ b/runtime/src/kmp_affinity.h @@ -262,7 +262,10 @@ class KMPNativeAffinity : public KMPAffinity { __kmp_free(mask); } int size() override { - return BITS_PER_MASK_T; + int weight = 0; + for (size_t i = 0; i < __kmp_affin_mask_size; ++i) + weight += __builtin_popcount(mask[i]); + return weight; } void set(int i) override { mask[i / BITS_PER_MASK_T] |= ((mask_t)1 << (i % BITS_PER_MASK_T)); -- GitLab