https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/91479

Backport 73bb8d9

Requested by: @jpeyton52

>From 8665ddef7954319a892cc7ce46099d1d31f59a1c Mon Sep 17 00:00:00 2001
From: Jonathan Peyton <jonathan.l.pey...@intel.com>
Date: Wed, 8 May 2024 09:23:50 -0500
Subject: [PATCH] [OpenMP] Fix child processes to use affinity_none (#91391)

When a child process is forked with OpenMP already initialized, the
child process resets its affinity mask and sets proc-bind-var to false
so that the entire original affinity mask is used. This patch corrects
an issue with the affinity initialization code setting affinity to
compact instead of none for this special case of forked children.

The test trying to catch this only testing explicit setting of
KMP_AFFINITY=none. Add test run for no KMP_AFFINITY setting.

Fixes: #91098
(cherry picked from commit 73bb8d9d92f689863c94d48517e89d35dae0ebcf)
---
 openmp/runtime/src/kmp_settings.cpp     | 2 ++
 openmp/runtime/test/affinity/redetect.c | 1 +
 2 files changed, 3 insertions(+)

diff --git a/openmp/runtime/src/kmp_settings.cpp 
b/openmp/runtime/src/kmp_settings.cpp
index ec86ee07472c1..58f19ea5b8ab7 100644
--- a/openmp/runtime/src/kmp_settings.cpp
+++ b/openmp/runtime/src/kmp_settings.cpp
@@ -6426,6 +6426,8 @@ void __kmp_env_initialize(char const *string) {
         }
         if ((__kmp_nested_proc_bind.bind_types[0] != proc_bind_intel) &&
             (__kmp_nested_proc_bind.bind_types[0] != proc_bind_default)) {
+          if (__kmp_nested_proc_bind.bind_types[0] == proc_bind_false)
+            __kmp_affinity.type = affinity_none;
           if (__kmp_affinity.type == affinity_default) {
             __kmp_affinity.type = affinity_compact;
             __kmp_affinity.flags.dups = FALSE;
diff --git a/openmp/runtime/test/affinity/redetect.c 
b/openmp/runtime/test/affinity/redetect.c
index dba83b72cc42e..4b96d1bd92ee7 100644
--- a/openmp/runtime/test/affinity/redetect.c
+++ b/openmp/runtime/test/affinity/redetect.c
@@ -1,4 +1,5 @@
 // RUN: %libomp-compile
+// RUN: %libomp-run
 // RUN: env KMP_AFFINITY=none %libomp-run
 // REQUIRES: linux
 

_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to