Index: runtime/src/kmp.h =================================================================== --- runtime/src/kmp.h +++ runtime/src/kmp.h @@ -596,7 +596,11 @@ extern size_t __kmp_affin_mask_size; #define KMP_AFFINITY_CAPABLE() (__kmp_affin_mask_size > 0) #define KMP_AFFINITY_DISABLE() (__kmp_affin_mask_size = 0) -#define KMP_AFFINITY_ENABLE(mask_size) (__kmp_affin_mask_size = mask_size) +// Round to the nearest multiple of sizeof(unsigned long), which is the +// size of mask_t. +#define KMP_AFFINITY_ENABLE(mask_size) \ + (__kmp_affin_mask_size = ((mask_size + sizeof(unsigned long) - 1) & \ + ~(sizeof(unsigned long)-1))) #define KMP_CPU_SET_ITERATE(i, mask) \ for (i = (mask)->begin(); (int)i != (mask)->end(); i = (mask)->next(i)) #define KMP_CPU_SET(i, mask) (mask)->set(i) Index: runtime/src/kmp_affinity.h =================================================================== --- runtime/src/kmp_affinity.h +++ runtime/src/kmp_affinity.h @@ -237,12 +237,12 @@ #endif /* KMP_ARCH_* */ class KMPNativeAffinity : public KMPAffinity { class Mask : public KMPAffinity::Mask { - typedef unsigned char mask_t; + typedef unsigned long mask_t; static const int BITS_PER_MASK_T = sizeof(mask_t) * CHAR_BIT; public: mask_t *mask; - Mask() { mask = (mask_t *)__kmp_allocate(__kmp_affin_mask_size); } + Mask() { mask = (mask_t *)__kmp_allocate(sizeof(mask_t) * __kmp_affin_mask_size); } ~Mask() { if (mask) __kmp_free(mask); @@ -296,7 +296,7 @@ KMP_ASSERT2(KMP_AFFINITY_CAPABLE(), "Illegal get affinity operation when not capable"); int retval = - syscall(__NR_sched_getaffinity, 0, __kmp_affin_mask_size, mask); + syscall(__NR_sched_getaffinity, 0, sizeof(mask_t) * __kmp_affin_mask_size, mask); if (retval >= 0) { return 0; } @@ -310,7 +310,7 @@ KMP_ASSERT2(KMP_AFFINITY_CAPABLE(), "Illegal get affinity operation when not capable"); int retval = - syscall(__NR_sched_setaffinity, 0, __kmp_affin_mask_size, mask); + syscall(__NR_sched_setaffinity, 0, sizeof(mask_t) * __kmp_affin_mask_size, mask); if (retval >= 0) { return 0; }