[Openmp-commits] [openmp] r245966 - Fix machine topology pruning.

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Tue Aug 25 11:44:41 PDT 2015


Author: jlpeyton
Date: Tue Aug 25 13:44:41 2015
New Revision: 245966

URL: http://llvm.org/viewvc/llvm-project?rev=245966&view=rev
Log:
Fix machine topology pruning.

This patch fixes a bug when eliminating layers in the machine topology (namely
cores, and threads). Before this patch, if a user specifies using only one 
thread per socket, then affinity is not set properly due to bad topology
pruning.

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

Modified:
    openmp/trunk/runtime/src/kmp_affinity.cpp

Modified: openmp/trunk/runtime/src/kmp_affinity.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_affinity.cpp?rev=245966&r1=245965&r2=245966&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_affinity.cpp (original)
+++ openmp/trunk/runtime/src/kmp_affinity.cpp Tue Aug 25 13:44:41 2015
@@ -1791,24 +1791,26 @@ __kmp_affinity_create_x2apicid_map(AddrU
             new_retval[proc] = AddrUnsPair(addr, retval[proc].second);
         }
         int new_level = 0;
+        int newPkgLevel = -1;
+        int newCoreLevel = -1;
+        int newThreadLevel = -1;
+        int i;
         for (level = 0; level < depth; level++) {
-            if ((maxCt[level] == 1) && (level != pkgLevel)) {
-               if (level == threadLevel) {
-                   threadLevel = -1;
-               }
-               else if ((threadLevel >= 0) && (level < threadLevel)) {
-                   threadLevel--;
-               }
-               if (level == coreLevel) {
-                   coreLevel = -1;
-               }
-               else if ((coreLevel >= 0) && (level < coreLevel)) {
-                   coreLevel--;
-               }
-               if (level < pkgLevel) {
-                   pkgLevel--;
-               }
-               continue;
+            if ((maxCt[level] == 1)
+              && (level != pkgLevel)) {
+                //
+                // Remove this level. Never remove the package level
+                //
+                continue;
+            }
+            if (level == pkgLevel) {
+                newPkgLevel = level;
+            }
+            if (level == coreLevel) {
+                newCoreLevel = level;
+            }
+            if (level == threadLevel) {
+                newThreadLevel = level;
             }
             for (proc = 0; (int)proc < nApics; proc++) {
                 new_retval[proc].first.labels[new_level]
@@ -1820,6 +1822,9 @@ __kmp_affinity_create_x2apicid_map(AddrU
         __kmp_free(retval);
         retval = new_retval;
         depth = new_depth;
+        pkgLevel = newPkgLevel;
+        coreLevel = newCoreLevel;
+        threadLevel = newThreadLevel;
     }
 
     if (__kmp_affinity_gran_levels < 0) {




More information about the Openmp-commits mailing list