[Openmp-commits] [openmp] r272561 - Fix bitmask complement operation

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Mon Jun 13 10:01:26 PDT 2016


Author: jlpeyton
Date: Mon Jun 13 12:01:26 2016
New Revision: 272561

URL: http://llvm.org/viewvc/llvm-project?rev=272561&view=rev
Log:
Fix bitmask complement operation

The bitmask complement operation doesn't consider the max proc id which means
something like !{0} will be translated to {1,2,3,4,...,600,601,...,1023} on a
Linux system even though there aren't 600 processors on said system. This
change has the complement bitmask and-ed with the fullmask so that it will only
contain valid processors.

Differential Revision: http://reviews.llvm.org/D21245

Modified:
    openmp/trunk/runtime/src/kmp.h

Modified: openmp/trunk/runtime/src/kmp.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp.h?rev=272561&r1=272560&r2=272561&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp.h (original)
+++ openmp/trunk/runtime/src/kmp.h Mon Jun 13 12:01:26 2016
@@ -536,6 +536,7 @@ typedef hwloc_cpuset_t kmp_affin_mask_t;
 # define KMP_CPU_CLR(i,mask)       hwloc_bitmap_clr((hwloc_cpuset_t)mask, (unsigned)i)
 # define KMP_CPU_ZERO(mask)        hwloc_bitmap_zero((hwloc_cpuset_t)mask)
 # define KMP_CPU_COPY(dest, src)   hwloc_bitmap_copy((hwloc_cpuset_t)dest, (hwloc_cpuset_t)src)
+# define KMP_CPU_AND(dest, src)    hwloc_bitmap_and((hwloc_cpuset_t)dest, (hwloc_cpuset_t)dest, (hwloc_cpuset_t)src)
 # define KMP_CPU_COMPLEMENT(max_bit_number, mask) \
     { \
         unsigned i; \
@@ -546,6 +547,8 @@ typedef hwloc_cpuset_t kmp_affin_mask_t;
                 hwloc_bitmap_set((hwloc_cpuset_t)mask, i); \
             } \
         } \
+        hwloc_bitmap_and((hwloc_cpuset_t)mask, (hwloc_cpuset_t)mask, \
+            (hwloc_cpuset_t)__kmp_affinity_get_fullMask()); \
     } \
 
 # define KMP_CPU_UNION(dest, src)  hwloc_bitmap_or((hwloc_cpuset_t)dest, (hwloc_cpuset_t)dest, (hwloc_cpuset_t)src)
@@ -638,6 +641,15 @@ typedef unsigned char kmp_affin_mask_t;
             }                                                                \
         }
 
+#  define KMP_CPU_AND(dest, src) \
+        {                                                                    \
+            size_t __i;                                                      \
+            for (__i = 0; __i < __kmp_affin_mask_size; __i++) {              \
+                ((kmp_affin_mask_t *)(dest))[__i]                            \
+                  &= ((kmp_affin_mask_t *)(src))[__i];                       \
+            }                                                                \
+        }
+
 #  define KMP_CPU_COMPLEMENT(max_bit_number, mask) \
         {                                                                    \
             size_t __i;                                                      \
@@ -645,6 +657,7 @@ typedef unsigned char kmp_affin_mask_t;
                 ((kmp_affin_mask_t *)(mask))[__i]                            \
                   = ~((kmp_affin_mask_t *)(mask))[__i];                      \
             }                                                                \
+            KMP_CPU_AND(mask, __kmp_affinity_get_fullMask());                \
         }
 
 #  define KMP_CPU_UNION(dest, src) \
@@ -717,6 +730,15 @@ extern int __kmp_num_proc_groups;
             }                                                                \
         }
 
+#   define KMP_CPU_AND(dest, src) \
+        {                                                                    \
+            int __i;                                                         \
+            for (__i = 0; __i < __kmp_num_proc_groups; __i++) {              \
+                ((kmp_affin_mask_t *)(dest))[__i]                            \
+                  &= ((kmp_affin_mask_t *)(src))[__i];                       \
+            }                                                                \
+        }
+
 #   define KMP_CPU_COMPLEMENT(max_bit_number, mask) \
         {                                                                    \
             int __i;                                                         \
@@ -724,6 +746,7 @@ extern int __kmp_num_proc_groups;
                 ((kmp_affin_mask_t *)(mask))[__i]                            \
                   = ~((kmp_affin_mask_t *)(mask))[__i];                      \
             }                                                                \
+            KMP_CPU_AND(mask, __kmp_affinity_get_fullMask());                \
         }
 
 #   define KMP_CPU_UNION(dest, src) \
@@ -758,7 +781,8 @@ typedef DWORD kmp_affin_mask_t; /* for c
 #   define KMP_CPU_CLR(i,mask)      (*(mask) &= ~(((kmp_affin_mask_t)1) << (i)))
 #   define KMP_CPU_ZERO(mask)       (*(mask) = 0)
 #   define KMP_CPU_COPY(dest, src)  (*(dest) = *(src))
-#   define KMP_CPU_COMPLEMENT(max_bit_number, mask) (*(mask) = ~*(mask))
+#   define KMP_CPU_AND(dest, src)   (*(dest) &= *(src))
+#   define KMP_CPU_COMPLEMENT(max_bit_number, mask) (*(mask) = ~*(mask)); KMP_CPU_AND(mask, __kmp_affinity_get_fullMask())
 #   define KMP_CPU_UNION(dest, src) (*(dest) |= *(src))
 
 #  endif /* KMP_GROUP_AFFINITY */
@@ -863,9 +887,7 @@ extern int __kmp_get_system_affinity(kmp
 extern int __kmp_set_system_affinity(kmp_affin_mask_t const *mask, int abort_on_error);
 extern void __kmp_affinity_bind_thread(int which);
 
-# if KMP_OS_LINUX
 extern kmp_affin_mask_t *__kmp_affinity_get_fullMask();
-# endif /* KMP_OS_LINUX */
 extern char const * __kmp_cpuinfo_file;
 
 #endif /* KMP_AFFINITY_SUPPORTED */




More information about the Openmp-commits mailing list